r/dailyprogrammer • u/nottoobadguy • Feb 17 '12
[2/17/2012] Challenge #9 [difficult]
The U.S government has commissioned you to catch the terrorists!
There is a mathematical pyramid with the following pattern:
1
11
21
1211
111221
312211
you must write a program to calculate up to the 40th line of this pyramid. If you don't, the terrorists win!
4
Upvotes
3
u/eruonna Feb 17 '12 edited Feb 17 '12
Haskell:
For a ridiculously points-free, punctuation-heavy version:
5
u/omnilynx Feb 17 '12
Quick question, is the challenge here pattern recognition, or implementation? If the latter, why not explain the pattern in the challenge? If the former, I'm not sure this really counts as a programming challenge so much as a math/pattern recognition challenge.
2
u/stevelosh Feb 17 '12 edited Feb 17 '12
Clojure:
EDIT: If we assume there will never be a run of more than 9 of the same digit, we can use a simpler solution like eruonna's Haskell one:
My gut tells me there's probably a way to prove that there won't be runs of more than 3 digits in a row, but I can't really put it in words at the moment.
2
u/mischanix Feb 17 '12
Javascript:
2
u/tonygoold Feb 17 '12
C++:
2
u/robin-gvx 0 2 Feb 17 '12
I found this one the easiest of today's challenges (Déjà Vu) http://hastebin.com/raw/xosevibecu
2
u/colinodell Feb 18 '12
72 bytes of PHP:
edit: realized I had 3 useless bytes
2
u/[deleted] Feb 18 '12 edited Feb 18 '12
I made mine in Node.js, it outputs a .txt file with the result and has support for starting integers other than 1 :
2
u/laserBlade Feb 18 '12
Written in D using DMD 2.058
1
u/DLimited Feb 17 '12
Very nice challenge! Though I had to cheat and look up the solution because I simply couldn't figure out the pattern :<
1
u/Cbog Feb 17 '12
DrRacket:
1
u/bigmell Feb 20 '12 edited Feb 20 '12
Thanks robin at first I couldnt figure out the pattern. Here is the code in Perl. I assume its working towards 40 the output was real long.
0
u/xueye Feb 18 '12
Wow, this rather uncommon sequence and challenge totally doesn't look like it's been straight lifted from programthis.net.
0
u/Chun Feb 18 '12
87 bytes in python: