{-# Language BangPatterns, QuasiQuotes #-}
module Main where
import Advent (format)
import Data.List (delete)
main :: IO ()
IO ()
main =
do input <- [format|2017 24 (%d/%d%n)*|]
let bridges = Int -> Int -> Int -> [(Int, Int)] -> [(Int, Int)]
search Int
0 Int
0 Int
0 [(Int, Int)]
input
print (maximum (map snd bridges))
print (snd (maximum bridges))
orient ::
Int ->
(Int,Int) ->
[(Int,Int)]
orient :: Int -> (Int, Int) -> [(Int, Int)]
orient Int
a (Int
b,Int
c)
| Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
b = [(Int
b,Int
c)]
| Int
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c = [(Int
c,Int
b)]
| Bool
otherwise = []
search ::
Int ->
Int ->
Int ->
[(Int,Int)] ->
[(Int,Int)]
search :: Int -> Int -> Int -> [(Int, Int)] -> [(Int, Int)]
search !Int
len !Int
weight !Int
match [(Int, Int)]
pieces =
(Int
len,Int
weight) (Int, Int) -> [(Int, Int)] -> [(Int, Int)]
forall a. a -> [a] -> [a]
:
do piece <- [(Int, Int)]
pieces
(a,b) <- orient match piece
search (len+1) (weight+a+b) b (delete piece pieces)