Create a program that calculates the factorial of a number using no built-in factorial functions. Easy? The catch is that you must write your entire program (including testing it) in haiku form.

Not enough work
You can use as many haikus as you need, but when pronounced, they must follow the 5-7-5 syllable format.


This is a , so you must get the most upvotes to win. Your program must consist of at least one full haiku, and all haikus must be complete.

When reading code, the first line of each haiku will have 5 syllables, the second will have 7, and the third will have 5.

  • 7
    \$\begingroup\$ Sounds like a perfect fit for something written in Shakespeare: shakespearelang.sourceforge.net/report/shakespeare/… \$\endgroup\$ Feb 17, 2014 at 15:31
  • 2
    \$\begingroup\$ It seems most answers are ignoring "including testing it". \$\endgroup\$
    – Anko
    Feb 17, 2014 at 18:16
  • 5
    \$\begingroup\$ I like how you link to a site that correctly says the important thing for Haiku are (a) kiru and (b) a seasonal reference and then only ask for the more or less optional part of counting mora (or syllables in a language that doesn’t really have mora. 😸 \$\endgroup\$ Feb 17, 2014 at 20:40
  • 1
    \$\begingroup\$ I agree with @ChristopherCreutzig -- it would be much more interesting if we had to ensure a seasonal reference and cutting. Sadly, we often overlook these fundamentals of haiku. Seems to me that then or punctuation could aid in cutting. For kigo, not so sure... \$\endgroup\$ Feb 18, 2014 at 1:42
  • \$\begingroup\$ I am no expert to Haikus, but there is certainly some lyrical quality expected. So far I only see one answer that has any. \$\endgroup\$
    – SebastianH
    Feb 18, 2014 at 13:45

38 Answers 38



Three haikus:


Last line is admittedly kind of cheaty.

Try here: http://www.bedroomlan.org/tools/befunge-93-playground



Least beautiful haiku ever.

int main(int argc,           
char *argv[]){int in,out;

(in > 


Int main, int argc,
char star argv. Int in out.
Sscanf argv 

sub one, percent d, 
and in. Out equals one. While 
in is greater than

one, out times equals
in minus minus. Printf
percent d out. Done
  • \$\begingroup\$ How do you pronounce char *argv[]){int in,out; to have it 7 syllables? I count 5-6, depending on pronounciation of argv... \$\endgroup\$ Feb 18, 2014 at 12:14
  • \$\begingroup\$ as in the comments: 'char star arg-v. int in out' \$\endgroup\$
    – AShelly
    Feb 18, 2014 at 14:41
  • \$\begingroup\$ Erm... totally missed the comments, was used to have them right to the code by the other answers :D Nevermind. \$\endgroup\$ Feb 18, 2014 at 14:42

Perl - 3 Haikus

This one useds some clever formatting and pronunciations - it also disregards symbols.

print "Enter number: ";
chomp(my $num = <STDIN>);
$result = 1;
for $x (1..$num) {
  $new = $x * $result;
  $result = $new;
if (1) { print "$result\n .
Is the factorial of\n";
if ($result) { print "$num"; }


Print: En-ter num-ber
Chomp: my num e-quals STD (stand)-IN
Re-sult e-quals one

For x one to num (or 'one range num')
New e-quals x times re-sult
re-sult e-quals new

If one: print re-sult
Is the fac-to-ri-al of
If re-sult: print num

Let me know if I messed up anywhere.


Mathematica - One Haiku (+1 extra (2 counting title))

 := Product @@
  Range[1, n]

fac-tor-i-al en

set de-layed pro-duct ap-ply

range from one to en

From some simple words

Complex functions can arise



C (GCC), 4 haikus

int fac(int number) { // int fac int number
        if (number == 0) { // if number equals zero
                puts("Done."); return 1; // puts done return one

        else return number // else return number
                * fac(number - 1); // times fac number minus one
        puts("Unreachable"); // puts unreachable

main(argc, argv) // main arg-c arg-v
        char ** argv; { // char pointer pointer arg-v
        char c = getchar(); // char c is getchar

        printf("%" // print-f ampersand
                "d", fac(c - '0')); // d fac c minus zero
        return +0; // return plus zero

Try It Online!



(defn fact [n] (if                  # def-fun fact n if
  (zero? n) 1                       # zero question mark n 1
  (* n (fact (dec n)))))            # times n fact dec n

Python 2

print(reduce(lambda              # print reduce lambda
    a,b: a * b, range(1,         # a b a times b range one
        1 + input()), 1))        # one plus input, one
  • \$\begingroup\$ When input is 0, TypeError: reduce() of empty sequence with no initial value \$\endgroup\$ Feb 17, 2014 at 11:27
  • \$\begingroup\$ @200_success: 0! = 1 is just a convention ;) \$\endgroup\$
    – Blender
    Feb 17, 2014 at 11:27
  • \$\begingroup\$ Now it works, but the last line has six syllables. \$\endgroup\$ Feb 17, 2014 at 12:32

Python - Two Haikus

val = int(input())        -> val is int(input())
for hi in range(1,n):   -> for hi in range one to n
    val *= hi           -> val is val times hi

# Still a cool haiku    -> Just read it
print(n)                -> print val in parentheses
# Completed haiku       -> Just read it   

Try it online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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