Over at Problem of the Day we like to party it up. Since April is coming to a close let's create a program to prepare for all the May birthdays coming up. Today's problem is given a number, generate a party hat that many lines tall. Here is an example with 8:
* *** ***** ******* ********* *********** ************* ***************
Comments:
Tom - 10 years, 8 months ago
a java solution:
reply permalink
Anonymous - 10 years, 8 months ago
In brainf*ck. online interpreter
reply permalink
Jt - 10 years, 8 months ago
Nicely done
reply permalink
Anonymous - 10 years, 8 months ago
reply permalink
Anonymous - 10 years, 8 months ago
Nice little problem for a lazy afternoon. J:
reply permalink
Daniel - 10 years, 8 months ago
I really need to start playing around with J.
reply permalink
Anonymous - 10 years, 8 months ago
It's good fun. I'm in an explainy mood today, so here's the gist of what that J snippet does:
reply permalink
SFF - 10 years, 8 months ago
Not as elegant as the others, but it works.
reply permalink
duddles - 10 years, 8 months ago
in python:
reply permalink
Anonymous - 10 years, 8 months ago
dude why would you add trailing whitespace?
reply permalink
Anonymous - 10 years, 8 months ago
c#
public static void Main() { Console.WriteLine(PartyHat(30)); }
reply permalink
Jt - 10 years, 8 months ago
Trying some C++
reply permalink
Dustin S - 10 years, 8 months ago
Python 2.7
reply permalink
Dustin S - 10 years, 8 months ago
lol, naming issues ^
reply permalink
Will - 10 years, 8 months ago
Yaay more LISP! :D
reply permalink
Samuel Chase - 10 years, 8 months ago
Solution in Common Lisp.
reply permalink
Byron - 10 years, 7 months ago
This might be really bad but I am just learning Python.
print("Please enter the number of rows you would like") rowcount = input(int)
starCount = 1; for x in range(0, int(rowcount)): line = ' ' * (int(rowcount) - int(x)) line += '*' * int(starCount) starCount += 2 print(line)
reply permalink