Retired

Recursion #1 - Factorial (retired)

6,007 of 8,336gabrielsiedler
Description
Loading description...
Fundamentals
Recursion
Mathematics
  • Please sign in or sign up to leave a comment.
  • wulei Avatar

    Should return n and fact (n!) -- SQL

  • hobovsky Avatar

    This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/190.
    Please join the discussion to help us identify duplicate kata and retire them.

  • seanburlington Avatar

    https://docs.codewars.com/authoring/guidelines/translation/

    "Do not translate kata into languages where the difficulty would significantly differ"

    The SQL version is significantly harder

    Should it really exists as a translation ?

    Functions in SQL are an advanced issue.

  • Madjosz Avatar
  • gRubies Avatar

    Very bad description. It is not clear what output data is expected, the final number, an array with a sequence of numbers, or a table (number, value). The tests are poorly designed, you can simply write the desired result with fixed data.

  • sashashi Avatar

    All the task instruction for SQL is "You have to create the function factorial that receives n and returns n!. You have to use recursion" but the test expects 17 results instead of a function. Even if the test accepts a function as result, including the keywords from the test is still way too difficult for 7 kyu

  • zulfiya-yumagulova Avatar

    I have passed all tests exept one, which says: RangeError: Maximum call stack size exceeded in javascript. And I can't sumbit it.

  • Nicolai1205 Avatar

    This was extremely hard, but incredibly satisfying to solve. Cheers.

  • Kacarott Avatar

    Fork which fixes markdown headers in description (author inactive)

  • Lucasss Avatar

    This comment has been hidden.

  • maldabba Avatar

    On postgresql and I get error that it should recieve X Values?

  • lbvf50mobile Avatar

    For ones who has PG::NumericValueOutOfRange: ERROR: integer out of range check 4.1.2.7. Constants of Other Types or this Stack Overflow answer. Documentation about recursive request creation could be found here 7.8.1. SELECT in WITH.

    This kata has poor description but brings profit. Thanks @eliseuvideira for the comment. And thanks the kata author for his work too.

  • nemo.rmn Avatar

    It was really hard to figure out what to do because:

    • description says to create a recursive function
    • but comment says to create a table recursively (I am sorry what?)
    • but test says 'do not create table'

    This is kind of mess in description that makes people go wrong way many times during solving the kata. Please make instructions clear for SQL

  • KetoTim Avatar

    This comment has been hidden.

  • eliseuvideira Avatar

    The SQL version of this kata should contain better instructions, like that the result should contain 17 rows, with numbers from 0 to 16 as a column named "n" and another column named "fact", with the factorial value of "n", also that you are not allowed to use CREATE FUNCTION, intead should use WITH RECURSIVE cte.

  • SumitKPandit Avatar

    Training in PostgreSQL 9.6

    Expected 17, Got 0

    Factorial of what number is 17? The question expects something it doesn't explain. Why should the function return 3 values?

  • lelle12 Avatar

    Does not appear to be working for SQL (postgres 9.6). It says expected 17 results, 0 found (or something similar). I validated my function against a real psql 9.6 and it works.

  • FArekkusu Avatar

    create recursively the table with n up to 16

    This can be down with a CTE or a function, and recursion actually implies their use.

  • FArekkusu Avatar

    create recursively the table with n up to 16

    It's not clear whether a row with n = 16 should be included or not.

  • Blind4Basics Avatar
  • bpolgardy Avatar

    How's this 7 kyu in SQL, lol?

  • MTwem Avatar

    Too hard for 7. Pls bump up to 5

  • poiuyt4321 Avatar

    I am trying to solve this kata in sql, but I don't understand how the solution is evaluated. I have created a function that does the what is requested, so if I do: SELECT factorial(3) I get the correct result of 6. Inputting the other values also returns the correct answer. Can anyone help?

  • bionicbrian Avatar

    (TypeScript): The requirement that "it calls itself" doesn't allow for tail call optimization using an inner "tail-call optimized" function. Was able to pass the checks with unnecessary conditionals for 1 and 0 in the "outer" function. :/

  • Javatlacati Avatar

    SQL Translation kumited! Please accept :smile:

  • hksong Avatar

    Javascript does not work.

    [eval]:6
                    const require = _ => void 0;
                                       ^
    SyntaxError: Unexpected token >
        at Object.<anonymous> ([eval]-wrapper:6:22)
        at 
        at evalScript (node.js:536:25)
        at startup (node.js:80:7)
        at node.js:906:3
    
  • NMAC Avatar

    Don't working :(

  • Javatlacati Avatar

    CoffeeScript Translation kumited! Please accept :D

  • chilversc Avatar

    This comment has been hidden.

  • aaron.rowan Avatar

    This comment has been hidden.

  • Osuology Avatar

    Anti-cheating methods probably shouldn't be this way. As someone else mentioned, it should be a random test.

  • user5036852 Avatar

    Nice kata!

    C#-Translation kumited!

    https://www.codewars.com/kumite/5795431e3467dbdb140001d4

    The anti-cheating test is very different from yours. But your way is not possible for C#. But my anti-cheating test works, too. :-)

  • user8476848 Avatar

    Kata is in a non-working state and even if you submit a previously accepted solution there is no way to pass the tests. Suggest it be pulled back to draft mode until the tests are fixed.

  • cindy0092 Avatar

    I keep getting below's error when I try to run the test. I even copied and paste someone else solution in this Kata, I still get the same error, can anyone fix the problem (or swtich back to old javascript).

           const require = _ => void 0;
                               ^
    

    SyntaxError: Unexpected token > at Object. (eval-wrapper:6:22) at at evalScript (node.js:536:25) at startup (node.js:80:7) at node.js:906:3

  • KyleShaver Avatar
    const require = _ =>; void 0;
                       ^
    

    This is preventing both the test cases and the submission tests from running, meaning this kata can not be completed. Since this has been an issue for a month, maybe converting the kata to regular old javascript might be an option?

  • hksong Avatar
    const require = _ => void 0;
                        ^
    

    Issue with test case. Throwing error even with no code or empty function.

  • masungwon Avatar

    it said that my tests passed initially, and when I clicked it again it said that they didn't pass. when I clicked on the run tests for the third time, the tests then passed again.

  • donaldsebleung Avatar

    Great Kata, this is the first recursion Kata that I have completed without any help :D

  • matt c Avatar

    I can see your test cases are trying to check whether solutions are hardcoded but this is not the way to go about testing hardcoded solutions, Random test cases are always the best way to eliminate hardcoded solutions :)

  • matt c Avatar

    Exact duplicate of: http://www.codewars.com/kata/the-elegance-of-the-code/javascript Even the test cases are basically the same.

  • matt c Avatar