Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

haskell bruteforce

View .gitignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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}
View .gitignore
1
http://stackoverflow.com/questions/11391377/bruteforce-with-lazy-evaluation-and-memory-consumption
View .gitignore
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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)
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.