This file contains 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
module Tests | |
open System | |
open Xunit | |
open FsUnit.Xunit | |
let fib (a,b) = | |
let sum = a+b | |
Some (sum,(b,sum)) |
This file contains 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
module Tests | |
(* | |
problem statement: | |
a palindrome is a string that reads same forward and backward, | |
e.g. 121 or tacocat. | |
A substring is a contiguous subset of characters in a string. | |
Given a string s, how many distinct substrings of s are palindromes? | |
for example: (initial test list) |
This file contains 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
module Tests | |
(* | |
Problem: | |
Given an expression tree, model the data and write a method that takes | |
the tree as an input and | |
generate a string that represents this expression. | |
This file contains 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
// q: how would you encode Conways rule of life in f#? | |
// a: how about a pattern match emitting an action? | |
type Action = NoChange | BecomeInactive | BecomeActive | |
/// return what should happen to the central cell given active neighbor count | |
let kernel' centralCell activeNeighbors = | |
match centralCell, (activeNeighbors<2), (activeNeighbors>3), activeNeighbors=3 with | |
| true,true,_,_ -> BecomeInactive // living cell with fewer than two neighbors dies | |
| true,false,false,_ -> NoChange // living cell with two or three neighbors lives to next generation | |
| true,false,true,_ -> BecomeInactive // living cell with more than there neighbors dies |
This file contains 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
//a: how would you compute intersection of two lists? | |
//b: I'd use set intersection, but if literally a list, I'd sort then merge: | |
let intersection a b = | |
let rec intersection' a b = | |
match a,b with | |
| _,[] -> [] | |
| [],_ -> [] | |
| x::a',y::b' when x=y -> x::intersection' a' b' | |
| x::a',y::_ when x<y -> intersection' a' b |
This file contains 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
//remove consecutive duplicates | |
let uniq items = | |
let uniq accum item = | |
match accum with | |
| a::_ when a = item -> accum | |
| _ -> item::accum | |
items |> List.fold uniq [] |> List.rev | |
let uniq_tests = |
This file contains 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
// Consider an ant taking a random walk over corners of a cube. | |
// What are the average number of steps to arrive at the far corner? | |
// user interface is next line: you can change the sample size | |
val nSamples = 100_000 | |
abstract class Direction | |
case class X() extends Direction | |
case class Y() extends Direction | |
case class Z() extends Direction |
This file contains 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
// Consider an ant taking a random walk over corners of a cube. | |
// What are the average number of steps to arrive at the far corner? | |
// user interface is next line: you can change the sample size | |
let nSamples = 1_000_000 | |
type Direction = X | Y | Z | |
/// walk in the given direction | |
let walk (x,y,z) direction = |
This file contains 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
//Montecarlo simulation of likely points delivered this planning increment (5 sprints) | |
let copperV = [14;13;19;10;15] | |
let nRuns = 10_000 | |
/// given velocity history and number of sprints in a PI, simulate the PI nRuns times | |
let sims velocityHistory nRuns nSprints = | |
let vHistory = velocityHistory |> Seq.toArray; | |
let rnd = System.Random(); | |
let simPi = [for _ in 1..nRuns -> |
This file contains 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
// pairs II | |
// for a lightweight IDE with F# syntax awareness and REPL try https://code.visualstudio.com | |
/// generate all possible pairings given a list of candidatesf | |
let rec genPossiblePairs list = | |
match list with | |
| [] -> [] | |
| me::rest -> [for otherPerson in rest -> me, otherPerson] @ genPossiblePairs rest | |
genPossiblePairs [1..3] |
NewerOlder