+ 4

[Challenge ] create this function and pattern

1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 ..... create a function that changes the values of a variable in above pattern and then returns the value

12th Mar 2018, 5:51 PM
Code Ninja
Code Ninja - avatar
8 Antworten
+ 4
Suppose you want to print the series upto n terms. take a variable x with initial value 1 and y with initial value 1. Create a loop which runs from 1 to n (you have to use a counter variable to do so whose value increases after each execution of loop). Inside the loop :- 1.print x 2. if x is equal to 5 , reassign value of y to 0. 3. if x is equal to 1 , reassign value of y to 1. 4. if y is 1 , increase value of x by 1. 5. if y is 0 , decrease value of x by 1.
12th Mar 2018, 6:10 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 4
keep it simple in RL I would put it in while (1) to keep going. https://code.sololearn.com/cTU1srA4RICz/?ref=app if it has to be a formula, here goes https://code.sololearn.com/c9dMT0Gn8CN4/?ref=app
12th Mar 2018, 7:09 PM
Louis
Louis - avatar
12th Mar 2018, 6:14 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
+ 3
I think this is the algorithm you want. Tell me if you need an explanation. https://code.sololearn.com/cP2hqC23u6Sg/?ref=app
12th Mar 2018, 9:38 PM
clement
clement - avatar
+ 3
Hello, Code Ninja! Thank you for your challenge. I made a simple piece of a code using basic lessons of Python 3 course here on SoloLearn, hope it will give you a clue on how to make this pattern: https://code.sololearn.com/cRN6N4tUZMxC/#py Obviously, you can ignore the cycles and make the output designed in a different way for your own purposes. I made the patterns stored in a dictionary for visuals. Have a great week!
13th Mar 2018, 8:12 AM
Andrey Vostokov
Andrey Vostokov - avatar
+ 3
here is my final code, thanks to all you guys I finally made it. https://code.sololearn.com/WTZOADJ67D59/?ref=app
13th Mar 2018, 6:10 PM
Code Ninja
Code Ninja - avatar
+ 1
https://code.sololearn.com/cp1JlhxsRHym/?ref=app
18th Mar 2018, 8:03 AM
‎ ‏‏‎Anonymous Guy
0
Late reply as only just saw this today. Here's my solution in C: https://code.sololearn.com/ctVS95HvCf80/#c
8th Apr 2018, 10:43 PM
Emma