36
2
Some of you may be familiar with the way that a motorcycle shifts. But for those who don't, It looks like this
6
5
4
3
2
N
1
Now I want to know what gear I am in after performing a few up and down shifts. The program should work from neutral.
Sample input:
V^^
Sample output:
2
As you can see I downshifted once from N to 1 and upshifted twice to 2nd gear.
This is a code golf. Shortest answer in bytes wins.
Note: The input can be any 2 characters. Can be U and D for up and down or whatever you want it has to be a string. You cannot shift beyond 1st or 6th gear. If you are in 6th and upshift again it will stay in 6th. Good luck!
5
Next time, please post your challenge to the sandbox to get feedback before posting it on main
– fəˈnɛtɪk – 2017-02-23T13:56:48.493@LliwTelracs oh, I am sorry I didn't know that! I will keep it in mind. – Martijn Vissers – 2017-02-23T13:57:31.777
Can the input shifts be on separate lines? – seshoumara – 2017-02-23T14:33:34.963
1@seshoumara the only two requirement are that is has to be a string and that you can only input 2 characters. So could use a newline as a character. but If you'd use it for another reason, I don't really mind. it would be interesting to see what you have in mind. but give a short explaination as to why you've done it that way if you do. GL! – Martijn Vissers – 2017-02-23T14:39:59.253
I meant using D and U, but put each one on separate lines because that's the natural way of parsing in sed. – seshoumara – 2017-02-23T14:56:08.697
@seshoumara Go for it. the preferred way would be a normal 1 line string but if its the natural way of parsing I think it should be allowed – Martijn Vissers – 2017-02-23T14:57:09.693
4It's a shame this doesn't account for the half-step shift between 1 and N. It'd be neat to be able to not only go 2 N 1 N 2 3, but also go 2 1 N 2 3 – Cort Ammon – 2017-02-23T17:03:50.773
2I agree to @CortAmmon - there is a single shift between 1 and 2. It's half shift where the neutral is. – Džuris – 2017-02-23T20:29:25.560
2not all motorcycles shift like this. Most clutchless motorcycles shift in N-1-2-3-4 (or N-1-2-3 on some very ancient vehicles). They don't have gear 5 or 6 and use a round gear, i.e. when it's 4 then increasing the gear will make it wrap around to N. – phuclv – 2017-02-24T14:15:32.537
1@LưuVĩnhPhúc Ofcourse not every single motorcycle ever, but most modern motorcycles (and the one that I own) ;) – Martijn Vissers – 2017-02-24T14:36:38.663
@Lifeless most modern motorcycles in my country are automatic clutch, and there are tens of millions of them. One of the top of the world. There are very few clutched motocycles compared to clutchless and scooteres – phuclv – 2017-02-24T15:43:44.850