Snippets created by Bjørn Bæverfjord

  • Largest palindrome made from the product of two n-digit numbers

    A generalised version of the solution to the fourth Project Euler problem - Largest palindrome product, using sequences. The key to understanding this code is how "Seq.map (fun x -> (Seq.map (fun y -> x * y) baseSeq)) baseSeq" generates a sequence of sequences that contains the products of all possible combinations of two n-digit numbers. "Seq.map (fun x -> (Seq.map (fun y -> x * y) {1..3})) {1..3}" will generate: seq [seq [1; 2; 3]; seq [2; 4; 6]; seq [3; 6; 9]]

    3 people like this

    Posted: 10 years ago by Bjørn Bæverfjord

  • Count leading zeros

    Several ways of counting leading zeros in a binary number. Update: clzDeBruijn now captures the look-up table in the closure so that the table is only evaluated once and everything is contained in the main function.

    3 people like this

    Posted: 10 years ago by Bjørn Bæverfjord

  • Optimal bitwise CIL-like code optimizer

    Prototype of a CIL code optimizer that generates optimal code for bitwise functions. Update: General improvements

    2 people like this

    Posted: 9 years ago by Bjørn Bæverfjord