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
type Peg = | |
| A | |
| B | |
| C | |
type Move = | |
| Move of int * Peg * Peg | |
static member toString m = | |
match m with | |
| Move(n, p1, p2) when n <> 1 -> sprintf "move %i %A %A" n p1 p2 |
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 rec sieve (xs : int seq) = | |
seq { | |
let p = xs |> Seq.take 1 |> Seq.exactlyOne | |
yield p | |
yield! xs |> Seq.skip 1 |> Seq.filter (fun x -> x % p <> 0) |> sieve | |
} | |
let ints = Seq.initInfinite (fun x -> x + 2) | |
let primes = sieve ints |
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
type position = int * int | |
type board = position list | |
let queens n = | |
let isNotAttack (p1 : position) (p2 : position) = | |
fst p1 <> fst p2 && snd p1 <> snd p2 && abs (fst p1 - fst p2) <> abs (snd p1 - snd p2) | |
let isSafe (b : board) = | |
match b with | |
| [] -> true |
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
def sieve(s: Stream[Int]): Stream[Int] = | |
s.head #:: sieve(s.tail filter(_ % s.head != 0)) | |
val primes = sieve(Stream.from(2)) | |
primes.take(100).toList |