6 kyu

A disguised sequence (I)

134 of 4,886g964
Description
Loading description...
Algorithms
Mathematics
  • Please sign in or sign up to leave a comment.
  • trashy_incel Avatar
  • ejini战神 Avatar

    C#: method name should be PascalCase (Please refer to implementation of backward compatibility here )

  • ejini战神 Avatar
    • JS chai && assert should be used

    • Ruby 3.0 should be enabled

  • gezamiklo Avatar

    Using Swift test are passed but on Attempt I get Code: 132 error with no logs at all. Quite simple code

  • YaokunYe Avatar

    I always run out of time, but I can't find another algorithm. Too bad!

  • sid114 Avatar

    clever!

  • B1ts Avatar
  • FArekkusu Avatar

    Solution should be imported explicitly in Python.

  • akar-0 Avatar
  • Valeriy_Zhma Avatar

    This comment has been hidden.

  • achambily Avatar

    It's a good exercise to proove that the guessed sequence is the good one ;)

  • Jerryg2212 Avatar

    please do a better job of explaining the sequence or send a link to someone that does.

  • user240425 Avatar

    Please mark the question with the mathematics tag when it's clearly a math problem. I hate math and filter them out. It's annoying that every other kata is still math, despite not tagged as such.

  • DaringSteel Avatar

    A solid math/coding exercise. Very satisfying.

  • powerfulshell Avatar

    This comment has been hidden.

  • Artem Vorobviov Avatar

    Well 't was good for me not by math, but BigInteger)

  • krishp Avatar

    Every goddamn time you get me. Whyyyyyyyyyyyyyyyyyyyyy

  • Ranald Avatar

    Nice kata. Gave me a chance to resurrect some maths :).

  • Sepero Avatar

    This comment has been hidden.

  • glasserc Avatar

    I would love for some hints about the mathematical part. I was also able to guess the closed form for the sequence and can prove it using mathematical induction, but I have no idea how I would have done that if I hadn't seen the pattern. This is a nonlinear recurrence relation, right? Is there a trick to analyze it?

  • Unnamed Avatar

    The initial solution in Lua has kata instead of solution and doesn't have return.

  • Bubbler Avatar

    NASM translation submitted.

  • 0kaguya Avatar

    This comment has been hidden.

  • icarus612 Avatar

    This comment has been hidden.

  • ThatRealMoose Avatar

    Honestly, Haven't the slightest clue as to what the sequence is.....

  • dulong26 Avatar

    I pass "Run Sample Tests", but when I press "Attempt". This message "Process exited prematurely with a SIGILL signal." keep appearring. What is wrong?

  • skylarjhdownes Avatar

    I submitted a version (Coffeescript) that I knew to be incorrect, but still passed all tests. There should be a test ensuring that fcn(1) returns 2, for those of us that hack out the long winded version. :D

  • donaldsebleung Avatar

    Objective-C Translation Kumited - please accept :D

  • mn113 Avatar

    This comment has been hidden.

  • Kim Pyung Soo Avatar

    This comment has been hidden.

  • Unnamed Avatar

    Nim has several primitive types: signed integers: int8, int16, int32, int64, and int, where int is the same size as a pointer

    I think it's not too good to assume int is 64 bit. (Although it's unlikely tha someone would want to test their solution in Nim locally on their 32-bit system :)

  • Veladus Avatar

    This comment has been hidden.

  • xiaocheng Avatar

    当时写的时候想到的是用递归,最后运行起来超时,怎么优化都是超时,然后就看了下别人写的竟然是2的n次方这样写,虽然的确是这个规律,但是如果n0和n1,不是1和2,那就规律不对,去用数学的方法来做这个点题目,感觉不通用,因为可能这个没有这规律,却花时间去想数学规律,有点不靠谱。

  • javia1492 Avatar

    This shouldnt be worth 6 kyu. An algorithmic approach is extreme overkill. Work smarter, not harder. Once you do some basic math you quickly spot the pattern and realize... there is a library for this! and literally write 1 line of code.

  • genescu Avatar

    This comment has been hidden.

  • lucvbeek Avatar

    This comment has been hidden.

  • cowile Avatar

    The Ocaml starting code is wrong and misleading.

    First is that int in Ocaml is not automatically promoted to a bignum. Bignums are in the Num module.

    Second is that the user written function is required to output a string. Why is this conversion not done in the testing code?

  • newtodisworld Avatar

    This comment has been hidden.

  • karmajunkie Avatar

    agree with haferjir. This kata is trivial in any language, if you have the math intuition to see the series. It has nothing at all to do with Elixir.

  • marksiemers Avatar

    This comment has been hidden.

  • mcamuzat Avatar

    I add the php version. My first translation..

    thanks.

  • Kaiyou Avatar

    the first one purely algorithmic from the definition of un the second one - not at all mandatory, but as a complement - is to get a bit your head around and find which sequence is hidden behind un.

    Finding the hidden sequence is a lot less work than the algorithmic solution, though.

  • kmj442 Avatar

    After manually solving for u2 and u3 I noticed the sequence and checked it against u17. That was fun, plus I felt like doing a little math with paper and pencil for the first time in a little while.

  • raulbc777 Avatar

    g964, a very god kata. I support your point of view. I think that with maths we may have solutions of better level, much more faster. This is the right place to publish them. But you were very polite and gentle. We gave us the chance to solve them by algorithms. I solved using dynamic programming. The solution of CrazyMerlin brilliant as always.

  • haferjir Avatar

    I'm not to sure about the purpose of this kind of kata. While sometimes katas have a straight forward implementation and a more elegant and faster mathematical solution it seems that this one only makes sense in terms of getting your head around the math. I'm not sure whether it's an appropriate codewars kata as it seems more like a mathwars kata.

    I think a solution would be to at least give some hints and reasons for this kata in the description.