day1
This commit is contained in:
14
day1/app/Main.hs
Normal file
14
day1/app/Main.hs
Normal 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
33
day1/day1.cabal
Normal 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
|
||||
Reference in New Issue
Block a user