THank you! But what do you call this sort of operation? - "%.2X%.2X%.2X" % [arr]- I'm looking for a key term to google so I can learn more about how to use this tool, and how it works. Is it shorthand for something else?
You're right. His solution doesn't correctly validate all sudokus - it just passes all the test cases. Find any valid sudoku and swap the 6th and 7th rows to create an example invalid solution that this solution incorrectly passes.
This is how it's broken down:
First, look at the two BIG pieces: "String Format" % what_to_format (takes array as input)
So, left side is saying, "format as hexidecimal", right side is saying...
"take r,g,b array, and "map" it. What map does is take each element, and transform it somehow. How? you tell it how in the function that you pass it. The function he's passing is taking the r,g,b numbers and ensuring that they are between 0 and 255. if they're not, it forces them into that range.
So in the end it looks something like this "%.2X%.2X%.2X" % [27,255,133] (or whatever rgb values it is)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Didn't know about the argument for
with_index
. Great!This comment is hidden because it contains spoiler information about the solution
https://github.com/bbatsov/ruby-style-guide#sprintf
http://ruby-doc.org/core-2.3.0/Kernel.html#method-i-format
THank you! But what do you call this sort of operation? - "%.2X%.2X%.2X" % [arr]- I'm looking for a key term to google so I can learn more about how to use this tool, and how it works. Is it shorthand for something else?
Absolutely agree, this has been a fun challenge. Though I think I'll have to keep myself from ordering an 'yvvi' in the future :]
You're right. His solution doesn't correctly validate all sudokus - it just passes all the test cases. Find any valid sudoku and swap the 6th and 7th rows to create an example invalid solution that this solution incorrectly passes.
This is how it's broken down:
First, look at the two BIG pieces: "String Format" % what_to_format (takes array as input)
So, left side is saying, "format as hexidecimal", right side is saying...
"take r,g,b array, and "map" it. What map does is take each element, and transform it somehow. How? you tell it how in the function that you pass it. The function he's passing is taking the r,g,b numbers and ensuring that they are between 0 and 255. if they're not, it forces them into that range.
So in the end it looks something like this "%.2X%.2X%.2X" % [27,255,133] (or whatever rgb values it is)
You have to return answers in a kata, not merely print or puts them.
Hope this helps :)