Created
December 19, 2011 23:41
-
-
Save limansky/1499449 to your computer and use it in GitHub Desktop.
The problem of list order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)