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
defmodule MyMath do | |
def factorial(n), do: factorial(n, 1) | |
def factorial(0, acc), do: acc | |
def factorial(n, acc) do | |
factorial(n - 1, acc * n) | |
end | |
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
(* Bring data on patient samples from the diagnosis machine to the laboratory with enough molecules | |
to produce medicine! *) | |
open System | |
let projectCount = int(Console.In.ReadLine()) | |
for i in 0 .. projectCount - 1 do | |
let token = (Console.In.ReadLine()).Split [|' '|] | |
let a = int(token.[0]) | |
let b = int(token.[1]) | |
let c = int(token.[2]) |
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 Token = string array | |
// unit -> string | |
let readInput () = Console.ReadLine() | |
// unit -> int | |
let readInt = readInput >> int | |
// string -> string [] | |
let tokenize (line : string) = line.Split ' ' |
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 Module = | |
| StartPos | |
| Diagnosis | |
| Molecules | |
| Laboratory | |
static member Create moduleName = | |
match moduleName with | |
| "START_POS" -> Module.StartPos | |
| "DIAGNOSIS" -> Module.Diagnosis | |
| "MOLECULES" -> Module.Molecules |
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 MoleculeType = | |
| A | B | C | D | E | |
override x.ToString () = | |
match x with | |
| A -> "A" | |
| B -> "B" | |
| C -> "C" | |
| D -> "D" | |
| E -> "E" |
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 MoleculeStorage = | |
{ Counts : Map<MoleculeType, int> } | |
static member Create (token : Token) = | |
{ Counts = | |
Map [ (MoleculeType.A, (int <| token.[0])) | |
(MoleculeType.B, (int <| token.[1])) | |
(MoleculeType.C, (int <| token.[2])) | |
(MoleculeType.D, (int <| token.[3])) | |
(MoleculeType.E, (int <| token.[4])) ] | |
} |
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 HealthPoints = int | |
type Player = | |
| Me | Enemy | Cloud | |
static member Create id = | |
match id with | |
| 0 -> Player.Me | |
| 1 -> Player.Enemy | |
| -1 -> Player.Cloud | |
| i -> failwithf "Unknown player id: %i" 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 Id = int | |
type SampleData = | |
{ Id : Id | |
CarriedBy : Player | |
HealthPoints : HealthPoints | |
Molecules : MoleculeStorage } | |
static member Create (token : Token) = | |
{ Id = (int <| token.[0]) | |
CarriedBy = Player.Create (int <| token.[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 GameState = | |
{ Robots : Robot list | |
Samples : SampleData 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
type Collect = SampleData -> string | |
type Gather = MoleculeType -> string | |
type Produce = SampleData -> string | |
type Goto = Module -> string |
OlderNewer