tisbury-treasure-hunt v2

This commit is contained in:
Alexander Heldt
2025-11-08 15:12:31 +01:00
parent 89739137e7
commit fad9b41d97

View File

@@ -3,8 +3,7 @@ import gleam/list
pub fn place_location_to_treasure_location(
place_location: #(String, Int),
) -> #(Int, String) {
let #(p, l) = place_location
#(l, p)
#(place_location.1, place_location.0)
}
pub fn treasure_location_matches_place_location(
@@ -18,20 +17,11 @@ pub fn count_place_treasures(
place: #(String, #(String, Int)),
treasures: List(#(String, #(Int, String))),
) -> Int {
let #(_, place_location) = place
list.fold(treasures, 0, fn(acc, t) {
let #(_, treasure_location) = t
case
treasure_location_matches_place_location(
place_location,
treasure_location,
)
{
False -> acc
True -> acc + 1
}
treasures
|> list.filter(fn(t) {
treasure_location_matches_place_location(place.1, t.1)
})
|> list.length
}
pub fn special_case_swap_possible(
@@ -39,24 +29,20 @@ pub fn special_case_swap_possible(
place: #(String, #(String, Int)),
desired_treasure: #(String, #(Int, String)),
) -> Bool {
let #(found_treasure_name, _) = found_treasure
let #(desired_treasure_name, _) = desired_treasure
let #(place_name, _) = place
case found_treasure_name {
"Brass Spyglass" -> desired_treasure_name == "Abandoned Lighthouse"
"Amethyst Octopus" ->
place_name == "Stormy Breakwater"
&& {
desired_treasure_name == "Crystal Crab"
|| desired_treasure_name == "Glass Starfish"
}
"Vintage Pirate Hat" ->
place_name == "Harbor Managers Office"
&& {
desired_treasure_name == "Model Ship in Large Bottle"
|| desired_treasure_name == "Antique Glass Fishnet Float"
}
_ -> False
case found_treasure, desired_treasure, place {
#("Brass Spyglass", _), _, #("Abandoned Lighthouse", _) -> True
#("Amethyst Octopus", _), #("Crystal Crab", _), #("Stormy Breakwater", _) ->
True
#("Amethyst Octopus", _), #("Glass Starfish", _), #("Stormy Breakwater", _) ->
True
#("Vintage Pirate Hat", _),
#("Model Ship in Large Bottle", _),
#("Harbor Managers Office", _)
-> True
#("Vintage Pirate Hat", _),
#("Antique Glass Fishnet Float", _),
#("Harbor Managers Office", _)
-> True
_, _, _ -> False
}
}