Skip to content

Instantly share code, notes, and snippets.

#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 " - "
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() =
@cmbrown1598
cmbrown1598 / Guesser.fsx
Last active August 20, 2019 21:23
The number guessing game
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; }
@cmbrown1598
cmbrown1598 / ChessPieces.fsx
Last active July 31, 2019 16:39
How chess pieces move on an empty board, in algebraic notation.
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; }
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
#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)
type Compounding =
| TimesPerYear of float
| Constant
type InterestCalculationOptions = {
Compounding : Compounding
Rate : float
Principal : float
TermInYears : float
}
type Name = string
type Percentage = decimal
type Return = decimal
type TargetReturn = decimal
type Model = Name
type Allocation = ( Model * Percentage ) list
type MarketValue = decimal
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
}
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