Skip to content

Instantly share code, notes, and snippets.

@limansky
Created December 19, 2011 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save limansky/1499449 to your computer and use it in GitHub Desktop.
Save limansky/1499449 to your computer and use it in GitHub Desktop.
The problem of list order
import Data.List (delete)
squarable x = x `elem` [y^2 | y <- [2..x] ]
nexts x rest = foldr check [] rest
where check v good = if squarable (x + v) then v:good
else good
search ls [] = [ls]
search ls rs = nexts (last ls) rs >>= \v -> search (ls ++ [v]) (delete v rs)
result = search [16] [1..15]
main = putStrLn $ "Result: " ++ show result
@kovrov
Copy link

kovrov commented Dec 22, 2011

def test(pool, res):
   for i in pool:
       if res[-1] != i and res[-1] + i in (4, 9, 16, 25):
           return i
   assert False

pool = list(reversed(range(1,16)))
res = [16,]
while pool:
   i = test(pool, res)
   pool.remove(i)
   res.append(i)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment