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