<div dir="auto">How did it go?<div dir="auto"><br></div><div dir="auto">When I solved that AoC problem I ended up using the matrix package: <a href="http://hackage.haskell.org/package/matrix">http://hackage.haskell.org/package/matrix</a></div><div dir="auto"><br></div><div dir="auto">/M</div><div dir="auto"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 19 Dec 2016 7:31 pm, "mike h" <<a href="mailto:mike_k_houghton@yahoo.co.uk">mike_k_houghton@yahoo.co.uk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><font size="4">Thanks for the pointers - I’ll take a look.</font></div><div><font size="4"><br></font></div><div><font size="4">The background to this is one of the puzzles on Advent Of Code 2016 Q.8.</font></div><div><a href="https://adventofcode.com/2016/day/8" target="_blank">https://adventofcode.com/2016/<wbr>day/8</a></div><div><br></div><div><font size="4">There are (several hundred) sequential  operations on a grid 50 x 6  - initially all zeroes</font></div><div><font size="4">e.g. </font></div><div><font size="4">rotate row y=0 by 4 </font></div><div><font size="4">rect 2x1 — sets sub grid from (0,0) to (2,1) to all 1s</font></div><font size="4">rotate column x=35 by 1</font><div><font size="4"><br></font></div><div><font size="4">I’m fine about parsing the input to a data structure and executing them i.e. </font></div><div><font size="4"><br></font></div><div><font size="4"><div>evalExpr :: Expr -> Screen -> Screen     — screen is essentially [[Int]]</div><div>evalExpr e s =</div><div>    case e of</div><div>        (Rect   r c ) ->     evalRect   r c s</div><div>        (RotRow r by) -> evalRotRow r by s</div><div>        (RotCol c by) -> evalRotCol c by s</div><div>        (NOP        ) -> id s</div><div><br></div><div>rotating a row was simple enough, code to  rotate column a bit untidy and not very nice. The </div><div>evalRect  - which sets values to one in the rectangle of size r x c starting at (0,0) top left - triggered the original question.</div><div><br></div><div><br></div><div>At this point  my knowledge of Haskell is being pushed (which is good) but I have a feeling that </div><div>my approach is not ‘correct’ once it gets beyond the parsing. Should each of the evalRect, evalRotRow and evalRotCol be called with a Screen (i.e. the grid at the root of this question)?</div><div>Is the state monad a fit for this problem?</div><div>Should I change my approach or is using vector the way forward?</div><div><br></div><div>Many thanks</div><div><br></div><div>Mike</div></font><font size="4"><div><br></div><div><br></div><div><br></div><div><br></div></font></div><div><font size="4"><br></font><div><blockquote type="cite"><div><font size="4">On 19 Dec 2016, at 15:27, Michael Orlitzky <<a href="mailto:michael@orlitzky.com" target="_blank">michael@orlitzky.com</a>> wrote:</font></div><font size="4"><br class="m_-1037435723290963001Apple-interchange-newline"></font><div><div><font size="4">On 12/19/2016 08:10 AM, mike h wrote:<br></font><blockquote type="cite"><font size="4">Hi,<br><br>I’m looking a problem where I have an NxN grid of ints. I need a<br>function like setValue x y newVal<br><br>I have tried using [[Int]] but it does become messy when splitting ,<br>dropping and then ++ back together.<br><br>What other options are available to represent a mutable grid?<br><br></font></blockquote><font size="4"><br>Mutable vectors (from the vector[1] package) are an obvious choice. When<br>I had to do something similar, I wound up going all the way to repa[2],<br>which magically turns all of your grid operations into parallel ones.<br><br><br>[1] <a href="https://hackage.haskell.org/package/vector" target="_blank">https://hackage.haskell.org/<wbr>package/vector</a><br>[2] <a href="https://hackage.haskell.org/package/repa" target="_blank">https://hackage.haskell.org/<wbr>package/repa</a><br><br>______________________________<wbr>_________________<br>Beginners mailing list<br><a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br></font></div></div></blockquote></div><br></div></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div></div>