Skip to content

Instantly share code, notes, and snippets.

@jdh30
jdh30 / k-nucleotide
Created June 13, 2015 15:45
This is a drop-in replacement for some of the very poor code given on The Computer Language Benchmarks Game
// F# code for the k-nucleotide task
// This is ~3.6x faster than the solution currently on The Computer Language Benchmarks Game.
// The optimisations are described in detail in the F# Journal article:
// "Optimising k-nucleotide" -- http://fsharpnews.blogspot.com/2013/08/optimizing-k-nucleotide.html
module Sub =
let maxLength = 29
let lengthPos = maxLength*2
let bits length = (1UL <<< (2*length)) - 1UL
let codeMask = bits maxLength
@jdh30
jdh30 / gist:c5ba4c52b46d2c77fa96
Last active August 29, 2015 22:52
Code for my CNC mill
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2
#define Y_STEP_PIN 60
#define Y_DIR_PIN 61
#define Y_ENABLE_PIN 56
#define Y_MIN_PIN 14
module SciMark2
module Random =
let m = Array.create 17 0
let mutable i = 4
let mutable j = 16
let mdig = 32
let m1 = (1 <<< mdig - 2) + ((1 <<< mdig - 2) - 1)
let m2 = 1 <<< mdig / 2
let dm1 = 1.0 / float m1
module Random = struct
let m = Array.create 17 0
let i = ref 4
let j = ref 16
let mdig = 32
let m1 = (1 lsl (mdig - 2)) + (1 lsl (mdig - 2)) - 1
let m2 = 1 lsl (mdig / 2)
let dm1 = 1.0 /. (2. ** float(mdig-1) -. 1.)
let nextDouble() =
@jdh30
jdh30 / neighbors.cpp
Created March 28, 2016 23:46
C++ implementation of a HashSet benchmark from the F# Journal
#include "stdafx.h"
#include <iostream>
#include <unordered_set>
using namespace std;
typedef pair<int, int> P;
template <class T> struct MyHash;
template<> struct MyHash<P>
@jdh30
jdh30 / neighbors2.fs
Last active April 2, 2016 23:41
F# implementation of a HashSet benchmark from the F# Journal with unboxed tuples
type [<Struct>] P =
val i : int
val j : int
new(i, j) = {i=i; j=j}
let cmp =
{ new System.Collections.Generic.IEqualityComparer<P> with
member __.Equals(this, that) =
this.i = that.i && this.j = that.j
@jdh30
jdh30 / neighbors2.rs
Created March 28, 2016 22:37
Rust implementation of a HashSet benchmark from the F# Journal
use std::collections::HashSet;
use std::hash::BuildHasherDefault;
use std::default::Default;
use std::hash::Hasher;
pub struct FnvHasher(u64);
impl Default for FnvHasher {
#[inline]
@jdh30
jdh30 / neighbors3.fs
Last active June 21, 2016 02:32
Neighbors benchmark in F# using the simple hash function from a Rust version
open System.Collections.Generic
type [<Struct>] P =
val i : int
val j : int
new(i, j) = {i=i; j=j}
let cmp =
{ new System.Collections.Generic.IEqualityComparer<P> with
member __.Equals(this, that) =
@jdh30
jdh30 / neighbors3.rs
Last active June 21, 2016 02:33
Neighbors benchmark in Rust using a simpler hash function Raw
use std::collections::HashSet;
use std::hash::BuildHasherDefault;
use std::default::Default;
use std::hash::Hasher;
pub struct FnvHasher(u64);
impl Default for FnvHasher {
#[inline]
let accountFactor = function
| `Simple -> 0.9
| `Valuable -> 0.7
| `MostValuable -> 0.5
let loyaltyFactor years =
1.0 -. float(min years 5) /. 100.0
let applyDiscount price = function
| `Unregistered -> price