+ 20

[M💙 Challenge] Where's the Number? 🔮 (Naïve Cup Shuffle ver.)

Monday Blue 💙 Challenge Series #9 Let's play some tricks this week! This time we will simulate cup shuffling process and determine the position of the target number after shuffling with predefined steps. 💼 TASK Write a program to accept 3 parameters:- ✔ Cup numbers: [ 1, 3, 4, 5, 2 ] * natural numbers start with 1 up to the number of cups and shuffled initially ✔ Target number: 1 * one of the previous stated cup number ✔ Shuffle sequence: [ 1, 4 ] * The cup position (1-based) to be swapped and swapping occurs between the cup at the opposite end. That means cup at position 1 and 4 will be swapped with 5 and 2 respectively. No shuffle will be performed when the position was located at the center for odd number of cups. Based on the example above, the following process will be carried out:- [ 1, 3, 4, 5, 2 ] ⬇ (shuffle at position 1) [ 2, 3, 4, 5, 1 ] ⬇ (shuffle at position 4) [ 1, 5, 4, 3, 2 ] and finally output "Cup no. 1 at position 1". 🔧 TEST CASE [ 1, 2 ] | 1 | [ 1, 2, 2, 2, 1 ] "Cup no. 1 at position 2." [ 1, 2, 3 ] | 2 | [ 1, 3 ] "Cup no. 2 at position 2." [ 1, 2, 3, 4, 5 ] | 4 | [ 3, 1, 4, 5, 2 ] "Cup no. 4 at position 4." ❤ BONUS Clear-cut and optimized approach is encouraged. Please refrain from giving hints to others in this post before the challenge ends one week after. Happy Coding!!! 😁💻

13th Nov 2017, 5:21 AM
Zephyr Koo
Zephyr Koo - avatar
12 Answers
13th Nov 2017, 4:04 PM
Hiroki Masuda
Hiroki Masuda - avatar
+ 13
@Uria Glad to hear that! I purposely made it after recalling the famous quote: "Resists the temptation to code" 😉
14th Nov 2017, 2:45 AM
Zephyr Koo
Zephyr Koo - avatar
+ 12
Good luck Pegasus! 😉
13th Nov 2017, 5:42 AM
Zephyr Koo
Zephyr Koo - avatar
13th Nov 2017, 11:44 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 8
sayan didn't let me do first nuuu
13th Nov 2017, 5:45 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
Thanks everyone for your participation! My job is lighter this time as we got a few submissions only. As you might have already observed, it's not necessary to use a loop explicitly to perform swapping to determine the final position as the target will remain in the same place after even number of related swaps (itself or it opposite). The same logic goes for odd number of related swaps as well and it will move to the opposite position. In fact, this challenge was inspired by the quote "Resists the temptation to code" which explains one should analyse the problem to identify the underlying pattern before start to code. 😉 I hope you all enjoy and let's move on to the next challenge! ❤ https://www.sololearn.com/Discuss/869525/?ref=app
20th Nov 2017, 3:34 AM
Zephyr Koo
Zephyr Koo - avatar
+ 7
https://code.sololearn.com/c85o7B1es7gQ/?ref=app Simple and sweet solution
13th Nov 2017, 5:50 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
I shall attempt
13th Nov 2017, 5:35 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
heres mine//WITH ALL STEP BY STEP STAGES @# Zypher (( with your given test cases)) ## Wrong input checking added## https://code.sololearn.com/c05rtLyJTZgx/?ref=app
13th Nov 2017, 5:42 AM
sayan chandra
sayan chandra - avatar
+ 1
I really liked the challenge!!! This is the traditional way: https://code.sololearn.com/c3C9A0vzkj5S And this is a different mathematical approach (no need to swap): https://code.sololearn.com/ccmn3R55gLbP
13th Nov 2017, 9:37 PM
Uria
0
TR
13th Nov 2017, 1:59 PM
Tümer Özdemirci
Tümer Özdemirci - avatar