MultiplicationFrustration.frink

View or download MultiplicationFrustration.frink in plain text format


// Solver for the "Multiplication Frustration" geocache, GC38CAY
// http://www.geocaching.com/seek/cache_details.aspx?guid=cf06d6ad-6cdc-43fd-b588-54194fbc4c96

use navigation.frink
use GoogleEarth.frink

// Just solving for these is sufficient.
n1 = "CSAAF"
n2 = "AHSHR"
p = "JFCPBSSNRR"

eq= "$n1 * $n2 == $p"

chars = sort[toSet[charList[n1 + n2 + p]]]
println[chars]

for vals = toArray[0 to 9].lexicographicPermute[]
{
   en = eq
   for i=0 to 9
   {
      sub = subst[chars@i, toString[vals@i], "g"]
      en =~ sub
   }

   // Found the solution!  Now all this extra code to format the output nicely.
   if eval[en]
   {
      println[vals]
      p1 = "AH.SCS"
      p2 = "CS.AJH"
      for i=0 to 9
      {
         sub = subst[chars@i, toString[vals@i], "g"]
         p1 =~ sub
         p2 =~ sub
      }
      solution = "[DMS[39,$p1] North,   DMS[104,$p2] West]"
      println[solution]
      [lat,long] = eval[solution]
      println[[lat,long] -> "degrees"]
      browseGoogleMaps[lat, long, "GC38CAY"]
   }
}


View or download MultiplicationFrustration.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 17835 days, 19 hours, 16 minutes ago.