1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import Data.Maybe data Instruction = X | Y deriving Show instance Eq Instruction where X == X = True Y == Y = True _ == _ = False instance Ord Instruction where Y <= X = False _ <= _ = True data BTree a = Branch a (BTree a) (BTree a) language (p, x, y) = Branch (p, x, y) (language (X:p, x + y, y)) (language (Y:p, x, x + y)) languageExprs = language ([], 1, 1) minLength [] = Nothing minLength x = Just $ flip foldl1 x (\a b -> if a < b then a else b) breadthSearch (Branch (p, x, y) lf rt) target | x == target = Just p | x < target && y < target = minLength $ catMaybes $ [breadthSearch lf target, breadthSearch rt target] | otherwise = Nothing main = do value <- getContents print $ breadthSearch languageExprs (read value) |
-
upload with new input
-
result: Success time: 0.02s memory: 3724 kB returned value: 0
20
Just [X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X,X]
-
result: Success time: 0.02s memory: 3724 kB returned value: 0
3
Just [X,X]
-
result: Success time: 0.02s memory: 3724 kB returned value: 0
4
Just [X,X,X]
-
result: Runtime error time: 0.02s memory: 3724 kB signal: -1
prog: Prelude.read: no parse



