# Factorial in haiku!

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.

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

### Scoring

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.

• Sounds like a perfect fit for something written in Shakespeare: shakespearelang.sourceforge.net/report/shakespeare/… Feb 17 '14 at 15:31
• It seems most answers are ignoring "including testing it".
– Anko
Feb 17 '14 at 18:16
• 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. 😸 Feb 17 '14 at 20:40
• 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... Feb 18 '14 at 1:42
• I am no expert to Haikus, but there is certainly some lyrical quality expected. So far I only see one answer that has any. Feb 18 '14 at 13:45

C

Least beautiful haiku ever.

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

[1],"%d",
&in);out=1;while
(in >

1){out*=
in--;}printf(
"%d",out);}//done

/*
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
*/

• How do you pronounce char *argv[]){int in,out; to have it 7 syllables? I count 5-6, depending on pronounciation of argv... Feb 18 '14 at 12:14
• as in the comments: 'char star arg-v. int in out' Feb 18 '14 at 14:41
• Erm... totally missed the comments, was used to have them right to the code by the other answers :D Nevermind. 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"; }


Haiku:

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))

factorial[n_]
:= 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

Mathematica

# Python

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.

# Clojure

(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

• When input is 0, TypeError: reduce() of empty sequence with no initial value Feb 17 '14 at 11:27
• @200_success: 0! = 1 is just a convention ;) Feb 17 '14 at 11:27
• Now it works, but the last line has six syllables. 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