Skip to content

Instantly share code, notes, and snippets.

@ptrelford
ptrelford / boolean.erl
Created November 6, 2012 07:14
Erlang sequential programming exercises
-module(boolean).
-export([b_not/1,b_and/2,b_or/2,test/0]).
b_not(false) -> true;
b_not(true) -> false.
b_and(false,false) -> false;
b_and(false,true) -> false;
b_and(true,false) -> false;
b_and(true,true) -> true.
@ptrelford
ptrelford / crossring.erl
Created November 7, 2012 07:56
Erlang sequential programming exercises
-module(crossring).
-compile(export_all).
start(N) ->
Pid = spawn(crossring,first,[N]),
register(cring, Pid),
ok.
send(M, Msg) -> cring ! {1, M, Msg }, ok.
@ptrelford
ptrelford / gist:4316147
Created December 17, 2012 06:13
Try Brainfuck web page
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Try Brainfuck</title>
<meta name="expires" content="0" />
<meta name="keywords" content="Brainfuck" />
</head>
<body>
<h1>Try Brainfuck</h1>
<textarea id="editor" cols="40" rows="4">

Survey CSV exercise

Background

We are surveying developers at a number of sites to find their favourite programming language. Each response from a site is stored in a type that contains the site name, and a map/dictionary of programming languages and the number of votes they received. In C# this could look something like this:

class SurveyResponse {
    public string Site;
 public Dictionary Results;
@ptrelford
ptrelford / gist:5641811
Created May 24, 2013 07:15
Survey CSV exercise
open Microsoft.FSharp.Reflection
open System.Collections.Generic
type ProgrammingLanguage =
| CSharp
| FSharp
| Haskell
| Ruby
| JavaScript
@ptrelford
ptrelford / DecisionTree.fsx
Last active December 19, 2015 11:19
Decision Trees - port of Machine Learning in Action from Python to F#
open System.Collections.Generic
module internal Tuple =
open Microsoft.FSharp.Reflection
let toArray = FSharpValue.GetTupleFields
module internal Array =
let removeAt i (xs:'a[]) = [|yield! xs.[..i-1];yield! xs.[i+1..]|]
let splitDataSet(dataSet:obj[][], axis, value) = [|
@ptrelford
ptrelford / DecisionTree.fs
Created July 13, 2013 19:49
Titanic: Machine Learning from Disaster guided F# script for the Kaggle predictive modelling competition of the same name.
module DecisionTree
open System.Collections.Generic
module internal Tuple =
open Microsoft.FSharp.Reflection
let toArray = FSharpValue.GetTupleFields
module internal Array =
let removeAt i (xs:'a[]) = [|yield! xs.[..i-1];yield! xs.[i+1..]|]
@ptrelford
ptrelford / Links.csv
Last active January 11, 2024 09:35
Mystic Brew
@ptrelford
ptrelford / Links.fs
Last active December 20, 2015 01:08
Morning Dew
@ptrelford
ptrelford / PacmanMaze.fsx
Last active December 20, 2015 04:09
Pacman maze runnable in Tsunami Cloud IDE
#r "System.Windows.dll"
#r "Tsunami.IDESilverlight.dll"
#r "Telerik.Windows.Controls.dll"
#r "Telerik.Windows.Controls.Docking.dll"
#r "Telerik.Windows.Controls.Navigation.dll"
open System
open System.Windows
open System.Windows.Controls
open System.Windows.Media