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.
exactly , i don't know why people talking about negative values when your code is already pass the goal of the exercise/test
But we return square digit, and negative in square is a positive number. So I think it doesn`t matter
Checking for sum of [1,2,...n] is NOT enough for a perfect solution,
eg. your program gives True for
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
which obviously is an invalid sudoku of 1,2,...,9
(but it does have sum of 45 in every row, column, and small square)
You have to make statistics of the occurred elements too to determine if the solution is valid.
Your idea basically is nice, but it has one flaw:
eg. your solution gives True for
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
{ 5,5,5 5,5,5 5,5,5 }
which obviously is an invalid sudoku of 1,2,...,9
(but it does have sum of 45 in every row, column, and small square)
You have to make statistics of the occurred elements too to determine if the solution is valid.
This comment is hidden because it contains spoiler information about the solution
"The function accepts an integer and returns an integer"
Solution does not work for negative integers (result is always a positive integer due to b * b)
"The function accepts an integer and returns an integer"
Solution is very compact but unfortunately
does not work for negative integers ('-' sign converted to '1')
This comment is hidden because it contains spoiler information about the solution