Ad
  • Custom User Avatar

    Expected is error, because there is more than one valid solution, for example:

    |328|756|491|   |328|756|491|
    |416|239|785|   |416|239|785|
    |795|418|263|   |795|418|263|
    +---+---+---+   +---+---+---+
    |983|542|176|   |983|547|126|
    |564|197|328|   |564|192|378|
    |172|683|954|   |172|683|954|
    +---+---+---+   +---+---+---+
    |649|375|812|   |649|375|812|
    |851|924|637|   |851|924|637|
    |237|861|549|   |237|861|549|
    

    If I copied everything correctly, you can see how the rows in the middle band are different.

  • Custom User Avatar

    Hello,

    I've got two issues. Timeout and random tests that fail.
    Timeout is the fun part. Random tests is the strange part and i need some help.
    If I believe the output of the attempt :

    Input:
    [3, 0, 0, 0, 0, 6, 0, 0, 0]
    [4, 1, 0, 0, 0, 0, 7, 8, 5]
    [7, 0, 0, 0, 0, 0, 0, 0, 0]
    [9, 8, 0, 5, 4, 0, 0, 0, 0]
    [0, 0, 0, 0, 0, 0, 0, 0, 0]
    [0, 0, 0, 0, 8, 3, 0, 5, 4]
    [0, 0, 0, 0, 0, 0, 0, 0, 2]
    [8, 5, 1, 0, 0, 0, 0, 3, 7]
    [0, 0, 0, 8, 0, 0, 0, 0, 9]
    Value is not what was expected
    

    My solution is wrong but I have no idea of the expected.

    My solver found this solution :

    [
      [ 3,9,8,7,5,6,4,2,1 ]
      [ 4,1,6,3,2,9,7,8,5 ]
      [ 7,2,5,4,1,8,9,6,3 ]
      [ 9,8,3,5,4,2,1,7,6 ]
      [ 5,4,2,6,7,1,3,9,8 ]
      [ 1,6,7,9,8,3,2,5,4 ]
      [ 6,7,9,1,3,5,8,4,2 ]
      [ 8,5,1,2,9,4,6,3,7 ]
      [ 2,3,4,8,6,7,5,1,9 ]
    ]
    

    What should be the expected output ?

  • Custom User Avatar

    I do katas to propose them as a training for people. To avoid that they take unclear or unconstructive katas i must try them before.
    I have the same complain than other people who complains :

    • test missing
    • no clear instruction
      ...
      Sad, the idea behind can be cool. But in this state, it's not a good kata. At least for me
  • Custom User Avatar

    If you are not using specific database functionality then you are using ANSI :smile:

    name alphabetically sorted test was split yesterday

    Thank you for your feedback

  • Custom User Avatar

    I firstly used rank() over (partition by people_id order by sth) and the result was also 1 for all the people, and all tests was positive. Additional tests seems to be necessary

  • Custom User Avatar

    Initially, yes I missed this part.
    But after re-reading the description i notice that the order was wrong. Anyway I did not update my code cause the error was not relative.

    After your comment, I made the good query and yes : it pass.

    But this test is very confusing :

    • should not use specific database functionality only ANSI (and no comments)

    It fail if the request if not good event if the 3 conditions in the test description are good.

    This Should be 3 tests :

    • should not use specific database functionality
    • should be only ANSI
    • should not have comment

    There should be some additionals tests :

    • Should return row_number relative to the order
    • Should be ordered by name
  • Custom User Avatar

    You missed the part where description says and the name of every people alphabetically, hence id row has not the same value of the row_number

  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    Thanks for your help. :)

    I did not arrive to make it work with your explanation but after a quick look to your solution,
    i made almost the same thing.
    My concern was probably the stopping condition.

    But i finish the exercice. How?

    After for modification to my algorithm, i was able to get to the response of calc(10,16) and calc(11,16) (from the attempt) and I notice that i was exactly the same that the results i get with my pure math function except the last number that was not in the right base.
    So i simply change into the right base the last number return by the fonction.

    It solve the exercice but :

    I am far from being good at math and I may have misunderstood some things in the links I have given but the results for n> 9 and n = 5 in base 10 may be wrong.

    The exercise remains interesting. :)

  • Custom User Avatar

    The reason I chose the '4' problem is that it's the shortest in base-10.
    Your problem is that 8 isn't the carry, it's the next digit; 0 is the carry.
    In multiplying the next digit and adding the carry, the product will always be 1 or 2 digits; the digit in the tens-place is the next carry and the digit in the ones-place is the next digit.

    I've worked the first several out below.

     2
    x2
    ==
    04
     ^--- 4 is the next digit, since the product < 10, we have a 0 carry
    
     0
     42
    x 2
    ===
    084
     ^---- this 8 is the next digit, it isn't a carry
                |
     00         |
     842 <------/
    x  2
    ====
    1684
    ^------ this 1 *is* a carry, and 6 is the next digit, 2 * 8 + (0 carry) = 16
    
     100
     6842
    x   2
    =====
    13684
    ^------ this 1 is the carry, 3 is the next digit (2 * 6 + 1 == 13)
    
     1100
     36842
     x   2
     =====
    073684
     ^------- product 2*3+1 -> 7 next digit, 0 carry
     
     
     01100
     736842
     x    2
     ======
    1473684
    ^---------- 1 is carry, 4 is next digit (2*7+0 = 14)
    
    101100
    4736842
    x     2
    =======
    9473684
    ^------------ 9 is next digit, 0 is carry (2 * 4 + 1 = 9)
    
     0101100
     94736842
    x       2
    =========
    189473684
     ^----------- 8 is next, 1 is carry (2 * 9 + 0 = 18)
    
    ...and so on.
    
    

    All you have left to determine is the stopping criteria and generalizing this algorithm for any number base. This should get you really close without taking the rest of the fun out.

  • Custom User Avatar

    Yes, this is the exemple written over wikipedia.
    I base my first attempt on this algorithm with this exemple. It's work well for calc(4,10) and calc(4,16)

    But now, let's try this algorithm with other number in base 10 : 2.
    calc(2,10) should result 105263157894736842 (Verify thx oeis.org/A092697/list)

    If you wrote the problem out starting at the right and worked left:

    2
    x2

    4

    This means that a number ending in 2 times 2 gives a product that ends in 4, so 4 is the next digit to the left of 2.
    We also figured out that we have to deal with a 0 carry.

    So in the number on the top, write a 4 with the 0 carry over the top to create the next iteration for the multiplication:

    0
    42
    x2

    84

    So now we know the digit to the left of the 4 in the multiplicand is 4, with a 8 carry.

    80
    42
    x2

    84 <-- almost same answer - the only difference is in the carries.

    And If i continue i have an infinite loop.

    So where's the fail? :x

  • Custom User Avatar

    These are interesting links. I'll give a big algorithmic hint that I may later flag as having spoiler content.

    Let's take the simplest base-10 problem: the 4-parasitic number ending in 4 is 102564 -- let's pretend we don't know the answer and see if we can figure out how to derive the 10256 part.

    If you wrote the problem out starting at the right and worked left:

     4
    x4
    ==
    16
    

    This means that a number ending in 4 times 4 gives a product that ends in 6, so 6 is the next digit to the left of 4. We also figured out that we have to deal with a 1 carry. Remember that the same set of digits are going to be in the top and the bottom, just shifted and the 4 rotated around to the beginning.

    So in the number on the top, write a 6 with the 1 carry over the top to create the next iteration for the multiplication:

     1
     64
     x4
    ===
    256
    

    So now we know the two digits to the left of the 4 in the multiplicand is 56, with a 2 carry. So expand the next digit out (note the carries across the top)

     21
     564
      x4
    ====
    2256
    

    I'm going to quit spelling the findings out and just write the rest of the iterations out:

     221
     2564
       x4
    =====
    10256 <-- this is the answer for what's to the left of 4, but if we continue...
    
    1221
    02564
       x4
    =====
    10256 <-- almost same answer - the only difference is in the carries and this time the lead digit rendered a 1 with no carry.
    
    01221
    102564
        x4
    ======
    410256 <-- the final product indicating the final answer has been reached for 4-parasitic ending in 4.
    
    The number is therefore "102564"
    

    The rest is really just a coding this up and accounting for which number-base you're dealing with.

  • Custom User Avatar

    Don't know if i will be happy or if i will be sad thinking about the time spent on this simple exercise...
    I now got a solution in full math that seem to work. My first attempt manipulated strings...

    But !
    Some tests always fail (22 tests pass/28).
    The 6 faillings test are the 6 in base 16 where n >= 10.
    For exemple : calc(10, 16) return me "1019c2d14ee410" which is "1019c2d14ee4" + "10"

    EDIT : In fact, i implemented https://oeis.org/A092697 so it logicaly fail.
    Does i should implement https://oeis.org/A128857 instead?

    Is it possible to know the result of calc(10, 16) ?

  • Custom User Avatar

    I hope you're feeling engaged not discouraged. This is one of those puzzles that I feel gives a sense of accomplishment after completing it.

  • Loading more items...