Trying to Start a Programming Meme

I've never tried to start a meme before, but since I don't really have anything great to post about, I'd like to try to start one. I think this one could be particularly fun because it encourages implementation of a basic program in many different languages.

Rules:

  1. Implement a program that takes in a user's name and their age, and prints hello to them once for every year that they have been alive.
  2. Post these rules, the source code for your solution, and the following list (with you included) on your blog.
  3. Bonus points if you implement it in a language not yet seen on the following list!

The List:

  1. [Python] http://www.eflorenzano.com/blog/post/trying-start-programming-meme
  2. [Bash] http://aartemenko.com/texts/bash-meme/
  3. [C] http://dakrauth.com/media/site/text/hello.c
  4. [Java] http://adoleo.com/blog/2008/nov/25/programming-meme/
  5. [Python 3] http://mikewatkins.ca/2008/11/25/hello-meme/
  6. [Ruby] http://stroky.l.googlepages.com/gem
  7. [Ruby] http://im.camronflanders.com/archive/meme/
  8. [Lisp] http://justinlilly.com/blog/2008/nov/25/back-on-the-horse/
  9. [Lua] http://aartemenko.com/texts/lua-hello-meme/
  10. [Functional Python] http://aartemenko.com/texts/python-functional-hello-meme/
  11. [Erlang] http://surfacedepth.blogspot.com/2008/11/erics-programming-meme-in-erlang.html
  12. [Haskell] http://jasonwalsh.us/meme.html
  13. [PHP] http://fitzgeraldsteele.wordpress.com/2008/11/25/memeing-in-php-2/
  14. [Javascript] http://www.taylanpince.com/blog/posts/responding-to-a-programming-meme/
  15. [Single-File Django] http://www.pocketuniverse.ca/archive/2008/november/27/florenzano-factor/

(...and make sure to check out the comments on this post for some other fun implementations!)

And here's my implementation:

name = raw_input('Please enter your name: ')
age = int(raw_input('Please enter your age: '))

for i in xrange(age):
    print "%2d) Hello, %s" % (i, name)

And its output:

Please enter your name: Eric Florenzano
Please enter your age: 22
 0) Hello, Eric Florenzano
 1) Hello, Eric Florenzano
 2) Hello, Eric Florenzano
 3) Hello, Eric Florenzano
 4) Hello, Eric Florenzano
 5) Hello, Eric Florenzano
 6) Hello, Eric Florenzano
 7) Hello, Eric Florenzano
 8) Hello, Eric Florenzano
 9) Hello, Eric Florenzano
10) Hello, Eric Florenzano
11) Hello, Eric Florenzano
12) Hello, Eric Florenzano
13) Hello, Eric Florenzano
14) Hello, Eric Florenzano
15) Hello, Eric Florenzano
16) Hello, Eric Florenzano
17) Hello, Eric Florenzano
18) Hello, Eric Florenzano
19) Hello, Eric Florenzano
20) Hello, Eric Florenzano
21) Hello, Eric Florenzano

Well there you have it, my attempt at a programming meme. I hope someone enjoys it!

53 Comments So Far...

By Alexander Artemenko at 2:37 a.m. on Nov. 25, 2008

My implementation in bash: http://aartemenko.com/texts/bash-meme/

 

By Eric Florenzano at 3:18 a.m. on Nov. 25, 2008

Yay :)

 

By Karsten W. Rohrbach at 6:26 a.m. on Nov. 25, 2008

name = raw_input('Please enter your name: ')
age = int(raw_input('Please enter your age: '))

print '\n'.join(map(lambda x: "%2d) %s"%(x+1, name), xrange(age)))
# ;-)

 

By tasc at 7:12 a.m. on Nov. 25, 2008

print('\n'.join('%d) Hello, %s' % (i, name) for i in range(age)))
;;)

 

By Steven Kryskalla at 7:19 a.m. on Nov. 25, 2008

Python one liner:

>>> print "\n".join((lambda x, y: ["Hello %s %s" % (x,i) for (x,i) in zip([x]*y, range(y))])(raw_input("Name? "), int(raw_input("Age? "))))

 

By Dave K at 7:50 a.m. on Nov. 25, 2008

Oneliners, just because they're easy in Python doesn't make them pythonic.

 

By David Krauth at 8:31 a.m. on Nov. 25, 2008

It's been so long since I've written any C that I had to give it a go:

/* Minimal error checking... */
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
if( argc = 3 ) {
int age = atoi(argv[2]);
if( age > 0) {
int i = 0;
while(i < age) {
printf("%2d) Hello, %s\n", i++, argv[1]);
}
return 0;
}
}
return printf("Usage: %s name age\n", argv[0]);
}

 

By David Krauth at 8:33 a.m. on Nov. 25, 2008

Well, my formatting didn't make it through, perhaps I need to use Markdown next time?

 

By David Krauth at 8:36 a.m. on Nov. 25, 2008

 

By Brandon Konkle at 9:16 a.m. on Nov. 25, 2008

Here's my contribution, my first attempt at a Java program: [The Adoleo Blog| Programming Meme](http://adoleo.com/blog/2008/nov/25/programming-meme/)

 

By Brandon Konkle at 9:17 a.m. on Nov. 25, 2008

Ha! Whoops, I was assuming that Markdown was enabled for the comments. Sorry about that!

 

By Brandon Konkle at 9:18 a.m. on Nov. 25, 2008

I see David Krauth's active link above, though. Does it automatically linkify? I'll try that: http://adoleo.com/blog/2008/nov/25/programming-meme/

 

By Michael Watkins at 9:51 a.m. on Nov. 25, 2008

I submit Python 3 as a separate implementation, as your 2- Python snippet won't run on 3+.

http://mikewatkins.ca/2008/11/25/hello-meme/

Perhaps 3-fying ought to be a meme...

 

By Michael Watkins at 11:01 a.m. on Nov. 25, 2008

PS: I've added a 2+3 compatibility shim to the example so that the same code can run on both.

I've not found a need to litter my code with too many of these "shims". I'm in the process of migrating our code base away from Python 2 and I won't say its painless, but then again I wouldn't say its painful either. In some cases - unicode handling in Python 3 is superior - you get a real reward for your effort.

 

By Eric Florenzano at 12:56 a.m. on Nov. 26, 2008

Hey that's really cool. I must confess I haven't been thinking of 3.0 compatibility yet in writing any of my Python snippets, but with a few small changes it could work in both. Thanks for the comment and post!

 

By stroky.l at 11:08 a.m. on Nov. 25, 2008

I haven't a blog so i make a page with google page creator : http://stroky.l.googlepages.com/gem
i wrote it in ruby and it's no a French gem !

 

By Camron Flanders at 11:44 a.m. on Nov. 25, 2008

here's a smaller, more Ruby - Ruby version:
http://im.camronflanders.com/archive/meme/

 

By Eric Florenzano at 12:51 a.m. on Nov. 26, 2008

Hey Luc! Thanks for posting!

 

By stroky.l at 12:29 p.m. on Nov. 25, 2008

i am a debuting in programming and more in ruby i just read a tuto today. Ruby seems really similar to python

 

By Justin Lilly at 2:14 p.m. on Nov. 25, 2008

Okay, I'm in. Here's a lisp implementation:

http://justinlilly.com/blog/2008/nov/25/back-on-the-horse/

 

By Jeff McNeil at 9:18 p.m. on Nov. 25, 2008

I haven't touched TCL in a while, this sounds like a good reason...

#!/usr/bin/tclsh

if { $argc != 2 } {
puts "Usage: test.tcl name age"
} else {
for {set i 0} {$i < [lindex $argv 1]} {incr i} {
puts "Hello, [lindex $argv 0]"
}
}

I think the last time I used TCL was for some F5 load balancer rules.

 

By Alexander Artemenko at 3:32 a.m. on Nov. 26, 2008

Another meme, this time—in lua: http://aartemenko.com/texts/lua-hello-meme/

 

By Alexander Artemenko at 3:50 a.m. on Nov. 26, 2008

This contest so funny, so I wrote another python version— functional oneliner: http://aartemenko.com/texts/python-functional-hello-meme/

 

By Jordan at 9:18 a.m. on Nov. 26, 2008

Here's the thing in Erlang:

http://surfacedepth.blogspot.com/2008/11/erics-programming-meme-in-erlang.html

Now where's my bonus points?

 

By Jason Walsh at 3:53 p.m. on Nov. 26, 2008

Still learning Haskell, but here was my go.
http://jasonwalsh.us/meme.html

 

By Taylan Pince at 9:22 p.m. on Nov. 26, 2008

I can't believe there is no JavaScript implementation yet! Here is mine:

http://www.taylanpince.com/blog/posts/responding-to-a-programming-meme/

 

By Sam Bull at 2:20 p.m. on Nov. 27, 2008

I decided to nerd out and solve this in a single-file Django project.

http://www.pocketuniverse.ca/archive/2008/november/27/florenzano-factor/

I'm worried the BDFL will see this and cast me out or something, but hey, it was fun!

 

By Eric Florenzano at 3:58 p.m. on Nov. 27, 2008

That is so, so awesome!

 

By Michael Watkins at 5:17 p.m. on Nov. 27, 2008

Inspired by Sam Bull, I've added a "single file" QP web application:

http://mikewatkins.ca/2008/11/27/another-hello-meme-entry/

For a limited time it lives at:

http://mikewatkins.ca:8111/

 

By Helmo at 12:49 a.m. on Nov. 28, 2008

//lol, one cool meme

//C#

using System;
using System.Text;
namespace Meme
{
class Program
{
static void Main()
{
Console.Write("Please enter your name:");
string name = Console.ReadLine();
Console.Write("Please enter your age:");
int age = int.Parse(Console.ReadLine());
for (int i = 1; i <= age; i++)
{
Console.WriteLine("Hello, " + name);
}
}
}

 

By No' at 2:10 a.m. on Dec. 9, 2008

Instead of looping using xrange, you may want to use "string" * "number"...

print "%2d) Hello, %s\n" % (i, name) * age

 

By No' at 2:11 a.m. on Dec. 9, 2008

well... the "%d" variable won't work. But you get the idea.

 

By PiterKokoniz at 10:40 p.m. on April 7, 2009

Hello !!! :)
My name is Piter Kokoniz. Just want to tell, that I like your blog very much!
And want to ask you: will you continue to post in this blog in future?
Sorry for my bad english:)
Thank you!
Your Piter

 

By Eston at 3:42 a.m. on April 14, 2009

Kickin' it old school this time, Eric. It's <strong>QBASIC time.</strong>
<a href="http://www.flickr.com/photos/eston/3441272580/">QBASIC Screenshot</a>

<pre>
' Eric Florenzano's Code Meme in QBASIC
' Eston Bond (socialuxe.com)
' I haven't written anything in this language since elementary school.
CLS
INPUT "What is your name"; n$
INPUT "How old are you"; a
FOR i = 1 TO a
PRINT "Hello, "; n$
NEXT i
END
</pre>

 

By cheapest wow gold at 4:31 a.m. on June 13, 2009

Thx for sharing the exciting info with us.

 

By Single course fee payment at 12:43 a.m. on June 17, 2009

Nice informative post.

 

By Online universities degree at 12:55 a.m. on June 17, 2009

Hey that's really cool.

 

By Get college degree online at 1:54 a.m. on June 17, 2009

I like your blog very much!

 

By Prior learning degree at 1:55 a.m. on June 17, 2009

I think this one could be particularly fun because it encourages implementation of a basic program in many different languages.

 

By Online courses at 1:56 a.m. on June 17, 2009

Thanks a lot for sharing such an valuable stuff.

 

By hitloop at 1:36 p.m. on June 17, 2009

My application in bash:http://aartemenko.com/texts/bash-meme/

 

By Jordan Shoes at 12:43 a.m. on June 20, 2009

good job! thank you very much!

 

By UGG Boots at 12:45 a.m. on June 20, 2009

great! thanks for your sharing!

 

By Nike Shoes at 12:45 a.m. on June 20, 2009

you are really something!

 

By jordan shoes at 12:47 a.m. on June 20, 2009

maybe this one could be particularly fun because it encourages implementation of a basic program in many different languages

 

By injection molding at 12:06 a.m. on June 21, 2009

Thanks Jack!

 

By Lingerie at 8:09 p.m. on June 22, 2009

eric, you did a great job. i know these things aren't easy and take a lot of time. you did great. keep up the excellent work

 

By tiffany jewellery at 12:40 a.m. on June 25, 2009

Thanks a lot for sharing such an valuable stuff.

 

By nike shoes at 11:08 p.m. on June 26, 2009

>>> print "\n".join((lambda x, y: ["Hello %s %s" % (x,i) for (x,i) in zip([x]*y, range(y))])(raw_input("Name? "), int(raw_input("Age? "))))

 

By Stop Dreaming Start Action at 7:11 a.m. on July 2, 2009

Not sure about what you post here. But, it's still informative. Thanks.

 

By Rusli Zainal Sang Visioner at 7:12 a.m. on July 2, 2009

It's great to be able to learn from your blogs and laugh while doing so! Thanks for the info.

 

By hearthomes at 10:05 p.m. on July 3, 2009

 

Voice your opinion...