Wanting to continue with the Haskell approach of using just lists, which looks back at one of my favourite books from collage Brid and Wadler's Introduction to Functional Programming, I decided to allow my self one function, from the lens package, that is not in Haskell's standard of functions. At some point I guess it might get much of a performance issue to remain with just lists, but for now we continue.
That being said I could not face working with binary date in Haskell, directly at least, and so took a slightly lazy approach with calulating mid points, rather than going for swapping letters for 0 and 1.
-- we need to accumulate, rather than simply foldfoldl'fz[]=zfoldl'fz(x:xs)=letz'=z`f`xinseqz'$foldl'fz'xs-- calculate our half way rangehalf=(\rangesm->ifm=='F'||m=='L'thenfstrangeselsesndranges).rangeswhereranges(min,max)=letmp=(min+max)`div`2in((min,mp),(mp+1,max))-- calculate a seat numberseatis=let(rs,cs)=splitAt7is(r,_)=foldl'half(0,127)rs(c,_)=foldl'half(0,7)csin(r*8+c)main=doxs<-readFile"day5_input"<&>linesletseats=mapseatxsprint(maximumseats)print$fst$head$dropWhilesnd$dropWhile(not.snd)$zip[0..](foldrupdateemptySeatsseats)whereemptySeats=map(constFalse)[0..1023]updates=elements.~True
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Wanting to continue with the Haskell approach of using just lists, which looks back at one of my favourite books from collage Brid and Wadler's Introduction to Functional Programming, I decided to allow my self one function, from the lens package, that is not in Haskell's standard of functions. At some point I guess it might get much of a performance issue to remain with just lists, but for now we continue.
That being said I could not face working with binary date in Haskell, directly at least, and so took a slightly lazy approach with calulating mid points, rather than going for swapping letters for 0 and 1.