After discussing with my partner I thought I should do the binary version too, so here is a slightly modified version, but rather than using Haskell binary stuff, just used fold to convert the binary string to an int.
-- 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 numberseat=toDec.map(\x->ifx=='F'||x=='L'then'0'else'1')wheretoDec=foldl'(\accx->acc*2+digitToIntx)0main=doxs<-readFile"day5_input"<&>linesletseats=mapseatxsprint(maximum(mapseatxs))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.
After discussing with my partner I thought I should do the binary version too, so here is a slightly modified version, but rather than using Haskell binary stuff, just used fold to convert the binary string to an int.