+ 42

[ASSIGNMENT] Lets generate this pattern!!

var array=[1,2,3,4,5,6,7,8, 9]; //pattern 123 234 345 456 567 678 789 891 912 123 ....to infinity the pattern itself is easy,the problem is the pattern restarting after its reached the end.i need this for a web code,thanks Note::it should work with an array of any length or elements.Thanks!!😄 non web codes might help too

5th Mar 2018, 10:17 PM
᠌᠌Code X
᠌᠌Code X - avatar
53 Answers
+ 47
Just do this : ""+arr[i%length]+arr[(i+1)%length]+arr[(i+2)%length] https://code.sololearn.com/WFU5e5iaEynx/?ref=app
6th Mar 2018, 5:34 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 20
https://code.sololearn.com/cNvftY4nN1Ej/?ref=app https://code.sololearn.com/c4r3Q50jQU32/?ref=app
8th Mar 2018, 7:06 AM
LukArToDo
LukArToDo - avatar
+ 16
to get the next value you can use : ( current modulo number ) + offset in your case it is : ( current % 9 ) + 1 to reach the correct next value
5th Mar 2018, 10:48 PM
David RIEHL
David RIEHL - avatar
+ 16
first part of problem as David told with modulo then to solve the situation when reached at end of array, concat the ending array part and starting array part in a single arrray , it ll happen when when( end index < start index) https://code.sololearn.com/Wj8XH9T2AJFZ/?ref=app
6th Mar 2018, 3:45 AM
Morpheus
Morpheus - avatar
+ 16
আমি বাংলাদেশি
15th Jun 2018, 1:20 PM
Minn queen
Minn queen - avatar
+ 15
☺️☺️☺️👇My try in php https://code.sololearn.com/wzaUmhkJ9mR8/?ref=app
7th Mar 2018, 3:29 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 12
My solution is surprisingly easy. But up to now all other solutions are mote complicated since we KNOW how to solve this kind of probs. https://code.sololearn.com/cxnmuCGvoshv/?ref=app
6th Mar 2018, 6:17 PM
Oma Falk
Oma Falk - avatar
+ 8
https://code.sololearn.com/cm1bWStrfqMK/?ref=app
12th Mar 2018, 7:17 PM
D_Stark
D_Stark - avatar
6th Mar 2018, 12:49 PM
Mr.Curious
Mr.Curious - avatar
6th Mar 2018, 5:42 PM
Tomás Badenes
Tomás Badenes - avatar
+ 6
https://code.sololearn.com/Wg6ImxLVHTdj/#js
6th Mar 2018, 8:46 AM
Andrew
Andrew - avatar
6th Mar 2018, 5:04 PM
dieserrapha
dieserrapha - avatar
+ 6
confusing right
6th Mar 2018, 5:27 PM
Lesley Chitsika
Lesley Chitsika - avatar
6th Mar 2018, 6:33 PM
Oma Falk
Oma Falk - avatar
+ 5
#include<iostream> using namespace std; int main() { int arr[]={1,2,3,4,5,6,7,8,9}; int i,j=0,k=0; while(k<20) { for(i=1;i<=3;i++) { if(j==10) { j==1; } cout<<arr[j]; j++; } if(j==10) { j%9+1; } j=j-2; cout<<"\n"; k++; } }
6th Mar 2018, 1:40 PM
Asim Naqvi
Asim Naqvi - avatar
7th Mar 2018, 12:45 AM
Warith Vatanaplachaigoon
Warith Vatanaplachaigoon - avatar
7th Mar 2018, 9:30 AM
Zoetic_Zeel
Zoetic_Zeel - avatar
+ 4
https://code.sololearn.com/w6v4bH35NH6X/?ref=app https://code.sololearn.com/wxnXDmklU0vy/?ref=app
8th Mar 2018, 4:28 PM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 4
https://code.sololearn.com/cALSQ6QJLu2Y/?ref=app
11th Mar 2018, 7:14 AM
Martin Möhle
Martin Möhle - avatar