DivideAndConquer.frink

Download or view DivideAndConquer.frink in plain text format


// Solver for the "Divide & Conquer" geocache, GC37TRN
// http://www.geocaching.com/seek/cache_details.aspx?guid=e319c07a-8006-4ccb-ad68-4888059b799f

use navigation.frink
use GoogleEarth.frink

// Just solving for these is sufficient.
n1 = "AI.AFI"
n2 = "BI.HCE"
p = "E.AAE"

others="JGD"

eq= "floor[$n1 / $n2, 0.001] == $p   &&  $n1 - $n2 == GD.EGA"


chars = sort[toSet[select[charList[n1 + n2 + p + others], %r/[A-Z]/i]]]
println[chars]

for vals = toArray[0 to 9].lexicographicPermute[]
{
   if vals@4 != 1    // E must be 1
      next
   
   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 = "BI.HCE"
      p2 = "AI.AFI"
      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, "GC37TRN"]
   }
}


Download or view DivideAndConquer.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 20217 days, 23 hours, 33 minutes ago.