5 kyu

Josephus Survivor

4,245 of 16,827GiacomoSorbi
Description
Loading description...
Mathematics
Combinatorics
Algorithms
Lists
Arrays
  • Please sign in or sign up to leave a comment.
  • Asilver-jpg Avatar

    This comment has been hidden.

  • AFireInside777 Avatar

    Does anyone know what numbers they use for the final test at the end that keeps timing out?

  • tafens Avatar

    This comment has been hidden.

  • rineez Avatar

    The kata description says we can assume n>=1, but random test cases are sometimes generating n=0.

  • Dentist Avatar

    I have passed all the assertions, but I just can't understand what is meant by "Should work for random inputs too". I simply don't get it, call me newbie but please give me a hint... These are not other types, not negative n. What is it then??????

  • Jammer7373 Avatar

    This needs to support a newer version of F#. Important (efficient) List functions and operations are missing (or crash) in the ancient version of F# that is supported. That means I have to fall-back to older functions that are many orders of magnitude slower and cause the submission tests to time out. Like others here, I'm opposed to a purely math solution being the only option.

  • Style Magnus Avatar

    This comment has been hidden.

  • migzaws@@ Avatar

    Execution Timed Out (12000 ms)error is my code wromg im newbie

  • Just4FunCoder Avatar

    Python fork

    • Fixed test framework setup
    • changed description (josephus_survivor(7,3) => means 7 people in a circle;) to be more language agnostic
  • Nad.Chel Avatar

    It passes all the sample tests in my IDE, but times out here. How could I optimize the performance of my method? I create an ArrayList and iterate through it removing elements until only one is left. I have an inkling that it's a math thing. Not my strongest suit

  • Joe K Avatar

    In C# I keep running into an issue where index is out of range. I suspect that something is wrong with my code or CodeWars itself has the issue. The size of the list had a count of 1. I'm accessing it at list[0] which should still be inbounds. However, it keeps saying my answer is out of bounds.

  • cmorris Avatar

    Fun challenge. For anyone whose solution times out, I would recommend rethinking your algorithm. It's tempting to think that you need to constantly iterate over each element of the array, but you actually don't.

  • toni.g.m Avatar

    I really dislike this kind of Kata. It's trivial to solve programmatically, but the programmatical solution is prevented through absurdly large test cases and hard-capped computation time. Instead, the solution is to calculate it. This isn't mathwars, this is codewars. Why is this flagged as an algorithm kata when the only "algorithm" is to implement a math formula that someone else came up with?

  • vall-ball Avatar

    I see for PowerShell: 14 of 11,796 Is it possible to pass this kata in PS?

  • HonZaTri Avatar

    Wow. Really tough (took me 3 hours? C# pro(programming for living :) ) who programming for 1,5y from zero). Pretty practice for processing of edge cases.

    Would be interesting, do more performance targeted version. That is what I would be scared by with my solution :D

  • noqwA Avatar

    idk how to optimise my code. Did by myself first. then by internet and there are no suitable solutions. Can smn help?

  • Divinity Avatar

    so im very annoyed my code passes all 38 tests, and times out on the very last one: josephusSurvivor(4687, 4892) man this is unfair :D no clue how to optimize rip

  • user5272014 Avatar

    What's up with these college boy math problems? How about a little creativity?

  • kekia Avatar

    how to know which number is taken out ???is it random?

  • akar-0 Avatar

    COBOL translation updated to new tests framework.

  • el-f Avatar
  • rampdedlizer Avatar

    If you know Josephus Permutation, it becomes easy ~

  • Nam01ar Avatar

    mm dont understand this list 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11

    I return 7, it shoulkd equal 10...dont see why

  • lilsweetcaligula Avatar

    The e-eye of the tig-uurr!

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • jacksonbenete Avatar

    It is not a hard kata, but depending of the language you're using you can be lacking some Array/List facilities and will demand some thinking. I agree it's more of a mathwars kind of problem. I suggest you to write it down step by step with pen and paper if you want to spot some error on your reasoning.

  • HWstar24 Avatar

    what is test6? how can I tell? I passed all of them except for it.

  • ElderBlade Avatar

    This comment has been hidden.

  • robochat Avatar

    This comment has been hidden.

  • RealKenshiro Avatar

    Funny Kata! Arigatou Gozaimasu!

  • rhymu8354 Avatar

    This kata has little to do with programming, and mostly to do with math. Respectfully, in my opinion, it should go on mathwars.com not codewars.com

  • ilya_plotnikov Avatar

    Need a test with consecutive numbers, like (19,20). I was able to get through all tests with a mistake in my code. Only cought it on Josephus Permutation.

  • atmurray0013 Avatar

    In JavaScript I fail the test cases for the josephusSurvivor(14,2). It say expected 28, but got 13. The expected is actually outside the range of the input since I thought the max value would be 14, and from the test cases on the side 13 is the correct answer. Thought I would see if anyone else had a similar issue with the test cases.

  • pythor77 Avatar

    This comment has been hidden.

  • s0g00d Avatar

    passes all tests but does not work.

  • aarush Avatar

    Enjoyed Solving this Kata 😊

  • PLAT1N Avatar

    This comment has been hidden.

  • AnhSang Avatar

    This comment has been hidden.

  • jazell Avatar

    why does 2 get eliminated here why not 4? why does 7 get eliminated here why not 5? are the people chosen at random i though if input is 7,3 it means every third person is eliminated . Am i understanding it wrong ?

  • user8436785 Avatar

    This comment has been hidden.

  • Spear Gato Avatar

    The PHP version seems to have an issue with the final test, I checked the time taken and output whats happening to ensure the checks are completed within the 12 second time frame, yet it still thinks my code is taking too long?

  • Dr. Lugo Avatar

    This comment has been hidden.

  • niraj185 Avatar

    Looking for more tips. I solved by computing list, it works fine for test but not in attempt, due to lack of algorithem.

  • user8436785 Avatar

    CFML, NASM, OCaml, and Prolog translations.

  • rajat004 Avatar

    I think there is something wrong with this Kata, I am not able to choose python language. Whenever I am trying to choose Python, I does not response. What is the problem? I never wrote test cases before so There could be my own mistake also

  • Bas Celik Avatar

    This comment has been hidden.

  • davidamey Avatar

    The Haskell sample tests have the solution-method in them. Probably shouldn't!

  • user8436785 Avatar
  • mario31 Avatar

    This comment has been hidden.

  • fibonaccios Avatar

    Such a nice kata Giacomo, although I failed 'Josephus Permutiations' and unlocked solutions, I learned from that and managed to solve this. Thanks for the amazing kata!

  • user8436785 Avatar
  • DannyS95 Avatar

    This comment has been hidden.

  • DannyS95 Avatar

    This comment has been hidden.

  • ASDFGerte Avatar

    This comment has been hidden.

  • Helge801 Avatar

    GO Translation kumited - Please review and approve

  • lukeyates1981 Avatar

    Is there a flaw in the tests for PHP on this kata?

    The first few sets of tests work and complete in under 0.3ms, but then the "testRandom" times out saying it took longer than 12 seconds to execute.

    I can't imagine the random tests would take that much longer to run than all the others!

  • donaldsebleung Avatar

    I just noticed a contradiction between the Kata Description and the JavaScript random test cases when authoring the PHP translation to this Kata. The Description explicitly states:

    Notes and tips: using the solution to the other kata to check your function may be helpful, but as much larger numbers will be used, using an array/list to compute the number of the survivor may be too slow; you may assume that both >> n and k will always be >=1 <<.

    But the value of n in the JavaScript random tests seems to range from 0 to 5000, both inclusive, if I read the code correctly. I originally wanted to edit the Kata myself to resolve this minor Issue but then realized that the edit button wasn't there.

  • donaldsebleung Avatar

    PHP Translation Kumited - please carefully review and approve :D

  • DSchwettmann Avatar

    This comment has been hidden.

  • K01egA Avatar

    In haskell translation module by default named Codewars.G964.Closet. Shold be Codewars.G964.Josephus. Thoughtful person can also easely find one possible solution :)

  • hencethus Avatar

    I've kumited an Elixir translation.

  • MErmanProject Avatar

    This comment has been hidden.

  • WillLearn Avatar

    This comment has been hidden.

  • Kimodo90 Avatar

    can anyone provide an explanation for the currenlty available solutions(by g964, & unnamed)

  • g964 Avatar

    Maybe you don't agree with the C# translation?

  • g964 Avatar

    C# translation kumited, maybe Clojure to morrow if you agree.

  • g964 Avatar

    Haskell translation kumited.

  • g964 Avatar

    Coffeescript translation kumited...

  • simpsOff Avatar

    This comment has been hidden.

  • AngusJGoldsmith Avatar

    Enjoyable kata! I've written a Java translation if you want to take a look.

  • Abbe Avatar

    This comment has been hidden.

  • dnolan Avatar

    Nice Kata! This one was fun.

  • jolaf Avatar

    In pre-set code, the function is named josephus, while josephus_survivor is expected.