Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
parseInt isn't required here, (Integer. str) (with a space after the ., for some reason the space is getting removed in my comment) gets the job done. parseInt would avoid errors if there are any letters in the middle of the string, but knowing that the inputs will always be numerical makes this unneccessary. Not a criticism, just a comment
Depending on how you want to tackle it, one word to help you out: memoize
Basically, you take an array [1] and add the results of 2x+1 and 3x+1 to it. Then you have an array with 3 values [1,3,4]. Then you go through and add the results of 2x+1 and 3x+1 for each of the new numbers. Since you add two numbers each for each number, the amount of calculations you do on each pass increases exponentially. Then you return the nth element of the array. The issue here is that getting to large numbers, just having an array that goes past "n" indices will not guarantee a correct answer, since so many new values are added and some of the lower ones will have 2x+1 and 3x+1 results that are NOT YET part of the array. So you need to overshoot the size of the array in terms of "n" by quite a bit.
Wow! What great code!
This comment is hidden because it contains spoiler information about the solution
✘ Got 34 from gift #1, expected 34.
✘ Got 22 from gift #2, expected 22.
✘ Got 94 from gift #3, expected 94.
✘ Got 59 from gift #4, expected 59.
✘ Got 87 from gift #5, expected 87.
✘ Got 28 from gift #6, expected 28.
✘ Got 62 from gift #7, expected 62.
✘ Got 71 from gift #8, expected 71.
✘ Got 5 from gift #9, expected 5.
✘ Got 47 from gift #10, expected 47.
What's this about? Why is this failing?
I see people using gsub all the time here with a bunch of what appears to be gibberish in the middle. The SoloLearn app I used to learn the fundamentals did not go into this at all and I haven't found anything that really explains this method. Any resources out there that could turn the \w//?+/\2w== kind of thing into English for me?
I'm not sure I understand, you are deleting at the index of the element with smallest value OR zero? Does zero just get selected when numbers.index(numbers.min) throws up an error due to a nil array? Very clever, just not sure how the zero would be selected
Not sure if you checked through other solutions, but Ruby has a great way to handle variables inside of strings, you can put everything in quotes and insert your variable with #{variable name} anywhere inside of the quotes