Skip to content

Instantly share code, notes, and snippets.

View mathias-brandewinder's full-sized avatar

Mathias Brandewinder mathias-brandewinder

View GitHub Profile
@mathias-brandewinder
mathias-brandewinder / cards.clj
Last active November 9, 2015 01:49
Wonderland katas
(def suits [:spade :club :diamond :heart])
(def ranks [2 3 4 5 6 7 8 9 10 :jack :queen :king :ace])
@mathias-brandewinder
mathias-brandewinder / turtle.fsx
Last active September 10, 2015 16:25
Turtle: draft dojo
(*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Of Turtles & Discriminated Unions'
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The goal of this exercise is to introduce F# discriminated
unions, and how they can be used to design a DSL.
@mathias-brandewinder
mathias-brandewinder / Script.fsx
Created August 9, 2015 01:30
Language Safety Score using Logistic Regression
(*
This is a reaction to this blog post by Steve Shogren:
http://deliberate-software.com/safety-rank-part-2/
*)
#I @"../packages"
#r @"Accord.3.0.1-alpha\lib\net45\Accord.dll"
#r @"Accord.MachineLearning.3.0.1-alpha\lib\net45\Accord.MachineLearning.dll"
#r @"Accord.Math.3.0.1-alpha\lib\net45\Accord.Math.dll"
#r @"Accord.Statistics.3.0.1-alpha\lib\net45\Accord.Statistics.dll"
open System
let readInt () = Console.In.ReadLine() |> int
let N = readInt ()
let readline = [ for i in 0 .. N - 1 -> readInt () ]
let minimumBetweenTwoNumbers n1 n2 = min n1 n2
let rec minimum data mini =
let rec minimum data mini =
match data with
| first::second::tail ->
let min = abs (first - second) |> minimumBetweenTwoNumbers mini
match tail with
| [] -> min
| _ -> minimum second::tail min
@mathias-brandewinder
mathias-brandewinder / gist:d3daebd687f2095de1b1
Created March 31, 2015 05:28
Conversion to F# of "Gradient Descent Training Using C#"
// This is a conversion to F# of the C# code presented in
// MSDN Magazine, March 2015, by James McCaffrey:
// https://msdn.microsoft.com/en-us/magazine/dn913188.aspx
open System
let sumprod (v1:float[]) (v2:float[]) =
Seq.zip v1 v2 |> Seq.sumBy (fun (x,y) -> x * y)
let sigmoid z = 1.0 / (1.0 + exp (- z))
@mathias-brandewinder
mathias-brandewinder / gist:8f081f3c1fae03133bba
Created March 7, 2015 16:31
Bubbles from Fractal Forest
// just a tiny tweak on the Fractal Forest dojo:
// https://github.com/c4fsharp/Dojo-Fractal-Forest
open System
open System.Drawing
open System.Windows.Forms
let width, height = 500, 500
let form = new Form(Width = width, Height = height)
let box = new PictureBox(BackColor = Color.White, Dock = DockStyle.Fill)
@mathias-brandewinder
mathias-brandewinder / example.fsx
Created January 31, 2015 04:13
Accord.NET multi class SVM on digit recognizer problem
// Uses Accord.NET version 2.14.0
#r @"..\packages\Accord.2.14.0\lib\net40\Accord.dll"
#r @"..\packages\Accord.Math.2.14.0\lib\net40\Accord.Math.dll"
#r @"..\packages\Accord.Statistics.2.14.0\lib\net40\Accord.Statistics.dll"
#r @"..\packages\Accord.MachineLearning.2.14.0\lib\net40\Accord.MachineLearning.dll"
open System
open System.IO
// blog post: http://clear-lines.com/blog/post/Fun-with-L-system.aspx
type Symbol = | Sym of char
type State = Symbol list
type Rules = Map<Symbol,State>
type LSystem =
{ Axiom:State
open System.Drawing
let brightness (c:Color) = c.GetBrightness ()
let pixels (bmp:Bitmap) =
seq { for x in 0 .. bmp.Width - 1 do
for y in 0 .. bmp.Height - 1 ->
(x,y) |> bmp.GetPixel }
let breakpoint (bmp:Bitmap) =