Last active
November 28, 2019 11:07
-
-
Save OnurGumus/8e81ee89b385e10be38f24f98020ecad to your computer and use it in GitHub Desktop.
birthday_odds_1
This file contains hidden or 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
open System | |
type Item = O = 0 | X = 1 | A = 2 | |
let inline add char = function | |
| struct (Item.O,Item.O) -> struct (char, Item.O) | |
| x, Item.O -> x, char | |
| _, y -> y, char | |
let rec calc numA numX = function | |
| _ when numX = 0 -> 0 | |
| _ when numA = 0 -> 1 | |
| struct (Item.A,Item.A) as state -> | |
calc numA (numX - 1) (add Item.X state) | |
| state -> | |
calc (numA - 1) numX (add Item.A state) | |
+ calc numA (numX - 1) (add Item.X state) | |
open System.Diagnostics | |
let sw = Stopwatch.StartNew() | |
calc 10 30 (Item.O,Item.O) |> printf "%i" | |
printfn "%A" sw.Elapsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment