Problem of the Day
A new programming or logic puzzle every Mon-Fri

Smallest Compiled Program

Today's challenge will require you to use a compiled language (ie not javascript, python, or ruby). The goal is to create the smallest program in that language that will compile and print out "Hello ProblemOTD".

Permalink: http://problemotd.com/problem/smallest-compiled-program/

Comments:

  • btgrant - 10 years, 1 month ago

    In Scala, we can write:

    object HelloPOTD extends App {
      println("Hello ProblemOTD")
    }
    

    This can be compiled: scalac HelloPOTD.scala ... and then run: scala HelloPOTD.

    Just in case it's not "cheating", we can get away with less if we write a Scala script:

    println("Hello ProblemOTD")
    

    This can be compiled and run: scala HelloPOTDScript.scala

    Both scenarios produce the prescribed output.

    reply permalink

  • Derek - 10 years, 1 month ago

    C

    main(){puts("Hello ProblemOTD");}
    

    Compile with

    gcc hello.c
    

    It gives a whole bunch of warnings, but #includes for standard functions, function type declarations and return statements are technically optional in C (at least the dialect that gcc understands)!

    reply permalink

  • Derek - 10 years, 1 month ago

    FWIW, I'm sure there's a whole bunch of dirty black magic obfuscation tricks that could compress this even further. I'm not that ambitious.

    reply permalink

  • David - 10 years, 1 month ago

    Since you highlight use of a compiled language, do you intend for the "smallest program" to refer to byte size of the compiled program or the character length of the code?

    reply permalink

Content curated by @MaxBurstein