-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtisbury_treasure_hunt.gleam
46 lines (40 loc) · 1.62 KB
/
tisbury_treasure_hunt.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gleam/list
pub fn place_location_to_treasure_location(
place_location: #(String, Int),
) -> #(Int, String) {
case place_location {
#(string, int) -> #(int, string)
}
}
pub fn treasure_location_matches_place_location(
place_location: #(String, Int),
treasure_location: #(Int, String),
) -> Bool {
let place_location: #(Int, String) = place_location_to_treasure_location(place_location)
place_location == treasure_location
}
pub fn count_place_treasures(
place: #(String, #(String, Int)),
treasures: List(#(String, #(Int, String))),
) -> Int {
let place_location: #(Int, String) = place_location_to_treasure_location(place.1)
treasures
|> list.filter(fn(item) { item.1 == place_location})
|> list.length
}
pub fn special_case_swap_possible(
found_treasure: #(String, #(Int, String)),
place: #(String, #(String, Int)),
desired_treasure: #(String, #(Int, String)),
) -> Bool {
let place_location: #(Int, String) = place_location_to_treasure_location(place.1)
let condition_1 = found_treasure.0 == "Brass Spyglass" && place.0 == "Abandoned Lighthouse" && desired_treasure.1 == place_location
let condition_2 = found_treasure.0 == "Amethyst Octopus" && place.0 == "Stormy Breakwater" && desired_treasure.0 == "Crystal Crab" || desired_treasure.0 == "Glass Starfish"
let condition_3 = found_treasure.0 == "Vintage Pirate Hat" && place.0 == "Harbor Managers Office" && desired_treasure.0 == "Model Ship in Large Bottle" || desired_treasure.0 == "Antique Glass Fishnet Float"
case desired_treasure {
_ if condition_1 -> True
_ if condition_2 -> True
_ if condition_3 -> True
_ -> False
}
}