Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

↻ /prog/ Challenge [Vol. λfx.f x] ↻

Name: Anonymous 2011-02-13 12:14

THE CHALLENGE: Write a program that, given a number n, prints the expansion of (a+b)^n.

Example: 4a^4 + 4a^3b + 6a^2b^2 + 4ab^3 + b^4

HOWEVER: You must do the above in a language you do not have any experience with. Never programmed in Haskell before? Gather some documentation and go for it.

(Well, you're advised to do that. I can't possibly know whether or not you know a programming language.)

Name: Anonymous 2011-02-15 13:15


module Binomial where
main=do
    theorem<-readLn::IO Int
    putStrLn $ binomial theorem
    main
cocks=iterate(\cock->zipWith(+)(0:cock)(cock++[0]))[1]
deal n|n==1=""|otherwise=show n
dealer c n|n==0=""|n==1=c|otherwise=c++"^"++show n
dicksort _[]=[]
dicksort _[cock]=[cock]
dicksort dick(cock:cocks)=cock:dick:dicksort dick cocks
toss dick dicks=concat$dicksort dick dicks
binomial n=toss" + "$zipWith3(\cock penis dick->(deal$cock)++(dealer"a"penis)++(dealer"b"dick))(cocks!!n)[n,n-1..0][0..n]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List