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
#r "Facades/netstandard" | |
#r "netstandard" | |
let vals = [1;2;3;4;5;6;7;8;9] | |
let operations = [(+);(-);(fun x y -> (x * 10) + (y))] | |
let render ops expectedResult = | |
let s op = | |
if op 1 1 = 2 then Some " + " | |
else if op 1 1 = 0 then Some " - " |
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
type Response = | Bull | Cow | Empty | |
let bullAndCow (attempt : int[]) (answer : int[]) = | |
let bullCowOrNothing (idx:int) (chr:int) = | |
if (answer.[idx] = chr) then Bull | |
else if (Array.contains chr answer) then Cow | |
else Empty | |
Array.mapi bullCowOrNothing attempt |> Array.filter (fun n -> n <> Empty) | |
let rec getGuess() = |
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
open System | |
type Results = { Games : int; Guesses : int; BestGame : int; TotalGuesses : int } | |
let rec again results = | |
Console.Write "\r\nWould you like to play again? (y/n): " | |
let t = {results with Guesses = 0; TotalGuesses = results.Guesses + results.TotalGuesses; } | |
match Console.ReadKey() with | |
| m when m.Key = ConsoleKey.Y -> {t with Games = results.Games + 1; } |
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
type Square = Rank * File | |
and Rank = | One = 1 | Two =2 | Three = 3| Four = 4 | Five = 5 | Six = 6 | Seven = 7 | Eight = 8 | |
and File = | A = 1 | B = 2 | C = 3 | D = 4 | E = 5 | F = 6 | G = 7 | H = 8 | |
type Piece = | Pawn | King | Queen | Knight | Bishop | Rook | |
type Color = | Black | White | |
type ChessMove = { Piece : Piece; Color : Color; StartingSquare : Square; DestinationSquare : Square; } |
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
open System | |
type Sector = | TopLeft = 1 | TopMiddle = 2 | TopRight = 3 | CenterLeft = 4 | CenterMiddle = 5 | CenterRight = 6 | BottomLeft = 7 | BottomMiddle = 8 | BottomRight = 9 | |
type Position = { Rank : Rank; File : File } | |
and File = | A = 1 | B = 2 | C = 3 | D = 4 | E = 5 | F = 6 | G = 7 | H = 8 | I = 9 | |
and Rank = | One = 1 | Two = 2 | Three = 3 | Four = 4 | Five = 5 | Six = 6 | Seven = 7 | Eight = 8 | Nine = 9 | |
type Grid = Map<Position, int> | |
let lengthOfSecondItemInTuple e = (snd e) |> Array.length |
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
#r "FSharp.Data.3.0.0\\lib\\net45\\Fsharp.Data.dll" | |
open System.IO; | |
open FSharp.Data | |
type BigOleFile = CsvProvider<"C:\\working\\sample.txt", "\t"> | |
let writeData filePath stringLines = | |
try | |
File.WriteAllLines (filePath , Array.ofList stringLines) | |
Ok (List.length stringLines) |
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
type Compounding = | |
| TimesPerYear of float | |
| Constant | |
type InterestCalculationOptions = { | |
Compounding : Compounding | |
Rate : float | |
Principal : float | |
TermInYears : float | |
} |
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
type Name = string | |
type Percentage = decimal | |
type Return = decimal | |
type TargetReturn = decimal | |
type Model = Name | |
type Allocation = ( Model * Percentage ) list | |
type MarketValue = decimal |
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
let getFactors (value : bigint) = | |
let isFactor i pf = | |
i % pf = 0I | |
let rec potentialFactors start i = seq { | |
match start with | |
| Some v when v > 2I -> for a in v..2I..i do yield a | |
| Some _ | None -> | |
yield 2I | |
yield! potentialFactors (Some 3I) i | |
} |
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
type BiggerThanZero = private BiggerThanZero of bigint | |
module BiggerThanZero = | |
let create uintValue = | |
if (uintValue > 0I ) then BiggerThanZero uintValue | |
else failwith "No zeros" | |
let value (BiggerThanZero u) = | |
u | |
NewerOlder