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.
This is nice except that every single one of 4
if
s will be tested even though at most 1 can be truthy.Please add some comment to your solution. It is giberrish IMO
Why? You are reducing to a single number according to the data ops. The only time there is no operation on that number is for operation
o
, which just pushes the number to the main function's output array. Seems pretty straightforward.I've done it a bit differently in that my reduce function builds the main output array but I like this top solution, focusing on the number itself.
I'm sorry. How careless of me.
Wrong solution.How about board with -1 and 10 ? just like this(all 1 is replaced by -1 and all 9 is replaced by 10)
[
[5, 3, 4, 6, 7, 8, 10, -1, 2],
[6, 7, 2, -1, 10, 5, 3, 4, 8],
[-1, 10, 8, 3, 4, 2, 5, 6, 7],
[8, 5, 10, 7, 6, -1, 4, 2, 3],
[4, 2, 6, 8, 5, 3, 7, 10, -1],
[7, -1, 3, 10, 2, 4, 8, 5, 6],
[10, 6, -1, 5, 3, 7, 2, 8, 4],
[2, 8, 7, 4, -1, 10, 6, 3, 5],
[3, 4, 5, 2, 8, 6, -1, 7, 10],
]
Using reduce as a quasi loop without even returning any reduced value is kind of ugly to my taste.
Прекрасное решение через Set! Однако, с точки зрения алгоритма, код можно улучшить.
Цикл for следовало бы включить в функцию validSet, и затем проверять валидность поэтапно, а не единожды в конце...
Ведь если, к примеру, строки (rowSet) не валидны, то составлять столбцы (columnSet) и квадраты (boxSet, boxCorner) дальше уже не имеет смысла.
Да, при этом код стал бы внешне чуть менее лаконичным, но думаю это было бы логичнее и производительнее.
Although it checks for uniqueness, the numbers could still be greater than 9
good
This is the kind of functional programming i am striving to learn how to write.
Super clever
boxCorner is so impressive how did u come with this idea i mean how good are u at math ? i want to become better i u can give me some tips
Very elegant use of the Set here. Congratulations.
Can somebody explain this answer please?
This comment is hidden because it contains spoiler information about the solution