I’m making a program that prints all possible mixtures of numbers from 0 to 9 and I want to delete the numbers that my code puts before the actual number if the output is less than 6 places.
I’ve tried putting “” before 0 in every array, but it also puts random spaces in the output.
JavaScript
x
15
15
1
Class1 = [0,1,2,3,4,5,6,7,8,9]
2
Class2 = [0,1,2,3,4,5,6,7,8,9]
3
Class3 = [0,1,2,3,4,5,6,7,8,9]
4
Class4 = [0,1,2,3,4,5,6,7,8,9]
5
Class5 = [0,1,2,3,4,5,6,7,8,9]
6
Class6 = [0,1,2,3,4,5,6,7,8,9]
7
8
for i in Class1:
9
for j in Class2:
10
for k in Class3:
11
for l in Class4:
12
for m in Class5:
13
for n in Class6:
14
print (i,j,k,l,m,n)
15
So I want it to output lets say 895 and not 000895. It does that until it reaches 100000, but that’s logical.
Advertisement
Answer
Replace:
JavaScript
1
2
1
print (i,j,k,l,m,n)
2
By:
JavaScript
1
2
1
print (100000*i+10000*j+1000*k+100*l+10*m+n)
2