Skip to content

Instantly share code, notes, and snippets.

@sgoguen
Last active February 3, 2021 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgoguen/076ba8ede1546562cf37c09add1537a1 to your computer and use it in GitHub Desktop.
Save sgoguen/076ba8ede1546562cf37c09add1537a1 to your computer and use it in GitHub Desktop.
type Moves = int
type ActionRoll =
| CheckOneCamera
| MotionSensor // Tells you which camera the thief is on
| ScanAll
type WindowState = Locked | Open
type Square = {
North: Z
South: Z
East: Z
West: Z
}
and Z = Square of Square | Wall | Window of WindowState
type Direction = North | South | East | West
type Color = R | P | B | Y | G | W | H | E
type Walls = int
type Sqr = S of Color * Walls * int
type ExitType = Window | Door
type Action =
| Move of Square
| TryOpen of ExitType * Direction
| TurnOffPower
| TurnOnPower
| TakePainting
type Square2 = Action list
let charToColor = function
| '-' -> E
| 'R' -> R
| 'P' -> P
| 'H' -> H
| 'B' -> B
| 'Y' -> Y
| 'G' -> G
| _ -> E
let charToWindow = function
| '1' -> 1
| '2' -> 2
| '4' -> 4
| '8' -> 8
| _ -> 0
open System
open System.Globalization
let toWall = function
| c when c >= '1' && c <= '9' -> int(int(c) - int('1')) + 1
| c when c >= 'A' && c <= 'F' -> int(int(c) - int('A')) + 10
| _ -> 15
let board = @"
---RRRRRR---
---RRRRRR---
PPPHHHHHHBBB
PPPHWWWWHBBB
PPPHWWWWHHHH
HHHHWWWWHGGG
YYYHWWWWHGGG
YYYHWWWWHGGG
YYYHHHHHHGGG
---HHHHHH---
---HHHHHH---"
let windows = @"
###R1RR1RFFF
###RRRRRR###
PPPHHHHHHB1B
8PPHWWWWHBBB
PPPHWWWWHHHH
HHHHWWWWHGGG
YYYHWWWWHGGG
8YYHWWWWHGG2
Y4YHHHHHHGGG
###HHHHHH###
###HHHHHP###"
let walls = @"
---911113---
---C04406---
913941143913
802A90030446
C4428002855-
-55280002913
91380002A802
8002C0068002
C46C10016C46
---92C683---
---C6--C6--
"
// 0 - Open
// N - 1, E - 2, S - 4, W - 8
// F - Close
module Array2 =
let map f a = [ for row in a do yield [ for cell in row do yield f cell ] ]
let zip2 a1 a2 =
Array.zip a1 a2 |> Array.map (fun (r1, r2) -> Array.zip r1 r2)
let zip3 a1 a2 a3 =
zip2 (zip2 a1 a2) a3
|> map ( fun ((a, b), c) -> (a, b, c))
let toBoard (f) (board: string) = [
for row in board.Split("\n") do
if row.Length > 0 then
yield [
for c in row do yield f c
]
]
printfn "%A" (toBoard toWall walls)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment