+ 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
8 Answers
+ 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.
+ 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
+ 3
Implemented in java :
https://code.sololearn.com/cgSRwaJfv05J/?ref=app
+ 3
I think this is the algorithm you want. Tell me if you need an explanation.
https://code.sololearn.com/cP2hqC23u6Sg/?ref=app
+ 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!
+ 3
here is my final code, thanks to all you guys I finally made it.
https://code.sololearn.com/WTZOADJ67D59/?ref=app
+ 1
https://code.sololearn.com/cp1JlhxsRHym/?ref=app
0
Late reply as only just saw this today. Here's my solution in C:
https://code.sololearn.com/ctVS95HvCf80/#c