One Million Hits

March 29, 2013

Programming Praxis passed one-million all-time hits yesterday at 9:22pm GMT (that’s 4:22pm CDT where I live). My thanks to all of you for making this happen.

Your task is to write a program that outputs the number 1000000; be as fun and creative as you can. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

10 Responses to “One Million Hits”

  1. No one relevant said

    print bin(64)[2:]

  2. […] today’s Programming Praxis exercise, our goal is ro print the number 1000000 in a creative way. Let’s […]

  3. My Haskell solution (see http://bonsaicode.wordpress.com/2013/03/29/programming-praxis-one-million-hits/ for a version with comments):

    main :: IO ()
    main = print . pred $ sum (zipWith (*) q (tail q)) + head q - last q
        where q = map fromEnum "Real programmers don't comment their code, \
                               \if it was hard to write, it should be hard \
                               \to understand and harder to modify."
    
  4. Jussi Piitulainen said

    This is too simple, but I needed it for real earlier today.
    I just wasn’t sure of counting the zeroes, and I don’t know if
    the system understands anything but a string of digits, so:

    ./configure \
    --enable-single-host \
    --enable-c-opt \
    --enable-multiple-versions \
    --enable-shared \
    CFLAGS=-D___FORCE_MAX_HEAP=$(echo 1,000,000 | tr -d ,)

  5. Jan Van lent said

    Forth program inspired by [1].
    The number one million represented using postfix notation with only the number one, addition and multiplication.

    1 1 + 1 + 1 1 + 1 + * 1 1 + * 1 1 + * 1 + 1 1 + 1 + * 1 1 + 1 + * 1 1 + 1 + * 1 +
    1 1 + 1 + 1 1 + 1 + * 1 1 + * 1 1 + * 1 + 1 1 + 1 + * 1 1 + 1 + * 1 1 + 1 + * 1 +
    * .
    

    [1] Zeroless Arithmetic: Representing Integers ONLY using ONE,
    Edinah K. Gnang and Doron Zeilberger,
    http://www.math.rutgers.edu/~zeilberg/mamarim/mamarimhtml/arif.html

  6. Jan Van lent said

    Postscript program using the number one, addition and exponentiation.

    1 1 add 1 add 1 1 add exp 1 add 1 1 add 1 add exp 1 1 add exp =
    
  7. Jussi Piitulainen said

    This one I wrote just for fun: a random binary digit for each letter
    of “million”, freely instantiated but constrained to match. Cheers.

    (define (digit) (random-integer 2))
    (define (fold op o args)
      (if (null? args) o
          (fold op (op o (car args)) (cdr args))))

    (fold (lambda (o arg)
            (do ((x (digit) (digit))
                 (y (digit) (digit)))
                ((o x y) (write x) <))) >
          (string->list "million"))

    (newline)

  8. djschoch said
    declare
        one_million pls_integer := 1;
    begin
        dbms_output.put_line('To my good friend, Mr. P. Praxis,'||chr(10));
        dbms_output.put_line('Congratulations on reaching one million total hits!'||chr(10));
        
        -- count to one million (or thereabouts)
        for i in 1..1000000 loop
            one_million := one_million + 1;
        end loop;
        
        dbms_output.put_line('As you requested, here is the number one million written '||
            'from one of your least favorite programming languages, Oracle PL/SQL:');
        dbms_output.put_line(to_char(one_million,'9,999,990')||chr(10));
        dbms_output.put_line('(What fun is a PL/SQL program without a little bug in it?)'||chr(10));
        dbms_output.put_line('-Dan-');
    end;
    /
    
    To my good friend, Mr. P. Praxis,
    
    Congratulations on reaching one million total hits!
    
    As you requested, here is the number one million written from one of your least
    favorite programming languages, Oracle PL/SQL:
    1,000,001
    
    (What fun is a PL/SQL program without a little bug in it?)
    
    -Dan-
    P.S. WordPress currently states that the "pre" tag IS allowed, so I'm trying it here.
    
    PL/SQL procedure successfully completed.
    
  9. programmingpraxis said

    Thanks Dan (and others). I’m beginning to think this Internet thing really works.

    By the way, WordPress doesn’t count what it calls syndicated views, which are things like RSS feeds where people read the blog without actually generating a hit. Most exercises generate two or three times as many syndicated views as hits, so the actual count is higher. Unfortunately WordPress doesn’t give a total on syndicated views.

  10. David said

    1 million is such a small number. 1,000,000 in binary is only 64 in decimal :)

    : .bin  base @ >r  2 base ! .  r> base ! ;  ok
    64 .bin 1000000  ok
    

Leave a comment