-12
\$\begingroup\$

Use any programming language to display numbers divisible by 1000000 that are greater than 1 and less than 10000000. Each number should be displayed in new line. Your program should display exactly:

1000000
2000000
3000000
4000000
5000000
6000000
7000000
8000000
9000000
\$\endgroup\$
2
  • \$\begingroup\$ Hi, I closed your question as a duplicate of an older question, because the challenge specified there is pretty much the intent of this question. The other question is about testing divisibility between two numbers. \$\endgroup\$ Oct 27, 2018 at 17:42
  • 2
    \$\begingroup\$ @EriktheOutgolfer Not all answers here can be ported there, this one is more trivial. (being trivial should not be a reason for closing) \$\endgroup\$
    – DELETE_ME
    Oct 28, 2018 at 15:02

21 Answers 21

3
\$\begingroup\$

Japt -R, 5 bytes

9õ*L³

Test it


Explanation

9õ        :Range [1,9]
  *       :Multiply each by
   L      :100
    ³     :Cubed
          :Implicitly join with newlines and output
\$\endgroup\$
3
\$\begingroup\$

Python 2, 29 bytes

i=0;exec'i+=10**6;print i;'*9

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Bash, 13 bytes

seq {1,1,9}e6

Try it online!

This answer is found out by @manatwork

\$\endgroup\$
3
  • \$\begingroup\$ seq {1,1,9}e6 \$\endgroup\$
    – manatwork
    Feb 21, 2019 at 9:13
  • \$\begingroup\$ @manatwork great! never heard such a notation before. \$\endgroup\$
    – tsh
    Feb 21, 2019 at 9:38
  • \$\begingroup\$ Is just a usual brace expansion. echo seq {1,1,9}e6 will show you that it expands to your original code. \$\endgroup\$
    – manatwork
    Feb 21, 2019 at 9:42
2
\$\begingroup\$

Whitespace, 85 bytes

[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S S _Add][S N
S _Duplicate][S S S T   S T S N
_Push_10][T S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_EXIT][S N
S _Duplicate][S S S T   T   T   T   T   S T S S S N
_Push_1000][S N
S _Duplicate][T S S N
_Multiply][T    S S N
_Multiply][T    N
S T _Print_number][S S S T  S T S N
_Push_10][T N
S S _Print_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Pseudo-code:

Integer i = 0
Start LOOP:
  i = i + 1
  If(i == 10):
    Exit with an error
  Integer j = 1000 * 1000 * i
  Print j as number to STDOUT
  Print "\n"
  Go to next iteration of LOOP
\$\endgroup\$
2
\$\begingroup\$

PowerShell, 14 bytes

1..9|%{$_*1e6}

Try it online!

Simply loops from 1 to 9 and multiplies each by 1e6, i.e., 1000000, to give the appropriate numbers. Ho-hum boring. Saved 7 bytes thanks to mazzy.

Previous versions:


PowerShell, 21 bytes

1..9|%{"$_"+"000000"}

Try it online!

Boring simple loop from 1 to 9 that just string-concatenates the output together.


PowerShell, 21 bytes

1e6..9e6|?{!($_%1e6)}

Try it online!

Loops from 1e6 to 9e6, pulls out those entries where they're divisible by 1e6. Times out on TIO but works offline. Run it with 3 instead of 6 to see the logic better.

\$\endgroup\$
2
  • \$\begingroup\$ ? 1..9|%{$_*1e6} \$\endgroup\$
    – mazzy
    Oct 29, 2018 at 21:19
  • \$\begingroup\$ @mazzy Of course! The most boring solution yet! Haha. \$\endgroup\$ Oct 30, 2018 at 12:35
1
\$\begingroup\$

Neim, 8 bytes

9Δμ7𝕎𝕋)_

Try it online!

\$\endgroup\$
1
\$\begingroup\$

05AB1E, 6 bytes

9L6°*»

Try it online.

Explanation:

9L        # List in the range [1,9]
  6°*     # Multiply each by 10**6
     »    # Join the list by newlines (and output implicitly)
\$\endgroup\$
1
\$\begingroup\$

Java 11, 62 61 56 54 bytes

v->{for(int i=0;i++<9;)System.out.println(i*1000000);}

-2 bytes thanks to @ggorlen.

Try it online.

Explanation:

v->{                        // Method with empty unused parameter and no return-type
  v->{for(int i=0;i++<9;)   //  Loop `i` in the range (0,9]
    System.out.println(     //   Print without trailing newline:
     i*1000000);}           //    `i` multiplied by 1,000,000
\$\endgroup\$
2
  • 1
    \$\begingroup\$ You could save a couple bytes with v->{for(int i=0;i++<9;)System.out.println(i*1000000);} \$\endgroup\$
    – ggorlen
    Oct 30, 2018 at 18:33
  • \$\begingroup\$ @ggorlen Can't believe I didn't check if that was shorter.. I did try printf("%.0f%n",i*1e6) and println((int)(i*1e6)) but forgot about just println(i*1000000).. Thanks! \$\endgroup\$ Oct 30, 2018 at 20:01
1
\$\begingroup\$

Python 3, 35 bytes

for i in range(1,10):print(i*10**6)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Keg, 17 bytes

Ϩ²:(
;|:.
,':"+

Try it online!

Explanation

Ϩ    # Push 1k
 ²   # Square the value
  :( # Copy the value for the accumulator
;|   # Repeat 10-1 times:
  :. # Print TOS
,    # Print newline
 ':" # Copy 1m to TOS
    + #Add the values

Keg, 8 bytes (SBCS) (Doesn't seem to work online yet)

9Ï_⑷ė6Ë*

Try it online!

Explanation

9Ï_     #Generate range 1-9 by generating range 0-9 and discarding 0
   ⑷        #Map the following to each element:
    ė6Ë*    #   Multiply each by 10 to the power of 6
#-pn puts newlines between each item, which is printed using -no
\$\endgroup\$
3
1
\$\begingroup\$

W n d, 5 bytes

-í╞6\

Explanation

Decompressed:

9    M % Map in the range 1..9
 a  *  % Multiply the current item by ...
  6^   % ... 10 to the power of 6
\$\endgroup\$
0
\$\begingroup\$

JavaScript (Node.js), 35 bytes

for(i=0;i++<9;)console.log(i*10**6)

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Attache, 16 bytes

Output[1:9*10^6]

Try it online!

Explanation

Output[1:9*10^6]
       1:9          the range from 1 to 9
          *10^6     multiplied by 10^6 (1e6)
Output[        ]    output each entry on its own line
\$\endgroup\$
0
\$\begingroup\$

///, 29 bytes

/!/000000
/1!2!3!4!5!6!7!8!9!

Try it online!

33 bytes for no trailing newline:

/"/000//!/""
/1!2!3!4!5!6!7!8!9""

Try it online!

\$\endgroup\$
0
\$\begingroup\$

C++ 44 bytes

for(int i=1;i<=9;i++){cout<<i*100**6<<endl;}
\$\endgroup\$
0
\$\begingroup\$

Retina, 16 bytes


9*
L$`.
$.>`6*0

Try it online! Explanation:


9*

Insert 9 _s.

L$`.

List a value for each _.

$.>`6*0

Number of characters up to and including the current _ followed by six zeros.

\$\endgroup\$
0
\$\begingroup\$

C# (.NET Core), 48 44 bytes

for(int i=0;i++<9;)Console.WriteLine(i*1e6);

Try it online!

-4 bytes: changed i*1000000 to i*1e6 in Console.WriteLine()

Ungolfed:

for (int i = 0; i++ < 9;)               // from 1 to 9
    Console.WriteLine(i * 1e6);     // write i times 1,000,000 (1e6 = 1*(10^6) = 1,000,000) to the console
\$\endgroup\$
0
\$\begingroup\$

APL (Dyalog Unicode), 7 bytesSBCS

Full program.

⍪1E6×⍳9

Try it online!

⍳9ɩndices one through nine

1E9× multiply million by those

 columnify

\$\endgroup\$
0
\$\begingroup\$

Ruby, 30 24 bytes

(1..9).map{|d|p d*10**6}

Try it online!

-6 bytes: use map instead of step. Use 10**6 instead of 1e6.to_i

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Oct 18, 2019 at 4:41
0
\$\begingroup\$

Jelly, 6 bytes

9Rȷ6×Y

Try it online!

Explanation

9R     [1, 2, ..., 8, 9]
  ȷ6   100000
    ×  Multiply each
     Y Join by newline
\$\endgroup\$
0
\$\begingroup\$

x86-16 machine code, IBM PC DOS, 31 26 bytes

00000000: ba10 018b fab1 09b4 09cd 21fe 05e2 fac3  ..........!.....
00000010: 3130 3030 3030 300d 0a24                 1000000..$

Listing:

BA 0110     MOV  DX, OFFSET O           ; DOS pointer to output string 
8B FA       MOV  DI, DX                 ; pointer to defrerence for increment 
B1 09       MOV  CL, 9                  ; counter to 9 
8A E1       MOV  AH, CL                 ; DOS write string function also to 9 
        LOOPY: 
CD 21       INT  21H                    ; write string to stdout 
FE 05       INC  BYTE PTR[DI]           ; increment first digit 
E2 FA       LOOP LOOPY                  ; loop 9 times 
C3          RET                         ; return to DOS 
        O:  DB  '1000000',0DH,0AH,'$'   ; output string

Standalone DOS executable, output to STDOUT.

enter image description here

TODO: re-do screenshot with old program length!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.