Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Although this isn't a requirement for this kata, a minor improvement would be to use
isSpace
instead ofisAlpha
so characters that aren't alphabetical are captured correctly.Omg wtf HAHAHHAHAHHA
It does not work for this sudoku for example :
[[5 3 4 6 7 8 9 2 2]
[6 7 2 2 9 5 3 4 8]
[2 9 8 3 4 2 5 6 7]
[8 5 9 7 6 2 4 2 3]
[4 2 6 8 5 3 7 9 2]
[7 2 3 9 2 4 8 5 6]
[9 6 2 5 3 7 2 8 4]
[2 8 7 4 2 9 6 3 5]
[3 4 5 2 8 6 2 7 9]]
I replaced all 1s in a valid sudoku by 2s.
euyemura,
combination(k)
returns anEnumerable
, not anArray
of all the combinations. TheEnumerable
is lazy and will only find out the next combination when you call for the next value. When calling anEnumerable
method likereduce
on the return value ofcombination(k)
you canbreak
out of the loop and return early in you want, hence not wasting cycles. In this kata, I would break out early if my current sum matchest
exactly. The solution above does not do this so will always have to sum all combinations so there is a bit of room for performance improvement, but not much.Can't do better than linear time, constant memory. I suspect something's fishy in the tests.
Sorry, late response. You can pass a block into
ls.combination(k)
instead of to the.map
function, which would allow you to exit early. However, the target distance is a limit, not a minimum. Since each combination you try might be higher than your last max and lower than the limit, we must visit every single combination to be sure of our answer.Good thinking though =D
Hello! yours is top voted so i wanted to ask you and everyone else, is there a better way to do this than to use .combination(k)? If i'm not not mistaken this method creates every single combination, as opposed to doing something like making every combination in order until it creates an array with a sum that is over the target distance and then stopping. I ended up using combination as well, but isn't the time efficiency of it pretty bad? Your solution is super elegant, just want to understand if there's more efficient ways.
Would you resubmit your translation? I couldn't approve the current version (description changed)
Oh, just make sure you put the empty function in the "solution setup":
Cheers
No, I think the kata is clear about being sequential by 1.
I like your solution, it's very well organized, but I think the sequential part is wrong. The instructions just say the number has to be sequential, but doesn't specify that it has to be +/- 1 for each number. Even though the test cases don't have any other types of sequential sequences, your solution would be wrong if the number was 741 for instance. That's still a sequential number in my opinion, even though it doesn't decrement by 1. Overall nice job though, much more concise than mine!
EDIT: I just refactored my solution using some stuff from yours, but with a method for sequential numbers that works for any sequence (I think), if you're interested in taking a look.
Yeah good point, this still isn't fixed. Thought it was an issue with my code as I was using the "permutation" method!
Very nice solution, I like it!
Please have a look at https://github.com/bbatsov/ruby-style-guide, it's better to use &&, || etc. operators over keywords like 'and', 'or' and the 'return' keyword is not needed.
Date is in the title!
How about adding the 'date and time' tag?
Loading more items...