Skip to content

Instantly share code, notes, and snippets.

View PatrickMcDonald's full-sized avatar

Patrick McDonald PatrickMcDonald

View GitHub Profile
@PatrickMcDonald
PatrickMcDonald / Fibonacci.fsx
Last active August 29, 2015 14:04
Generate Fibonacci numbers
let fibs() =
let rec fibs' a b =
seq {
yield b
yield! fibs' b (a+b)
}
fibs' 1L 1L
fibs() |> Seq.take 10 |> List.ofSeq;;
#r "System.Numerics"
open System.Numerics
/// Find the roots of ax² + bx + c
let quadraticRoots a b c =
let ``√ B² - 4ac`` = sqrt (b * b - 4.0 * a * c)
let ``2a`` = 2.0 * a
(-b + ``√ B² - 4ac``) / ``2a``, (-b - ``√ B² - 4ac``) / ``2a``
namespace StringTimes
{
using System;
public class Program
{
private static void Main(string[] args)
{
const int Iterations = 10000000;
let foldBack folder seq state =
let arr = Seq.toArray seq
Array.foldBack folder arr state
let folder a b =
let res = a + b
//printfn "fold %A and %A giving %A" a b res
res
let list = seq [1..1000000]
let createTimer() =
let sw = System.Diagnostics.Stopwatch.StartNew()
fun () ->
sw.Elapsed
let timer = createTimer()
// Do some stuff to time
timer();;
namespace Curry
{
using System;
internal static class Program
{
// Curry methods
public static TResult Curry<T, TResult>(this Func<T, TResult> f, T arg)
{
// Curry'2 is just invoke
@PatrickMcDonald
PatrickMcDonald / CampingChecklist.md
Last active August 29, 2015 14:05
Camping Checklist

Camping Checklist

Cooking

  • Trangia
  • fuel bottle
  • Cobb
  • fuel
@echo off
pushd visualfsharp\src
msbuild fsharp-library-build.proj /p:TargetFramework=net40
if %errorlevel% neq 0 goto :END
msbuild fsharp-library-unittests-build.proj /p:TargetFramework=net40
let rec change denominations amount =
match denominations with
| [] -> 0
| _ when amount = 0 -> 1
| head :: tail when amount < head -> change tail amount
| head :: tail -> (change denominations (amount - head)) + (change tail amount)
change [50; 20; 10; 5; 2; 1] 100;;
[<CompiledName("SortByDescending")>]
let sortByDescending keyf source =
checkNonNull "source" source
mkDelayedSeq (fun () ->
let keyf = System.Func<_,_>(keyf)
let res = System.Linq.Enumerable.OrderByDescending(source, keyf)
res :> seq<_>)
[<CompiledName("SortDescending")>]
let sortDescending source =