Skip to content

@lewurm /.gitignore
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
haskell bruteforce
brute
brute.hi
brute.o
http://stackoverflow.com/questions/11391377/bruteforce-with-lazy-evaluation-and-memory-consumption
import Data.Maybe
bruteforce :: (a -> Bool) -> [a] -> Maybe a
bruteforce f xs
| null result = Nothing
| otherwise = Just $ head result
where
result = mapMaybe bruteforce' xs
-- test one instance
bruteforce' x
| f x = Just x
| otherwise = Nothing
generatorString :: Int -> [String]
generatorString 0 = [""]
generatorString deep = concatMap (\x -> map (\ys -> (x:ys)) nextgen) ['a'..'z']
where nextgen = generatorString (deep - 1)
main :: IO ()
main = do
putStrLn $ fromJust $ bruteforce ((==) "zabcde") (generatorString 6)
SHELL := bash
all: brute
brutenolimit: all
./brute +RTS -s
brute800: all
./brute +RTS -s -M800M
brute200: all
./brute +RTS -s -M200M
brute: brute.hs
ghc --make -O2 $< -o $@ -rtsopts
.PHONY: all clean brutenolimit brute200 brute800
clean:
rm -rf brute{,.o,.hi}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.