Ad
  • Custom User Avatar

    exactly , i don't know why people talking about negative values when your code is already pass the goal of the exercise/test

  • Default User Avatar

    But we return square digit, and negative in square is a positive number. So I think it doesn`t matter

  • Default User Avatar

    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.

  • Default User Avatar

    Your idea basically is nice, but it has one flaw:

    • checking for sum of [1,2,...n] is NOT enough for a perfect solution,

    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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    "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)

  • Default User Avatar

    "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')

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution