This commit is contained in:
Joey Eamigh
2024-12-01 14:01:33 -05:00
commit 7ca9b1d3f6
9 changed files with 1144 additions and 0 deletions

14
day1/app/Main.hs Normal file
View File

@@ -0,0 +1,14 @@
module Main (main) where
import Data.List (sort, transpose)
import Text.Printf (printf)
-- readFile "./inputs/day1" >>= \inputs -> let columns = map sort $ map (map (read :: String -> Int)) $ transpose $ map words $ lines inputs in printf "total distance: %d\n" (sum $ map abs $ zipWith (-) (columns !! 0) (columns !! 1)) >> printf "similarity score: %d\n" (sum $ map (\x -> x * (length $ filter (\y -> x == y) (columns !! 1))) (columns !! 0))
main :: IO ()
main = do
inputs <- readFile "./inputs/day1"
let columns = map sort $ map (map (read :: String -> Int)) $ transpose $ map words $ lines inputs
printf "total distance: %d\n" (sum $ map abs $ zipWith (-) (columns !! 0) (columns !! 1))
printf "similarity score: %d\n" (sum $ map (\x -> x * (length $ filter (\y -> x == y) (columns !! 1))) (columns !! 0))

33
day1/day1.cabal Normal file
View File

@@ -0,0 +1,33 @@
cabal-version: 2.2
-- This file has been generated from package.yaml by hpack version 0.37.0.
--
-- see: https://github.com/sol/hpack
name: day1
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/day1#readme>
homepage: https://github.com/githubuser/day1#readme
bug-reports: https://github.com/githubuser/day1/issues
author: Author name here
maintainer: example@example.com
copyright: 2024 Author name here
license: MIT
build-type: Simple
source-repository head
type: git
location: https://github.com/githubuser/day1
executable day1
main-is: Main.hs
other-modules:
Paths_day1
autogen-modules:
Paths_day1
hs-source-dirs:
app
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
default-language: Haskell2010