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.

  • 6
    \$\begingroup\$ Sounds like a perfect fit for something written in Shakespeare: shakespearelang.sourceforge.net/report/shakespeare/… \$\endgroup\$ Feb 17 '14 at 15:31
  • 2
    \$\begingroup\$ It seems most answers are ignoring "including testing it". \$\endgroup\$
    – Anko
    Feb 17 '14 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 '14 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 '14 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 '14 at 13:45

37 Answers 37



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 '14 at 12:14
  • \$\begingroup\$ as in the comments: 'char star arg-v. int in out' \$\endgroup\$
    – AShelly
    Feb 18 '14 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 '14 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




Uses a single haiku to do the job!

f = lambda x:   \ #  f is lambda x:
    0**x or x * \ #    zero pow x, or x times
    f(x-1)        #    f(x minus 1)

This defines a recursive lambda which calculates the factorial - 0**x handles the case of 0 as it evaluates to 1.



(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 '14 at 11:27
  • \$\begingroup\$ @200_success: 0! = 1 is just a convention ;) \$\endgroup\$
    – Blender
    Feb 17 '14 at 11:27
  • \$\begingroup\$ Now it works, but the last line has six syllables. \$\endgroup\$ Feb 17 '14 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, privacy policy and cookie policy

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