Last active
August 29, 2015 14:21
-
-
Save jarlestabell/bec41f108c0715bfbc68 to your computer and use it in GitHub Desktop.
Another solution inspired by http://blog.bjartwolf.com/?p=4272
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
let calcExpr n = | |
let rec innerCalcExpr n current last= | |
if current>last then "" else [|""; "+"; "-"|].[n%3] + string current + innerCalcExpr (n/3) (current+1) last | |
"1" + innerCalcExpr n 2 9 | |
let rec sum = function | |
|(op::h::t) -> (int (op+h)) + sum t | |
| _ -> 0 | |
let eval text = sum ("+" :: (System.Text.RegularExpressions.Regex.Split(text,@"(\+)|(-)") |> List.ofArray)) | |
let generateAndPrint() = seq {0 .. (pown 3 8) - 1} |> Seq.map calcExpr |> Seq.filter(fun s->eval s = 100) |> | |
Seq.iter (printfn "%s") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously not the way to do it! :)