# I challenge you to generate the following sequence [closed]

I challenge you to generate the following sequence till 100 terms through any programming language in shortest characters possible.
The sequence is like this :-

1 2 3 4 5 10 20 30 40 50 100 200 300 400 500 ........


The output needs to be like this (above) only, nothing extra.

Remember, You can use + and - only and for mathematical calculations only (++ and -- are also allowed) and no other mathematical function like tan(), log(), pow(), ......etc.

Also, You cannot use any character variables in your code.

• "You can use + and - only for mathematical calculations" So is this a [restricted-source] challenge? Commented Apr 16, 2014 at 2:35
• Eh, seems easier to just treat them as strings and concat '0' each loop. Commented Apr 16, 2014 at 2:36
• @algorithmshark can there be [restricted-source] + [code-golf]? Commented Apr 16, 2014 at 2:37
• Wait a minute, if we can't use characters or strings, how do we output the numbers separated with spaces? Can they be newline separated instead? Commented Apr 16, 2014 at 2:44
• “You can use + and - only for mathematical calculations” – Does this mean that I must not use + and - for something other than mathematical calculations or does this mean that I must not use any other mathematical operators than + and -? Commented Apr 16, 2014 at 14:48

## GolfScript (21 chars)

If

You can use + and - only for mathematical calculations

means what it says then:

[6,1>~{4$10*}95*]' '*  If it is intended to say The only mathematical operators you can use are + and - then the multiplications can be replaced with string manipulation at the same character count: [6,1>~{4$0+}95*]' '*


Dissection:

[         # Start gathering values into an array
6,1>~   # Dump the numbers 1 to 5 onto the stack
{       # Beginning of loop body
4$# Copy the 5th item on the stack  Here the variants differ  10* # Multiply it by 10  or  0+ # Postpend '0'  And then merge again  }95* # Loop 95 times, so we end up with 100 items on the stack ] # Gather those 100 items into an array ' '* # Space-separate them  • I don't know GolfScript but 4$10* # Copy the 5th number on the stack and multiply by 10 -- Only addition subtraction and (in|de)crements are allowed Commented Apr 16, 2014 at 14:04
• @user80551, that's not clear to me, but it's easily worked around at the same character count. Commented Apr 16, 2014 at 14:34

## Perl, 38 bytes

Disclaimer: The restrictions of the changed question are not too clear to me.

for$i(0..19){print$_.0 x$i.$"for 1..5}


The code uses variables with integer values except for $" which is used for the separation space. It can be easily replaced by ' ' (+1 byte). Mathematical operations are not used, the code only contains string concatenations and the repetition operator. The result are 100 numbers: 1 2 3 4 5 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000 10000 20000 30000 40000 50000 100000 200000 300000 400000 500000 1000000 2000000 3000000 4000000 5000000 10000000 20000000 30000000 40000000 50000000 100000000 200000000 300000000 400000000 500000000 1000000000 2000000000 3000000000 4000000000 5000000000 10000000000 20000000000 30000000000 40000000000 50000000000 100000000000 200000000000 300000000000 400000000000 500000000000 1000000000000 2000000000000 3000000000000 4000000000000 5000000000000 10000000000000 20000000000000 30000000000000 40000000000000 50000000000000 100000000000000 200000000000000 300000000000000 400000000000000 500000000000000 1000000000000000 2000000000000000 3000000000000000 4000000000000000 5000000000000000 10000000000000000 20000000000000000 30000000000000000 40000000000000000 50000000000000000 100000000000000000 200000000000000000 300000000000000000 400000000000000000 500000000000000000 1000000000000000000 2000000000000000000 3000000000000000000 4000000000000000000 5000000000000000000 10000000000000000000 20000000000000000000 30000000000000000000 40000000000000000000 50000000000000000000  Ungolfed: for$i (0..19) { # 20 * 5 = 100 numbers
for $_ (1..5) { print$_     # first digit
. 0 x $i # zeros .$"     # separator (space)
}
}

• Not a bad solution. The shortest I could manage was 34: print 1..5,!($,="0$,"||$")for a..t Commented Apr 17, 2014 at 7:25 ## Python 60 r=range for i in r(20): for j in r(1,6):print str(j)+'0'*i,  Thanks to @ace for pointing out that this was way too long. ## Python 113 from itertools import* i=j=0 for x in cycle(range(1,6)): i+=1;print str(x)+'0'*j, if i%5==0:j+=1 if i>99:break  • It should be shorter if you use two loops instead of itertools Commented Apr 16, 2014 at 9:16 • for j in'12345' lets you omit the str() command, which brings you down to 51 characters, if you remove the first line and spell out range Commented Apr 16, 2014 at 14:39 • @MrLemon j will then become a character variable which is not allowed. Commented Apr 16, 2014 at 14:58 • @user80551 I totally overlooked that part, you are correct. Commented Apr 16, 2014 at 15:12 • Use list comprehension and this will reduce to 47 characters [i*10**j for j in range(21)for i in range(1,6)] Commented Apr 16, 2014 at 15:47 # GolfScript, 30 25 characters (26 23 newline separated) ;6,1>{.{10*}%}20*][]*' '*  Commented: ; # pop the input string (empty) 6,1> # generate [1 2 3 4 5] {.{10*}%} # duplicate the array and multiply everything by 10 20* # do this 20 times (5 * 20 = 100) ] # wrap the whole stack in an array []* # flatten ' '* # join by space  I really don't like the repetition at the end, but GS doesn't provide a flat_map or flatten of any sort. Thanks @PeterTaylor for providing a way to flatten! If we can separate by newlines instead of spaces, then 23 characters: ;6,1>{.{10*}%}20*][]*n*  • You should create a programming language called DoorknobScript. Commented Apr 16, 2014 at 5:50 • To get an array of 1 to 5 it's better to do either 6,(; or 6,1>. GS does provide a couple of ways to do one-level flatten: []* or {~}%. But to use either you'll need to remove the initial '' from the stack (which is currently giving you output with a leading space) or avoid including it by using an explicit [. Commented Apr 16, 2014 at 7:34 • {.{10*}%} # duplicate the array and multiply everything by 10 Multiplying isn't allowed. Commented Apr 16, 2014 at 14:08 • @user Where does it say that? Most of the other answers use multiplication too. Commented Apr 16, 2014 at 15:04 • It says "Remember, You can use + and - only and for mathematical calculations only (++ and -- are also allowed)". Doesn't "only" means ..... "only"? Commented Apr 16, 2014 at 17:02 ## APL (17 24) ,⍉10⊥¨(⍳5)∘.{⍺,1↓⍵/0}⍳20  • Multiply and power are not allowed. Commented Apr 16, 2014 at 14:05 • @user80551: ok I changed it Commented Apr 16, 2014 at 14:16 # Java,185 class g {public static void main(String[] args){for(int x=0;x<20;x++){for(int i=1;i<6;i++){System.out.print(""+i); for(int j=0;j<x;j++){System.out.print("0");}System.out.print(" ");}}}}  • You forgot a space between int and j so your code didn't compile. I edited your answer to fix that. Commented Apr 16, 2014 at 13:31 • It's also an infinite loop rather than printing 100 terms. Commented Apr 16, 2014 at 13:36 • Oh ok, sorry I'll edit it. Commented Apr 16, 2014 at 13:38 • You can get it down to 169 by 1) renaming args 2) restructuring the loops and 3) declaring your ints up front : class G{public static void main(String[]a){int x=0,i,j;for(;x<20;x++)for(i=0;i++<5;System.out.print(" ")){System.out.print(""+i);for(j=0;j++<x;System.out.print("0"));}}} Commented Apr 16, 2014 at 13:51 • Can't you remove the space just before the third for Commented Apr 16, 2014 at 14:19 # Julia - 38 [print(i,"0"^j," ") for i=1:5,j=0:19];  ### Output: 1 2 3 4 5 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000 5000 10000 20000 30000 40000 50000 100000 ...  • -1 , multiplication and power are not allowed. Commented Apr 16, 2014 at 14:06 • Now they are strings, so i think it doesnt break the rules – CCP Commented Apr 16, 2014 at 14:30 • I just wrote the exact same solution before seeing yours. – gggg Commented Apr 16, 2014 at 17:43 # C, 93 i;main(j,k){for(;++i;)for(j=0;++j<6;){for(putchar(48+j),k=0;++k<i;putchar(48));putchar(32);}}  // it draws nice patterns on the terminal... • 87 bytes Commented Apr 10, 2020 at 19:54 # PHP - 61 for($i=0;$i++<21;)for($j=0;$j++<5;)echo str_pad($j,\$i,0).' ';