colorsPuzzle.frink

Download or view colorsPuzzle.frink in plain text format

/** Solver for a Twitter puzzle:
https://twitter.com/swansnake/status/1048992371982192641

   This solution is not particularly efficient (it could bail out of loops
   earlier with a different formulation) but is quite simple.  It is somewhat
   efficient in making sure each color has a unique number due to use of the
   array.permute[] method.  It will find all
   possible solutions if there are more than one.
*/


nums = array[1 to 12]
for [black, blue, brown, green, grey, orange, pink, purple, red, turquoise, white, yellow] = nums.permute[]
{
   if brown != red + blue + yellow
      next
   if green != blue + yellow
      next
   if grey != black + white
      next
   if orange != red + yellow
      next
   if pink != red + white
      next
   if purple != red + blue
      next
   if turquoise != blue + green
      next
   
   println[[black, blue, brown, green, grey, orange, pink, purple, red, turquoise, white, yellow]]
}


Download or view colorsPuzzle.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19970 days, 12 hours, 46 minutes ago.