4 kyu

Twice linear

579 of 23,728g964
Description
Loading description...
Mathematics
Algorithms
  • Please sign in or sign up to leave a comment.
  • KayleighWasTaken Avatar

    Function name in OCaml should be snake_case

  • amallya88 Avatar

    helps to use excel to expand out the recursive formula to understand it. the description is not the best

  • epere82917 Avatar

    This comment has been hidden.

  • hebopaul Avatar

    Serious question. Why do you skip x = 2? If you're supposed to fill the list with u(x) for x = 0 to infinity, then it should be [1, 3, 4, 5, 7, 10, 9, 13, 11, 16, 19...]. The test n = 10 list has no "5" element which means u(2) was skipped. Am I wrong? What's happening here?

  • bendeg Avatar

    Test in C with n = 7375 is ok on my side and takes approx. 2 seconds.

    Since my laptop isn't a fancy one (Intel® Core™ i5-8250U CPU @ 1.60GHz × 8), are there more CPU consuming tests after that one ?

  • Jonathan-Schaefer-git Avatar

    This comment has been hidden.

  • santimatiasmartinez9 Avatar

    I understood the statement that this is what you are looking for, but I have doubts as to how many numbers the list should have where the numbers are going to be added. In the example provided, dbl_linear(10) the parameter is 10 and u = [1 , 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...] and I see that 10 + 1 positions were produced in the list, is the statement correct? excuse my english

  • picpic Avatar

    I didnt get it, even AI couldnt get it

  • elchikita Avatar

    I can't find the reason to why this kata is took so much efforts from me to solve. I cannot explain how satisfied I am after solving this afterwards.

  • dev-ishwar Avatar

    This comment has been hidden.

  • Dmytro-Tarasenko Avatar

    This comment has been hidden.

  • crescentfuze Avatar

    This comment has been hidden.

  • december-man Avatar

    Excellent kata! Had a lot of fun optimizing the solution!

  • trashy_incel Avatar
  • CyroClast Avatar

    do i have to sort the u table?

  • itsgatsu Avatar

    This comment has been hidden.

  • Nap20192 Avatar

    This comment has been hidden.

  • Iluxmas Avatar

    Wow, it was like insight when I find my solution

  • a2011mccord Avatar

    I mean I half solved it, but it times out whenever I submit it to the hella large numbers. Not sure where else to go from here in terms of efficiency.. tried shaving down the length of the sequence that I'm generating but that wasn't enough. Iono :/

  • Koonlouis Avatar

    after 3-4 hours of time out using python, I finally did it. I never feel so refresh like this.In the end I can beat this kata!!!

  • devheptagon Avatar

    100th element should be 471 though test expects 447. I dont understand. If algorithm was wrong earlier values would be wrong too. Here is my output for u(100). Can someone tell me whats the problem? Thanks 1,3,4,7,9,10,13,15,19,21,22,27,28,31,39,40,43,45,46,55,57,58,63,64,67,79,81,82,85,87,91,93,94,111,115,117,118,121,127,129,130,135,136,139,159,163,165,166,171,172,175,183,187,189,190,193,202,223,231,235,237,238,243,244,247,255,256,259,261,262,271,273,274,279,280,283,319,327,331,333,334,343,345,346,351,352,355,364,367,375,379,381,382,387,388,391,405,406,409,418,471,475,477,478,487,489,490,495,496,499,511,513,514,517,519,523,525,526,543,547,549,550,559,561,562,567,568,571,580,607,706,711,712,715,729,730,733,742,759,763,765,766,769,775,777,778,783,784,787,811,813,814,819,820,823,837,838,841,850,1066,1093,1135,1137,1138,1143,1144,1147,1161,1162,1165,1174,1215,1216,1219,1228,1255,1701,1702,1705,1714,1741,1822,2551

  • tedddd Avatar

    This comment has been hidden.

  • dragonwillow Avatar

    Interesting kata. The way the numbers are generated is very important and should be clarified. It seems like the expectation is that the x's, y's, and z's are expected to be generated n times. If you generate them more than that, you'll have too many numbers in your set and your answer will be wrong (even if the nth index). If fewer, you'll have the same problem.

    This is also quite challenging to debug due to the lack of feedback. It's easier to debug the small numbers, but larger numbers (e.g. in the thousands) are hard to tell what's going wrong if you get the wrong answer. I think a lot of errors are going to likely be based on the aforementioned assumptions. If you're working on this, the kata expects you to generate x, y, and z exactly n times.

  • Maxime8 Avatar

    This comment has been hidden.

  • Bbllaaddee Avatar

    The tests in c++ version are written horribly. How should I debug my solution, if no output to cout or cerr is getting actually written in test reports? I mean, I can debug it in my terminal and vim, but that kinda defeats the whole purpose of the web-site. Pls, fix

  • Revazza Avatar

    when u(x) = 9

    y = 2x9+1 = 19

    z = 3x9+1 = 28

    but in test cases z = 27

    same goes when u(x) = 19

    'z' should be 58 instead test cases fails saying it should be equal to 57

  • Lukewhatever Avatar

    This comment has been hidden.

  • Lukewhatever Avatar

    Is there any way to log the time it took the function to finish? It's not very helpful if the only information we get is that the whole thing timed out.

  • pilgrim23 Avatar

    This comment has been hidden.

  • Supermedyk Avatar

    This comment has been hidden.

  • AbdulSalphan Avatar

    Does anyone know whats the maximum number value for n in the random testcases? My code works on time for atleast upto n = 20000.

  • mgc.bdd Avatar

    this was very easy, it should be 6 kyu

  • Roman Samoilov Avatar

    This comment has been hidden.

  • z_maximus Avatar

    This comment has been hidden.

  • i-am-unknown-81514525 Avatar

    I was getting Execute Timeout multiple time , I think i need some help I get 8 basic test correct with a timeout.

  • SergeyFM Avatar

    I first used an obscure data structure and then learned a very helpful scope function trick (in Kotlin). Thank you for such an educational kata!

  • JohanWiltink Avatar

    This comment has been hidden.

  • fresh-Blood Avatar

    This comment has been hidden.

  • dfhwze Avatar
  • SultanDuwaik Avatar

    can i request a longer version of u and what gives what ? or will this spoil the question ?

  • inupasheheran Avatar

    great kata..!!!!! great job....!!!!!!!

  • moudy-wold Avatar

    Can you explain the idea of kata more clearly?

  • voidptr69 Avatar

    Hello, With Python what is this error Time: 5721ms Exit Code: 139 :)

  • FArekkusu Avatar

    Solution should be imported explicitly in Python.

  • DomerDev Avatar

    This comment has been hidden.

  • MaxKolomiets Avatar

    This comment has been hidden.

  • tweller Avatar

    "Focus on efficiency" - CPU or memory?

  • monadius Avatar

    Updated Dart translation (Dart 2.14).

  • Walter Liu Avatar

    This comment has been hidden.

  • bobross1337 Avatar

    This comment has been hidden.

  • Derked Avatar

    I have a solution I believe will work, but it fails the test cases because the global variables do not reset on each function call (javascript). Is it possible to reset the global variables on each function call? I understood each function call to be independent and therefore I could use the original state of global variables in writing my solution.

  • mitaosi Avatar

    This comment has been hidden.

  • jtmyers1983 Avatar

    (Lua) when returning u(n) it always seems to be 1 index off. This is even true in the example for the problem in the instructions where it says dblLinear(10) should return 22...but if you count the values in the list 21 is at index 10...not 22. I think that the testing / solutions might not take into account that Lua tables start with index 1, not 0. Please advise?

  • Batyr Avatar

    This comment has been hidden.

  • __sos Avatar

    This comment has been hidden.

  • Kanzh Avatar

    I'm pretty sure I found a bug... check my solution Either that or I got lucky, not sure tbh

  • webtechalex Avatar

    This comment has been hidden.

  • DziadekRobert Avatar

    This comment has been hidden.

  • MatFynus Avatar

    This comment has been hidden.

  • artie-owlet Avatar

    On typescript - passed test with n=1000, but on "attempt" basic tests failed with "Timeout of 2000ms exceeded". Test - 12ms, attempt - more than 6s

  • cschipg Avatar

    This comment has been hidden.

  • Pedraamy Avatar

    This comment has been hidden.

  • Goop Shloop Avatar

    This comment has been hidden.

  • elfy941 Avatar

    This comment has been hidden.

  • JackLeo Avatar

    Why comments mention 60.000 test being the highest? Dart tests for 300,000, is this some sort of bug or increase in challenge? 60k ones completes in 895ms subsequent smaller checks complete within 1-3ms... Still times out on 200k-300k.

  • Palkin_Fedor Avatar

    1

  • sflow Avatar

    Hi,

    For how long after getting n values in the set, do I have to keep calculating the numbers of the sequence?

    Since smaller sequence number might come later, how do I decide when to stop calculating? Really need help generalizing this since as the n becomes large(n is going upto 600,000 in test cases), you need to keep calculating sequence way after n numbers of the sequence are calculated. Any hint or suggestion? (I might have misunderstood the problem as well, so please help!)

  • Very_Baguette Avatar

    My code works in the test, but when i try to attepmpt it i have an error: "Timed out"

  • Opabinia Avatar

    When you have a lot of work to get done, but somehow get nerd-sniped by a fascinating-seeming kata...

    Will try this ASAP. Hopefully, a powerful functional programming language like Haskell with lazy data structures should demolish this!

  • americo677 Avatar

    This comment has been hidden.

  • ChibiDev Avatar

    Wew, difficult (especially keeping performance in mind!), thanks for the challenge :-)

  • gutalien Avatar

    This comment has been hidden.

  • oyemayanq Avatar

    Thank you for the kata!!

  • dojodominion Avatar

    This comment has been hidden.

  • epicshaner Avatar

    This comment has been hidden.

  • SethVan Avatar

    This comment has been hidden.

  • user7981637 Avatar

    This comment has been hidden.

  • IdotEXE Avatar

    This comment has been hidden.

  • aboutdevz Avatar

    what is the meaning of this sentence

    "returns the element u(n) of the ordered (with <) sequence u (so, there are no duplicates)."

    i still dont get it please help me

  • Bubbler Avatar

    Factor translation submitted.

  • coding_hedgehog Avatar

    The description doesn't say how many numbers the list should consist of. As it is it could be infinite.

  • glynester Avatar

    This comment has been hidden.

  • soumya_khatua Avatar

    Brilliant kata. Without brute force, or high-level algorithm u can do it.Oh! if u think time is the main issue look twice where ur code actually taking long apply finest algorithm u know. For python user don't use sorting too much. All u need to do think straight. Try diff approaches if one fails down go for next one and soo on and soo forth. I really enjoyed this kata. Solved it in python.

  • Lyntier Avatar

    This comment has been hidden.

  • Bmlak Avatar

    This comment has been hidden.

  • drexler Avatar

    g964 what a brilliant problem!! I had 5 different solutions all of which kept timing out forcing a rethink of the algorithm and learning more Rust. Even then after solving it, looking at others' solutions...the simplicity of some solutions still astounds. Best kata i've attempted so far. Thanks.

  • Alex_Tsar Avatar

    Very interesting kata. Thanks

  • asia4Scala Avatar

    I have been trying to solve this for ages in Scala with a O(n) solution, but keep getting execution timeout errors. Any suggestions?

  • askmuhsin Avatar

    This is a very interesting problem! Thank you for creating it. I wanted to know if the solution involves trees?

  • woklis Avatar

    If I write the code in C, it immediately gives an error. An error occurs with an empty function and if all tests pass.

    Test Passed The expression (act) == (exp) is false. fixture.c:7:15: warning: implicit declaration of function 'dblLinear' is invalid in C99 [-Wimplicit-function-declaration] int act = dblLinear(n);


            OR 
    

    Test Results: dblLinear ShouldPassAllTheTestsProvided (4 of 4 Assertions) Completed in 1.5728ms STDERR fixture.c:7:15: warning: implicit declaration of function 'dblLinear' is invalid in C99 [-Wimplicit-function-declaration] int act = dblLinear(n); ^ 1 warning generated.

    /// There is no such error in C ++

  • RealJesus Avatar

    This comment has been hidden.

  • LukasG Avatar

    This comment has been hidden.

  • JezzaS Avatar

    My code works for the 4 test cases, but not for the 4 extra tests when you try to submit your answer. Any suggestions?

  • reagentjs Avatar

    This comment has been hidden.

  • rge123 Avatar

    Good fun :) Pleased that my first idea worked - that doesn't happen often!

  • gians Avatar

    This comment has been hidden.

  • NicolasOrtho Avatar

    And you cannot use sortedcontainers on codewars....

  • jafigueroa-dev Avatar

    I pregenerated the list (up to 60001) and pasted it in codewars. Now my solutions tab won't work, but I solved the problem I guess.

  • user9893733 Avatar

    This comment has been hidden.

  • cfarshad Avatar

    This comment has been hidden.

  • mateuszmacheta Avatar

    Hello

    I don't understand how we create sequence. I though we calculate values of y and z function up to certain point and sort them while removing duplicates. I prepared Excel sheet and figured out sorted sequence without duplicates (up to index 17) is 1, 3, 4, (5), 7, 9, 10, (11), 13, 15, (16), (17), 19, 21, 22, (23), (25), 27 In parentheses there are numbers which are not in example from Kata description. This is how I got those numbers: y(2) = 2 * 2 + 1 = 5 y(5) = 5 * 2 + 1 = 11 z(5) = 5 * 3 + 1 = 16 y(8) = 8 * 2 + 1 = 17 y(11) = 11 * 2 + 1 = 23 z(8) = 8 * 3 + 1 = 25

    Please let me know what I'm doing wrong.

  • LucaREz Avatar

    Random tests in prolog always fail: plunit_dbl_linear:dbl_lin_db/6: "Undefined procedure": dbl_lin/6 (forall bindings = [40])

    in line 49 of your test file there is a call to dbl_lin instead of dbl_lin_db (probably that line wasn't updated when the function was pasted in the test file)

  • raghurambachu Avatar

    I am able to execute the code on codepen but when running on codewars it's showing stderr timeout

  • maazza Avatar

    This comment has been hidden.

  • kalennoreth Avatar

    I found this one to be an excellent learning experience, but almost inaccessible at first. Other comments suggest a certain class that might be useful, but all are spoiler tagged. Is there some way to point people to the right path without utterly spoiling the problem? I only was able to figure it out by writing a not-so-great solution that barely avoided timing out and then seeing other solutions. Overall, though, this is my favorite kata I've yet encountered.

  • olizh Avatar

    Fabulous kata!

  • damage99 Avatar

    "*** Error in `./test': free(): invalid next size (fast): " Someone know what is?

  • AEParry Avatar

    This comment has been hidden.

  • terobero Avatar

    It took me around 2 hours to realize there can be more than one of same elements...

  • SaberMyKing Avatar

    I think there are some mistakes in this kata. Some test cases are incorrect, eg: dbl_linear(500), dbl_linear(1000) and so on. Because of the incorrect test cases, real answers disappeared in sulution page. Wrong anwsers are misleading. Of course, maybe I am wrong.

  • gj84 Avatar

    This comment has been hidden.

  • apparatchik Avatar

    This comment has been hidden.

  • jithrae Avatar

    This comment has been hidden.

  • m4ch4do Avatar

    This comment has been hidden.

  • DeCooper Avatar

    What an awesome kata! I had an ok Python solution that computed dbl_linear(60000) in about 500ms. However, the tests kept timing out, which forced me to come up with something better. When the aha moment finally came, it was over 10x faster than my original. I am glad the tests forced me to do better!

  • Ben@ Avatar

    Hello,

    My algorithm is taking 2300ms with my environment Windows/firefox for u(60000) but when I try to to submit it sends me timeout error. is ther anyway to test my function in the same conditions as here.

    regards, bmc

  • KeineAhnung- Avatar

    This can be solved in O(n)! Brilliant!

  • evilhaxor Avatar

    I believe this is the only challenge i've voted "Very Satisfied". I thought I had a great solution, fast and clean, and still think its good. Though I was pleased to see better solutions than mine, and also worse solutions. How can I know when/if i'm good enought to get a programming job?

  • sprengerjo Avatar

    Hi there,

    i have elixir optimisation issues. I need a hint on the data structure to store u in. I end up using a Map as a cache.

    I get a timeout after 30 random tests...

  • noeB Avatar

    Hi there,

    Currently trying to solve this kata, I'm having optimisation issues : On my first attempt 9 tests passed and then it timed out Second attempt : 60 tests passed, then timeout again.

    Just curious, how much tests is there to solve the kata ?

  • eric7237cire Avatar

    This comment has been hidden.

  • Kronodeus Avatar

    As others have stated, please indicate the sequence must also be a set. Description is incomplete without this detail.

  • Kronodeus Avatar

    By definition, a sequence can have repeated elements. Thus, the description of this Kata is insufficient. The best solution for a traditional sequence is to use a PriorityQueue. However, since the sequence must also be a set, a SortedSet implementation is required.

  • hilechen Avatar

    This is a very nice kata and I learned a lot. My original solution worked within time limit, but it was too lengthy and not straightforward. I read the clever solutions from others and started a new solution. It was neat and faster!

  • dennism Avatar

    This comment has been hidden.

  • james-k-polk Avatar

    Unfortunately, like many of the Kata, this one is under-specified and leaves a critical aspect un-answered. The issue in this case is duplicates. In other words, the same value may be generated from two different values in u. I think the fact that '<' is specified instead of '<=', and the fact that there is no unique answer for a duplicate, suggests that the correct thing to do is to ignore duplicates. In other words, treat u as a set, and order the elements of the set according to '<'.

  • thapelo.masemola Avatar

    This comment has been hidden.

  • Gadelius Avatar

    I have runtime error, but my code works pretty well. What should I do? Could you help me?

  • lynxlynxlynx Avatar

    There are 5 solutions for shell. Can someone please tell me if any of them are shell-only, i.e. don't just dump the whole problem to bc, awk or some other more appropriate language?

    Interestingly enough, preventing dupe addition is slower overall in bash than just filtering it out later, even though about every fourth element is a dupe (eg. for 6000).

  • soumens1 Avatar

    One Important Note: ignore duplicate value

  • Aestmanindel Avatar

    This comment has been hidden.

  • Aestmanindel Avatar

    This comment has been hidden.

  • VadKozJr Avatar

    I was hrdcode this one. I had no ideas what to do with repititions and my range increased too fast, so, i used range n * 5. Didnt think about deque or two lists etc. It was hard for me. IMO, its not 4 kyu.

  • crashfr Avatar

    I read somewhere that n goes to 60k max and my algorithm can compute "dbl_linear(140000) " in sample test under 12000 ms. Then why do i got an Execution Timed Out (12000 ms) at Attempt?

  • Mike Anderson Avatar

    This comment has been hidden.

  • Ezekiel93 Avatar

    Add the disclaimer that there are no duplicates in u. Lost a lot of time debugging this shit.

  • hobovsky Avatar

    Description definitely needs a disclaimer on how duplicates should be handled. Additionally, a link to N-Linear could also be added.

  • palohar Avatar

    Guys is this more of a math problem or a programming problem? I have like 5 different working solutions, in sample tests I can compute dbl_linear(25000) in 7426ms. But I always get time out on submit. What are the constrains of n? Just so I know, whether my approach is just a bit off or completely wrong. This takes away my otherwise peaceful sleep :/ Thanks.

  • Phil157 Avatar

    For Fortran solution - Can you tell me how many random tests I need to complete? I've optimised my code extensively since proof of concept passed about 50 total test cases with zero failed. I've now solved it for a max. of 108 tests, but with major part being random this may drop to 90. I've used an insert sort (& de-duplication) on the fly so that my data array is sorted from the start. Now I'm finding so-called optimisation, e.g. removing "Size(array)" from loop in favour of a variable, editing my function code to be in-line etc. actually have a negative impact. As I'm usually only the 2nd Fortran user, is the number of tests reasonable?

  • Henning-K Avatar

    For Rust are you compiling+running the solution in Release mode and are the compile times also counted against timeouts?

  • monobrawl Avatar

    This comment has been hidden.

  • holysloth Avatar

    This comment has been hidden.

  • monadius Avatar

    NASM translation (with the test code taken from the C version). Please review and approve.

  • aleplond Avatar

    This comment has been hidden.

  • jansona Avatar

    I wrote a queue class to solve this, and pass the sample test... but time out when trying "attempt".

  • DARK_RED_APPLE Avatar

    This comment has been hidden.

  • coryshrmn Avatar

    Great kata! It inspired me to create a more general version: N Linear. Instead of x * 2 + 1 and x * 3 + 1, the multipliers are a parameter.

  • tarasratushny Avatar

    This comment has been hidden.

  • valerauko Avatar

    This comment has been hidden.

  • sasayins Avatar

    This comment has been hidden.

  • kvosbur Avatar

    One note that I would make is to add in the description the fact that there are no duplicate values in u. Took me a little while to get the correct answer as I did not know about this assumption and took me reading some of the discourse to figure that out.

  • josevasquezr Avatar

    Por favor, mejoren sus especificaciones, me tardo mas en entender que es lo que quieren. En este a saber que es lo que piden.

  • CC712 Avatar

    test pass but timeout .... with a 2 while structra while { while { } }

    Is this really a code but a math question ?

  • hPark Avatar

    great kata! it took me several hours though.. using queue was very helpful

  • overthink Avatar

    This comment has been hidden.

  • cbondurant Avatar

    This comment has been hidden.

  • itchy_eagler>< Avatar

    iam able to pass test cases but while attempting it shows "Server Execution Error: The server attempted to execute your code but there was an issue with the request. This should be a rare issue. Please try running your code again. If the issue persists, please contact us."

    help plz

  • dinglemouse Avatar

    Very satisfying to solve this one (Java). And learned a new API as well. Thanks!

    :-)

  • dayfine Avatar

    I couldn't believe I actually passed the test with my still very slow solution. Then I couldn't believe there was actually a much simpler way to solve this...omg! Thanks op for the kata!

  • amad Avatar

    Is it a wrong expectation there for PHP?

    testBasics n=50 > Failed asserting that 189 matches expected 175.

  • haugk Avatar

    Haskell

    Nice one. I have to say though, I did not have to optimise for speed.

    The function name is not the one specified in the description. Not a biggy, but hard to see why that should be.

  • jalpher Avatar

    This comment has been hidden.

  • hhummel Avatar

    Great kata! My first solution was much worse than my second solution, which took about a day's worth of ruminating. One suggestion in the specification of the problem is to note that duplicate values are excluded. I see @Ellsmell noted this in the Suggestions, but it's still not in the (Javascript) spec.

  • AMGardner1985 Avatar

    Maybe its just me, but I didn't understand the task, could you imporve the description?

  • m123mikmik Avatar

    This comment has been hidden.

  • banz Avatar

    There is the true philosophy of life in this kata.

  • user9057704 Avatar

    This comment has been hidden.

  • bkaes Avatar

    Why does the C++ version use a unecessary class?

  • SophinQ Avatar

    can't submit because of time out :( want to know the reason and solution

  • SophinQ Avatar

    Time out :( try 2 ways

  • almon000 Avatar

    In basic tests I passed the first 5 examples but failed the last 5. However, I passed all the random tests, there are also many values of param 'n' in the area of the last 5. I don't know why...

  • sigod Avatar

    What is the upper limit for n?

  • Abuda Avatar

    Very interesting and amusing kata! Unlike many katas, the description is smart and concise. Had to optimize the code a few times though (for speed). Fun fact: Last submission saves 99.996% of time taken by the first successful algorithm!!

  • dschnelldavis Avatar

    Your TypeScript version appers to be broken.

    I get the error:

    ../home/codewarrior/spec.ts(1,1): error TS1084: Invalid 'reference' directive syntax.
    ../home/codewarrior/spec.ts(2,1): error TS1084: Invalid 'reference' directive syntax.
    

    In the example tests I fixed this by changing:

    /// <reference path="/runner/typings/main/ambient/mocha/index.d.ts" ></reference>
    /// <reference path="/runner/typings/main/ambient/chai/index.d.ts" ></reference>
    

    to

    /// <reference path="/runner/typings/main/ambient/mocha/index.d.ts" />
    /// <reference path="/runner/typings/main/ambient/chai/index.d.ts" />
    

    but I get the same error on the full tests, which I can't change.

    Could you please fix the full tests?

  • anter69 Avatar

    This comment has been hidden.

  • user5036852 Avatar

    Good kata!

    But maybe you could improve the description. ;-)

  • ptreitler Avatar

    A nice and challenging kata. Had to optimize it twice to get it running fast enough. Also interesting to see some very clever solutions. :)

    I do agree that this should be rated a bit higher - I found all the other 5 kyu kata much easier than this one.

  • OleksSobol Avatar

    I so confused. I passed examples, but can not pass test. I tried different algo but still no success. I deleted duplicates. Have no idea where is my mistake.

  • Dworin Avatar

    This comment has been hidden.

  • croceflamenco Avatar

    Another enjoyable & challenging kata. Thank you, g964. I do feel rather guilty about getting this one to pass without really understanding the logic behind optimizing it. Bookmarked for a revisit once my math skills improve =]

  • umitkablan Avatar

    This Kata is not correct - or I thought the solution vector should be sorted. Since 2n+1 is increasing slower than 3x+1 after finding the nth number in the solution vector we should iterate forward and check whether there is smaller 2x+1 than result (nth number) we found:

    ... int res = nums[n - 1]; for ( ; i < n; ++i ) { if ( 2 * nums[i] + 1 < res ) { res = 2 * nums[i] + 1; break; } } return res;

  • ShahriyarR Avatar

    This comment has been hidden.

  • DeriusXTR Avatar

    Very interesting challenge, have been trying to solve it for roughly 2 days. This challenge forced me to learn the concept of python generators which I ended up using in my solution. Though my First final submission is 5.5 seconds I am very happy with the progress.

  • Ellsmell Avatar

    Description should be clearer that the sequence can't have duplicates. I was stuck with an issue for a while because I didn't realise this.

  • Equim Avatar

    This comment has been hidden.

  • miljinx Avatar

    I ran the examples successfully, but when I submit I get this error (using Ruby):

    TypeError: buffer.stdout.push is not a function at Socket. (/runner/lib/shovel.js:164:27) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at Pipe.onread (net.js:543:20)

  • JohanWiltink Avatar

    Haskell:

    Getting warning for tab characters, and I think that's why I can't submit.

    They're in the example tests, where I found them myself and took them out (they're at the front of the actual test lines), but for the submit test, I obviously can't do that.

    Should I be suppressing warnings somehow? (I'm really really new at Haskell in CodeWars).

  • chapeupreto Avatar

    Could someone please tell me if there is any problem with PHP tests? When I click 'Run Examples', testBasics() turns green. However, when I click 'Run Suite' the same testBasics() turns red. It sounds to me that there's some problem when input is 100. Thanks!

  • prabingc Avatar

    This comment has been hidden.

  • vlkvlk Avatar

    Funny kata. I had to prepare 4 solutions, one faster than the other. All tests passed, but still too slow. Out of curiosity I compared the final one to the one in test evaluation (much more elegant, but slower): mine was 5 times faster (my dblLinear(100000) was 4.4s, "original" 22.7s) !

    So most of the time wasted during test was not because of my solution(s), but because of the test evaluation itself. That's sad... On the other hand I've learned a lesson about speed of PHP array operations, so I'm somewhat satisfied...

  • voliev Avatar

    What actually means this condition "with<" in the kata description?

  • DGoodrich Avatar

    This comment has been hidden.

  • vudulin Avatar

    This comment has been hidden.

  • greeven Avatar

    for js guys: console.log takes time :) (not sure if that qualifies as a spoiler)

  • hdl26 Avatar

    This comment has been hidden.

  • maximus1108 Avatar

    I'm pretty stumped on how to optimise my code to pass this. I've tried a few solutions, all off which include sorting, and going by others comments here, I guess that's why my code is too slow to pass.

    I'm puzzled at how this can be achieved without sorting?

    Any help would be much appreciated!

  • rjr20 Avatar

    Nice chewy kata! It took me a while to get it fast enough but doing so was a really valuable exercise. Also very interesting to look at other people's solutions.

  • steinbachr Avatar

    like a lot of other people have said, definitely seems like a harder than 5 kyu exercise. Feels like at least a 4.