Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
Code block support is not fully rolled out yet but likely will be in the middle of the event. Try to share solutions as both code blocks and using something such as https://topaz.github.io/paste/ , pastebin, or github (code blocks to future proof it for when 0.19 comes out and since code blocks currently function in some apps and some instances as well if they are running a 0.19 beta)
Is there a leaderboard for the community?: We have a programming.dev leaderboard with the info on how to join in this post: https://programming.dev/post/6631465
π Thread is locked until there's at least 100 2 star entries on the global leaderboard
Wouldn't this code fail in a case like this? Because you count different lines, not different characters in the lines, right? Or am I missing something? Thanks
(Let's ignore column symmetry for the sake of example).
##
..
..
..
(I think you will get answer 100, but the answer is 300)
But for sure after seeing this I have to learn Scala.
On your example, my code produces 301, which matches your 300 ignoring column symmetry (and 0 for task2, as there is no way to smudge a single cell to create symmetry).
Let me explain the code real quick: What smudgesAround does is compute the number of tiles you would need to change to create a symmetry around index i. First, toEdge is the number of tiles to the nearest edge, everything after that will be reflected outside the grid and won't matter. Then, for each actually relevant distance, we compare the rows/columns this distance from i. By zipping them, we create an Iterator that first yields the pair of first entries, then the pair of second entries, and so on. On each pair we apply a comparison, to count the number of entries which did not match. This is the number of smudges we need to fix to get these rows/columns to match. Summing over all relevant pairs of rows/columns, we get the total number of smudges to make i a mirror line. In symmetries, we just check each i, for task1 we want a mirror line without smudges and for task2 we want a mirror line for exactly one
You can also make this quite a bit shorter, if you want to sacrifice some more readability: