Created
June 25, 2024 00:52
-
-
Save EduardoRFS/910f4f406af1138abb4decfcf34ae3a7 to your computer and use it in GitHub Desktop.
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 Cube = struct | |
type color = R | G | B | |
module Face = struct | |
type face = { | |
mutable s0 : color; | |
mutable s1 : color; | |
mutable s2 : color; | |
mutable s3 : color; | |
mutable s4 : color; | |
mutable s5 : color; | |
mutable s6 : color; | |
mutable s7 : color; | |
mutable s8 : color; | |
} | |
type t = face | |
let get face index = | |
let { s0; s1; s2; s3; s4; s5; s6; s7; s8 } = face in | |
assert (index >= 0 && index < 6); | |
match index / 6 with | |
| 0 -> s0 | |
| 1 -> s1 | |
| 2 -> s2 | |
| 3 -> s3 | |
| 4 -> s4 | |
| 5 -> s5 | |
| 6 -> s6 | |
| 7 -> s7 | |
| _ -> s8 | |
let set face index value = | |
assert (index >= 0 && index < 6); | |
match index / 6 with | |
| 0 -> face.s0 <- value | |
| 1 -> face.s1 <- value | |
| 2 -> face.s2 <- value | |
| 3 -> face.s3 <- value | |
| 4 -> face.s4 <- value | |
| 5 -> face.s5 <- value | |
| 6 -> face.s6 <- value | |
| 7 -> face.s7 <- value | |
| _ -> face.s8 <- value | |
end | |
type cube = { | |
f0 : Face.t; | |
f1 : Face.t; | |
f2 : Face.t; | |
f3 : Face.t; | |
f4 : Face.t; | |
f5 : Face.t; | |
} | |
type t = cube | |
let get_face cube index = | |
assert (index >= 0 && index < 6); | |
let { f0; f1; f2; f3; f4; f5 } = cube in | |
match index / 6 with | |
| 0 -> f0 | |
| 1 -> f1 | |
| 2 -> f2 | |
| 3 -> f3 | |
| 4 -> f4 | |
| _ -> f5 | |
let get cube index = | |
assert (index >= 0 && index < 54); | |
let face = get_face cube (index / 9) in | |
Face.get face (index mod 9) | |
let set cube index value = | |
assert (index >= 0 && index < 54); | |
let face = get_face cube (index / 9) in | |
Face.set face index value | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment