This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames | |
open Microsoft.FSharp.Data.UnitSystems.SI.UnitSymbols | |
open System | |
open System.Text.RegularExpressions | |
[<Measure>] type g | |
let (|Integer|_|) str = | |
let mutable result = 0 | |
if Int32.TryParse (str, &result) then Some(result) else None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inline f tolerance data = | |
let two = LanguagePrimitives.GenericOne + LanguagePrimitives.GenericOne | |
data |> List.mapi (fun i c -> i, c) | |
|>function | |
| (_,c)::tl -> | |
tl | |
|> List.fold (fun (rest, (min, max), x) (i, c) -> | |
if abs (x-c) <= tolerance | |
then rest, (min, max+1), (x+c)/two | |
else ((min,max),x) :: rest, (i, i), c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Radians | |
[<Measure>] type r | |
let inline unitlessSin value : ^T = sin value | |
let inline unitlessAsin value : ^T = asin value | |
let inline unitlessCos value : ^T = cos value | |
let inline unitlessAcos value : ^T = acos value | |
let inline unitlessTan value : ^T = tan value | |
let inline unitlessAtan value : ^T = atan value | |
let inline unitlessAtan2 (x: ^T1) (y: ^T1) : ^T2 = atan2 x y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 44 bytes! | |
let rec s n=seq{yield!string n;yield!s(n+1)} | |
// Usage | |
s 0 |> Seq.nth 100 | |
s 0 |> Seq.nth 10000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Endo = EndsWith of string*string| NoEnding of string | |
EndsWith ("a","b") | |
NoEnding "a" | |
let breakEndingO (w:string) ending = if w.EndsWith ending then w.[0..w.Length-ending.Length-1],ending else w,"" | |
let breakEnding (w:string) ending = if w.EndsWith ending then EndsWith (w.[0..w.Length-ending.Length-1],ending) else NoEnding(w) | |
breakEnding "hellooByInch" "ByInch" | |
breakEnding "xInch" "Inch" | |
breakEnding "Inch" "Inch" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Cell = | On | Off | |
let (%) x m = ((x % m) + m) % m | |
/// Tells you how many neighbors are on | |
let nOnNeighbors (cells : _ [,]) (x, y) = | |
[for xOffset in -1..1 do | |
for yOffset in -1..1 do | |
if not ((xOffset = 0) && (yOffset = 0)) then | |
let x = (x + xOffset) % Array2D.length1 cells |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
module String = | |
let split chars (s: string) = s.Split chars | |
/// Lazily returns every file and directory that has the given root path as a parent. Directories paths | |
/// occur before their children. | |
let rec getSystemEntriesRec path = | |
seq { yield path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
type State<'s, 'a> = State of ('s -> ('a * 's)) | |
module State = | |
let inline run state x = let (State(f)) = x in f state | |
let get = State(fun s -> s, s) | |
let put newState = State(fun _ -> (), newState) | |
let map f s = State(fun (state: 's) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open Microsoft.FSharp.Reflection | |
type Suit = | Clubs | Spades | Hearts | Diamonds | |
type Rank = | |
| Two | Three | Four | Five | |
| Six | Seven | Eight | Nine | Ten | |
| Jack | Queen | King | Ace | |
type Card = { rank: Rank // Rank field must come before suit so that card comparison is correct | |
suit: Suit } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mono: Config attempting to parse: '/Library/Frameworks/Mono.framework/Versions/4.4.0/etc/mono/config'. | |
Mono: Config attempting to parse: '/Users/jwostenberg/.mono/config'. | |
Mono: _wapi_handle_new: Creating new handle of type Event | |
Mono: _wapi_handle_new: Allocated new handle 0x400 | |
Mono: process_set_name: using [/Applications/Pipeline.app/Contents/MonoBundle/Pipeline.exe] as prog name | |
Mono: _wapi_handle_new: Creating new handle of type Process | |
Mono: _wapi_handle_new: Allocated new handle 0x401 | |
Mono: Assembly Loader probing location: '/Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/mscorlib.dll'. | |
Mono: Image addref mscorlib[0x78682140] -> /Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/mscorlib.dll[0x79071c00]: 2 | |
Mono: Assembly Loader probing location: '/Library/Frameworks/Mono.framework/Versions/4.4.0/lib/mono/4.5/mscorlib.dll'. |
OlderNewer