Skip to content

Instantly share code, notes, and snippets.

@jarlestabell
Last active August 29, 2015 14:21
Show Gist options
  • Save jarlestabell/bec41f108c0715bfbc68 to your computer and use it in GitHub Desktop.
Save jarlestabell/bec41f108c0715bfbc68 to your computer and use it in GitHub Desktop.
Another solution inspired by http://blog.bjartwolf.com/?p=4272
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")
@jarlestabell
Copy link
Author

Obviously not the way to do it! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment