g | x | w | all
Bytes Lang Time Link
066AWK250409T200230Zxrs
050JavaScript221025T111503ZShaggy
006Japt R221025T110348ZShaggy
005Vyxal j221025T104724Zlyxal
01105AB1E180810T135301ZKevin Cr
nanC150717T160213Zlynn
064Ruby150718T195519Zclapp
nanRuby150718T140857Zaddison
640Common Lisp150718T203033ZFlorian
nan150718T145358Zaddison
020J150718T050029Zgar
042Julia150717T160949ZAlex A.
019MatLab150717T163110ZRobby
056Haskell150717T161222Znimi
nanCoffeeScript150717T154642Zrink.att
960Common Lisp150717T153853Zcoredump
nanPHP150717T152328Zrink.att
023Octave150717T134313Zuser0815
010APL150717T130434ZFUZxxl
nanAPL150717T124705Zprotist
nanKDBQ150717T082838ZWooiKent
nan150717T082053Zedc65
nanCJam150717T070040ZDennis
nanPyth150717T070028Zorlp
nanPython 2150717T064930Zxnor
nanPyth150717T064853Zisaacg

AWK, 66 bytes

{for(;i++<$1;printf"%032d\n",x){j=i;for(x=X;j;j=int(j/2))x=j%2 x}}

Attempt This Online!

With formatting:

{for(;i++<$1;print""){j=i;for(x=X;j;j=int(j/2))x=j%2 x
for(k=1;k<33;k+=4)printf substr(sprintf("%032d",x),k,4)FS}}

JavaScript, 50 bytes

f=n=>n&&print(n.toString(2).padStart(32,0,f(n-1)))

Try it online!

With first bonus, 41.6 bytes

f=n=>n&&print(n.toString(2).padStart(32,0,f(n-1)),n)

Try it online!

With both bonuses, 44.8 bytes

f=n=>n&&print(...n.toString(2).padStart(32,0,f(n-1)).match(/.{4}/g),n)

Try it online!

Japt -R, 6 bytes

õȤùTH

Try it

õȤùTH     :Implicit input of integer
õ          :Range [1,input]
 È         :Map each X
  ¤        :  To binary string
   ù       :  Left pad
    T      :    with 0
     H     :    to length 32
           :Implicit output joined with newlines

With bonuses, 8.96 bytes

õȤùTH ò4 pX ¸

Try it

õȤùTH             :As above
       ò4          :Partitions of length 4
          pX       :Push X
             ¸     :Join with spaces

Vyxal j, 7 6 5 bytes

vΠ₆↳›

Try it Online!

The benefits of having built-ins to pad things with spaces and to convert spaces to 0s. Uses 64 bit integers.

two can play at the flag game Japt.

Explained

vΠ₆↳›
vΠ      # Convert each number in the range [1, input] to binary
  ₆↳    # left pad each binary string with spaces so that it's length 32
    ›   # replace spaces with 0s
        # join on newlines because of `-j` flag

05AB1E, 13 11 bytes

Lb32jsäð0:»

-2 bytes thanks to @Mr.Xcoder.

Outputs without space-delimiter nor sequence-number.

Try it online.

Explanation:

L              # List of range [1,input]
               #  i.e. 5 → [1,2,3,4,5]
 b             # Convert each to a binary string
               #  i.e. [1,2,3,4,5] → ['1','10','11','100','101']
  32j          # Join everything together with a minimum length per item of 32,
               # which basically prepends spaces to make it length 32
               #  i.e. ['1','10','11','100','101'] → '                               1                              10                              11                             100                             101'
     sä        # Split it into the input amount of parts
               #  i.e. 5 → ['                               1','                              10','                              11','                             100','                             101']
       ð0:     # Replace every space with a 0
               #  i.e. '                             101' → '00000000000000000000000000000101'
          »    # Join everything together by newlines (and output implicitly)

C, 97 * 0.8 * 0.8 = 62.08

a,x;main(b){for(scanf("%u",&b);a++<b;printf("%d\n",a))for(x=32;x--;)printf("%*d",x%-4-2,a>>x&1);}

Example output for input "5":

0000 0000 0000 0000 0000 0000 0000 0001 1
0000 0000 0000 0000 0000 0000 0000 0010 2
0000 0000 0000 0000 0000 0000 0000 0011 3
0000 0000 0000 0000 0000 0000 0000 0100 4
0000 0000 0000 0000 0000 0000 0000 0101 5
0000 0000 0000 0000 0000 0000 0000 0110 6
0000 0000 0000 0000 0000 0000 0000 0111 7
0000 0000 0000 0000 0000 0000 0000 1000 8
0000 0000 0000 0000 0000 0000 0000 1001 9

I could add one more whitespace character to separate the decimal numbers from the binary numbers, but technically the problem doesn't require it, I think? EDIT: Thanks, CL!

Ruby, 64 bit

70 * 0.8 * 0.8 = 44.8 bytes (split, decimal)

1.upto(gets.to_i){|i|puts ("%064d"%i.to_s 2).scan(/.{4}/)*?\s+" #{i}"}

51 * 0.8 = 40.8 bytes (decimal)

1.upto(gets.to_i){|i|puts "%064d"%i.to_s(2)+" #{i}"}

67 * 0.8 = 53.6 bytes (split)

1.upto(gets.to_i){|i|puts "%064d"%i.to_s(2).scan/.{4}/}

44 bytes (no bonuses)

1.upto(gets.to_i){|i|puts "%064d"%i.to_s(2)}

Ruby, 28 (35 * 0.8)

?1.upto(*$*){|x|puts"%.32b #{x}"%x}

Common Lisp, score: 64.0

100 bytes * 0.8 * 0.8

I'm pretty happy with my score, but I still feel like there should be a possibility to simplify my code a bit.

Output

0000 0000 0000 0000 0000 0000 0000 0001  1
0000 0000 0000 0000 0000 0000 0000 0010  2
0000 0000 0000 0000 0000 0000 0000 0011  3
0000 0000 0000 0000 0000 0000 0000 0100  4
0000 0000 0000 0000 0000 0000 0000 0101  5
0000 0000 0000 0000 0000 0000 0000 0110  6
0000 0000 0000 0000 0000 0000 0000 0111  7
0000 0000 0000 0000 0000 0000 0000 1000  8
0000 0000 0000 0000 0000 0000 0000 1001  9
0000 0000 0000 0000 0000 0000 0000 1010  10

Code

(defun r(n)(dotimes(i n)(format t"~{~a~a~a~a ~}~a~%"(coerce(format()"~32,'0B"(1+ i))'list)(1+ i))))

Explanation

As described in coredump's answer, the format string

"~32,'0B"

does output base2 numbers but there seems to be no possibility to get the grouping right as well. Hence I coerce the string into a list and iterate over it by picking out groups of 4 with this format string:

"~{~a~a~a~a ~}~a~%"

After each group of 4 there's a blank, and after the last group, the base10 number is printed.

Without grouping (60x0.8 => 48.0)

(defun r(n)(dotimes(i n)(format t"~32,'0B ~:*~a~%"(1+ i))))

This uses ~:* to process the (single) format argument again.

Swift: 98.56 (154 * 0.8 * 0.8)

for x in 1...Int(Process.arguments[1].toInt()!){var p=String(x,radix:2)
let q=count(p)
for i in 0..<32-q{p=(((q+i)%4==0) ?"0 ":"0")+p}
println("\(p) \(x)")}

J, 20 bytes

(32#2)#:>:i.".1!:1<1

Sample input and output:

3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1

Julia, 42 bytes

This is a bit shorter without the bonuses.

n->for i=1:n println(lpad(bin(i),64,0))end

This creates an unnamed function that takes an integer and prints the binary representation of each number from 1 to n, each left padded with zeros to 64 characters.


With bonuses, 78 bytes * 0.8 * 0.8 = 49.92

n->for i=1:n for j=1:4:64 print(lpad(bin(i),64,0)[j:j+3]*" ")end;println(i)end

This creates an unnamed function that takes an integer and prints the binary representation as before, this time split into groups of 4 with the number in base 10 at the end.

MatLab, 19 bytes

@(x)dec2bin(1:x,32)

Not too much to this one, MatLab has a built in decimal to binary converter and automatically prints the result.

Haskell, 56 bytes

f n=putStr$unlines$take n$tail$sequence$replicate 32"01"

Usage:

*Main> f 5 
00000000000000000000000000000001
00000000000000000000000000000010
00000000000000000000000000000011
00000000000000000000000000000100
00000000000000000000000000000101

For 64bit, replace the 32 with 64. Every other number works, too.

CoffeeScript, 60.8 (76 × .8)

32-bit version for reasons mentioned above, as CoffeeScript compiles down to JavaScript.

f=(x)->console.log(("0".repeat(32)+i.toString 2).slice(-32),i)for i in[1..x]

With grouping it becomes slightly longer: 64.64 (101 × .8 × .8)

f=(x)->console.log(("0".repeat(32)+i.toString 2).slice(-32).match(/.{4}/g).join(" "),i)for i in[1..x]

Common Lisp, 96.0

Score: (* 150 .8 .8)

(lambda(y)(flet((p(n &aux(x(format()"~39,'0b ~:*~d"n)))(dolist(p'(4 9 14 19 24 29 34))(setf(aref x p)#\ ))(princ x)(terpri)))(dotimes(i y)(p(1+ i)))))

Example

Calling the function with 10:

0000 0000 0000 0000 0000 0000 0000 0001 1
0000 0000 0000 0000 0000 0000 0000 0010 2
0000 0000 0000 0000 0000 0000 0000 0011 3
0000 0000 0000 0000 0000 0000 0000 0100 4
0000 0000 0000 0000 0000 0000 0000 0101 5
0000 0000 0000 0000 0000 0000 0000 0110 6
0000 0000 0000 0000 0000 0000 0000 0111 7
0000 0000 0000 0000 0000 0000 0000 1000 8
0000 0000 0000 0000 0000 0000 0000 1001 9
0000 0000 0000 0000 0000 0000 0000 1010 10

Explanation

(format()"~39,'0b ~:*~d" #b101010101010) gives:

"000000000000000000000000000101010101010 2730"

The intermediate string (an array) is modified to put a space character at the following zero-based indices: 4 9 14 19 24 29 34. Then it is printed.

Note that the apparently straightforward (format t"~39,'0,' ,4:b ~:*~d" #b101010101010) format does not do what we want. It prints:

00000000000000000000000001010 1010 1010 2730

(the padding is not grouped by 4)

PHP, 51.84 (81 × .8 × .8)

32-bit version, as PHP is limited to only 32-bit on Windows regardless of whether the OS is 64-bit.

Takes one command line argument.

for($i=0;$i++<$argv[1];)echo chunk_split(str_pad(decbin($i),32,0,0),4," ")."$i\n";

Octave, 23 characters

dec2bin(1:input(""),32)

Example output for input 5:

ans =
00000000000000000000000000000001
00000000000000000000000000000010
00000000000000000000000000000011
00000000000000000000000000000100
00000000000000000000000000000101

APL, 10 characters

Another on in APL. Assumes⎕IO←1 (the default). No bonus points. Reads the number from the input device. If your APL uses 64 bit integers instead of 32 bit integers, substitute 64 for 32 as needed.

Notice that APL transparently converts to floating point numbers when the range of an integer is exceeded. It's hard thus to exactly say what integer size APL works with.

⍉(32⍴2)⊤⍳⎕

explanation

2          ⍝ the number 2
32⍴2       ⍝ a vector of 32 twos.
(32⍴2)⊤X   ⍝ X represented as base 2 to 32 digits precision
⍳X         ⍝ a vector of the integers from 1 to X
⎕          ⍝ a number queried from the terminal
(32⍴2)⊤⍳⎕  ⍝ the output we want, flipped by 90°
⍉(32⍴2)⊤⍳⎕ ⍝ the output we want in correct orientation (⍉ is transpose)

APL, 23.68 (37 × .8 × .8)

{⎕←(⍕⍵),⍨⊃,/,/' ',⍨⍕¨8 4⍴(32⍴2)⊤⍵}¨⍳⎕

KDB(Q), 50 * 0.8 * 0.8 = 32

I feel a bit sad with my submission :( There should be a better way to do this!

{-1{" "sv raze@'string(0N 4#0b vs x),x}@'1+til x;}

Explanation

                                         1+til x     / counting
   {                                  }@'            / lambda each
                      (0N 4#0b vs x),x               / convert to binary and join with input
    " "sv raze@'string                               / convert to string, concatenate each string and join with space
{-1                                             ;}   / print and surpress output in lambda

Test

q){-1{" "sv raze@'string(0N 4#0b vs x),x}@'1+til x;}5
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 1
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0010 2
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0011 3
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0100 4
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0101 5

JavaScript (ES6) 56.8 (71*0.8)

32 bit version, as JavaScript can not handle 64 bit precision (at most 53 bits using floating point doubles)

Without grouping

f=n=>{for(i=0;i++<n;)console.log((8*(8<<26)+i).toString(2).slice(1),i)} 

With grouping - score 60.16 (94*.64)

f=n=>{for(i=0;i++<n;)console.log((8*(8<<26)+i).toString(2).slice(1).match(/..../g).join` `,i)}

Test in any browser (ES5)

function f(n)
{
  for(i=0;i++<n;)console.log((8*(8<<26)+i).toString(2).substr(1).match(/..../g).join(' '),i)
}

// Test
console.log = function(x,y) { O.innerHTML += x+' '+y+'\n' }
Count to: <input id=I><button onclick="O.innerHTML='';f(+I.value)">-></button>
<pre id=O></pre>

CJam, 13.44 (21 × 0.64)

ri{)_2b64Ue[4/S*S@N}/

Try it online.

Pyth, 18 * 0.8 * 0.8 = 11.52 bytes

VSQjd+c.[64.BN\04N

Example output:

0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 1
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0010 2
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0011 3
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0100 4
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0101 5
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0110 6
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0111 7
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 8
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1001 9
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1010 10

Python 2, 48 * 0.8 = 38.4

i=0;exec"i+=1;print format(i,'032b'),i;"*input()

Converts a number to binary, uses string formatting to convert it to binary with 32 digits, and then also prints the decimal number for the bonus. Uses an exec loop to increment from 1 to the input value.

Pyth, 19 * 0.8 * 0.8 = 12.16 bytes

VSQjd+cjk.[032.BN4N

Example output for input 5:

0000 0000 0000 0000 0000 0000 0000 0001 1
0000 0000 0000 0000 0000 0000 0000 0010 2
0000 0000 0000 0000 0000 0000 0000 0011 3
0000 0000 0000 0000 0000 0000 0000 0100 4
0000 0000 0000 0000 0000 0000 0000 0101 5

Demonstration.