From 5e2434cff215c3a8815456b6b94670ba300b8715 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Sun, 5 Dec 2021 12:17:20 +0100 Subject: [PATCH] Day 5 Part 1: Not yet done and still readable --- d5golf.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 d5golf.hs diff --git a/d5golf.hs b/d5golf.hs new file mode 100644 index 0000000..69297ae --- /dev/null +++ b/d5golf.hs @@ -0,0 +1,16 @@ +import Data.List +type Board = [[Int]] +a&x|(u,_:v)<-break(==x)a=u:v&x|let=[a] +printfield :: Board -> String +printfield = intercalate "\n".map printrow +printrow :: [Int] -> String +printrow = concatMap show +createField :: [Int] -> Board +createField [x,y] = 0<$[0..x]<$[0..y] +drawPixel :: (Int,Int) -> Board -> Board +drawPixel (x,y) m|(l,h:r)<-splitAt x m,(u,v:d)<-splitAt y h=l++(u++(v+1):d):r +drawLine [x,y] [a,b] m = foldr drawPixel m [(u,v)|u<-[x..a],v<-[y..b]] +minmax x=map(maximum.(x>>=))[head,last] +p::[String] -> [[Int]] +p[s,_,t]=map(map read.(&','))[s,t] +main=interact$printfield.drawLine [1,0][1,2].drawLine [0,0] [4,0].createField.minmax.map(p.words).lines