Day 5 Part 1: Not yet done and still readable
This commit is contained in:
parent
65450ca033
commit
5e2434cff2
1 changed files with 16 additions and 0 deletions
16
d5golf.hs
Normal file
16
d5golf.hs
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue