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.
answered above
Thats awesome, knew about first but second was just gamechanger. Thank you
Depends. With simple exercises like this one, compact solutions are used in production. However, with more complex algorithms, code golfing is more of a past time. Self documenting and legible code is more desireable for professinal production code, as it's easier to read and maintain.
@Tobleron44 What language are you on? That sounds like an error in the description, since the correct output should be 1, 3, 5, 7, 9, 2, 6, 10, 8, 4.
Also, when you start your second run through, you forgot to switch from yes to no. You end on 10 (no), so when you go back to 2, it should be a yes.
But that would mean:
y n y n y n y n y n
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
1, 3, 5, 7, 9
then we have
N Y N Y N
2, 4, 6, 8, 10
1, 3, 5, 7, 9, 4, 8
...
And in the description it says
1, 3, 5, 7, 9, 2, 4, 6, 8, 4
what am i missing?
cool.
As I understand it, you need to write a function which takes an array, and returns another array. To populate the output array, go through the input, and select every other item. Once you reach the end, loop through the input array again with the same pattern, ignoring the items which were "selected" previously. However, when you restart the array, the decision to either include or exclude an item doesn't reset. So if you selected the last item, ignore the first item when you restart the array.
For example, take the array [1, 2, 3, 4, 5]
First, go through every other element, like so:
After "removing" these elements, we are left with
[2, 4]
, so we repeate the same pattern. However, because our last runthrough ended with a "Yes", this new runthrough starts with a "No":Now, since only
[2]
is left in our input form, we add it to the end of the output, returning[1, 3, 5, 4, 2]
.Hopefully that makes a bit more sense.
this makes a lot of sense... will definately take note of this.
You're not doing anything about the descending order.
False
and0
are different.Also, note that if you don't tell what's the input, what's the expected output and what's the result your code returned, nobody can help you.
Not 100% sure since I'm just getting into swift myself but I'm pretty sure what is happening is that even though your float is showing as 126.0, it's actually something like 125.9999 and when you truncate to an Int it just chops off the .999
I had a similar issue. I tried to cheat fix by just adding 1 to specific examples that were off by 1. That worked for all but one of the examples.
Out put was telling me that 159 was the right answer when I got 158. When I added 1 to my answer it swapped and told me that 158 was the right answer now that I was returning 159.
So bizarre. I didn't realize my output could affect the correct results.
Because in an application use, an extention can be used globally without any issues or headaches. Simply call the exention function on any Int and you're done.
Try defining result at the start of the function.
Also, you need to say that the function return a string so you should have
func switchItUp(_ number: Int) -> String
when defining the function.This comment is hidden because it contains spoiler information about the solution
Loading more items...