Skip to content

Commit

Permalink
shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 11, 2023
1 parent fa01dd9 commit 5278cb1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions solutions/src/2023/11.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# Language QuasiQuotes, NumericUnderscores, ImportQualifiedPost #-}
{-# OPTIONS_GHC -Wall -Wno-x-partial #-}
{-|
Module : Main
Description : Day 11 solution
Expand All @@ -11,9 +12,7 @@ Maintainer : emertens@gmail.com
-}
module Main where

import Data.Set (Set)
import Data.Set qualified as Set
import Data.List
import Data.List (inits, tails)
import Data.Map qualified as Map
import Advent
import Advent.Coord (coordLines, Coord(C))
Expand All @@ -30,13 +29,10 @@ main =
let rows = Map.assocs (counts [y | C y _ <- galaxies])
let cols = Map.assocs (counts [x | C _ x <- galaxies])

let solve1 n xs =
sum
[ (fst (head r) - fst (last l) - 1) * n * (sum (map snd l) * sum (map snd r))
let solve1 n xs
= sum
[ ((fst (head r) - fst (last l) - 1) * n + 1) * sum (map snd l) * sum (map snd r)
| (l,r) <- zip (inits xs) (tails xs), not (null l), not (null r)]
+ sum
[ sum (map snd l) * sum (map snd r)
| (l,r) <- zip (inits xs) (tails xs)]

let solve n = solve1 n rows + solve1 n cols

Expand Down

0 comments on commit 5278cb1

Please sign in to comment.