Coder Poetry
Decipher the encoded well-known sayings, songs, nursery rhymes, stories, etc.
Dizzy Animals
April 14, 2012
Posted by on Some nursery rhymes make no sense in our modern language. And sometimes there are several different “histories” as to what the rhyme originally meant. I wonder how multiple histories come into being? I’d like to know the history of why multiple histories exist; the “meta-history.”
Today’s rhyme is one of those whose history seems clouded.
Enjoy it in Java. (Maybe that’s why the monkey thought it was fun: he drank too much Java.)
Worker cobbler = new Worker(); cobbler.setJob(Job.REPAIR); cobbler.setDirectObject("Shoes"); Workbench bench = new Workbench(); cobbler.setWorkArea(bench); Animal weasel = new Weasel(); Animal monkey = new Monkey(); for (int i = 0; i < SOME_BIG_NUMBER; i++) { weasel.runAround(bench); monkey.runAround(bench); } Mood fun = new Mood("Fun"); monkey.feel(fun); Noise pop = new Noise("Pop!"); weasel.makeNoise(pop);
Hey, for a funny comic routine about this and other nursery rhymes, check out Tim Hawkins!
Translation |
---|
All around the cobbler’s Bench The monkey chased the weasel. The monkey thought it all in fun, Pop, goes the weasel. Read about some different explanations here and here. I didn’t know about all the different versions of this rhyme. I chose to implement the alternative lyrics #5 mentioned at the first link, because I think that’s the way I heard it as a kid. Although I’m not sure if it was a cobbler’s bench or a mulberry bush. Pretty sure I heard it as a cobbler’s bench. Maybe the cobbler’s bench was made out of mulberry wood. |
Nice Weather!
March 24, 2012
Posted by on We’ve sure been having good weather here lately. I’m excited for Spring and summer! The sunny outdoors makes me feel carefree.
And here’s just the song for it, Java style.
void rain(Raindrop[] raindrops, Object location) { for (Raindrop raindrop : raindrops) { raindrop.fall(location); } } Raindrop[] raindrops = new Raindrop[LOTS]; for (int i = 0; i < LOTS; i++) { raindrops[i] = new Raindrop(); } Person me = new Person(); Person guy = new Person(); Sun sun = new Sun(); Bed bed = new Bed(); rain(raindrops, me.getHead()); if (guy.getFeet().getSize() > bed.getFeetSize()) { System.out.println("Nothin' seems to fit"); } rain(raindrops, me.getHead()); me.sendMessage(sun, "I don't like the way you get things done."); me.sendMessage(sun, "You're sleeping on the job."); rain(raindrops, me.getHead()); Calendar now = Calendar.getInstance(); me.know(new Knowable() { public void know() { for (Raindrop raindrop : raindrops) { Mood mood = raindrop.getMood(); // will always be Mood.BLUE int moodStrength = me.sendMoodToMeet(mood, cal.getTime()); me.setStrength(moodStrength + 1); // won't defeat me! } now.add(Calendar.MINUTE, 5); me.sendMoodToMeet(Mood.HAPPINESS, now); } }); rain(raindrops, me.getHead()); me.getEyes().getPossibleColors().remove(Color.RED); me.getEyes().setCryingPossibility(0); if (me.complain() || !me.complain()) { rain(raindrops, me.getHead()); } me.setFree(true); me.setWorryObject(null); me.sendMoodToMeet(Mood.HAPPINESS, now); rain(raindrops, me.getHead()); me.getEyes().getPossibleColors().remove(Color.RED); me.getEyes().setCryingPossibility(0); if (me.complain() || !me.complain()) { rain(raindrops, me.getHead()); } me.setFree(true); me.setWorryObject(null);
Translation |
---|
“Raindrops Keep Falling on My Head”
by B.J. Thomas You can read the lyrics and watch him sing it on STLyrics. |
A friend of Saint Patrick
March 17, 2012
Posted by on Today is St. Patrick’s Day. I wanted to do a really easy one today. (That is, easy for me to write!) So here’s about a whole 5 minutes worth of effort!
Dictionary<Color, Difficulty> colorDifficulties = new Dictionary<Color, Difficulty>(); colorDifficulties.Add(Color.Red, Difficulty.Easy); colorDifficulties.Add(Color.Blue, Difficulty.Easy); colorDifficulties.Add(Color.Yellow, Difficulty.Easy); colorDifficulties.Add(Color.Green, Difficulty.Hard);
Translation |
---|
“It’s not easy being green.”
– Kermit the Frog |
Good Luck
March 14, 2012
Posted by on This one is for Saint Patrick’s Day!
And to bring in something to resemble a pot o’ gold and gems, the closest I came is to writing it in Ruby! It felt appropriate. You can “bundle” in other “gems” as you wish. 😉
module LeafOne def theme_one 'sunshine' end end module LeafTwo def theme_two 'rain' end end module LeafThree def theme_three 'roses that grow in the lane' end end module LeafFour def theme_four @explanation = nil 'somebody I adore' end end class Clover include LeafOne include LeafTwo include LeafThree include LeafFour end class Person def self.actions clover = Clover.new overlook clover look_over clover end end
Translation |
---|
“I’m Looking Over a Four-leaf Clover”
Information from Clover Specialty Company: Words: Mort Dixon See the above link for the lyrics. Read even more about it on Wikipedia |
Sidenote: I remember having to sing this song to try out for the school play sometime between 4th and 6th grade.
Animals, animals, animals
March 5, 2012
Posted by on So interesting that so many well-known sayings/songs/nursery rhymes are about animals.
Today we’ve got a whole bunch of animals!
Today’s post is also in response to a couple “helpful” comments from friends: “It should compile,” and “the last post was weak.”
Really? This is art. That mean’s there’s poetic license (doesn’t have to compile), and not every post can be a novel or at an advanced level, right?!
I know this post compiles (“worked on my machine”), and it’s a little longer and more complex than the last one. You could even add your own verses, if you want!
Thanks to the MSDN Library and all the posters in this Stack Overflow question for the help I needed in a couple spots.
abstract class Animal { public Animal(string sound) { this.Sound = sound; } public string Sound { get; private set; } } class Cow : Animal { public Cow() : base("Moo") { } } class Dog : Animal { public Dog() : base("Woof") { } } class Chicken : Animal { public Chicken() : base("Cluck") { } } class Pig : Animal { public Pig() : base("Grunt") { } } class Horse : Animal { public Horse() : base("Neigh") { } } class Goat : Animal { public Goat() : base("Bleat") { } } class Duck : Animal { public Duck() : base("Quack") { } } class Llama : Animal { public Llama() : base("Growl") { } } class Farm { List<Animal> animals; public Farm(string farmerName, string farmerExclamation) { this.FarmerName = farmerName; this.FarmerExclamation = farmerExclamation; animals = (from type in Assembly.GetExecutingAssembly().GetTypes() where !type.IsAbstract && type.IsSubclassOf(typeof(Animal)) select (Animal)Activator.CreateInstance(type, null) ).ToList(); } public string FarmerName { get; private set; } public string FarmerExclamation { get; private set; } public override string ToString() { string summary = string.Format("{0} had a farm, {1}", FarmerName, FarmerExclamation); StringBuilder output = new StringBuilder(); foreach (Animal animal in animals) { output.AppendLine(summary) .AppendFormat("And on that farm he had a {0}, {1}", animal.GetType().Name, FarmerExclamation) .AppendLine() .AppendFormat("With a {0} {0} here and a {0} {0} there", animal.Sound) .AppendLine() .AppendFormat("Here a {0}, there a {0}, everywhere a {0} {0}", animal.Sound) .AppendLine() .AppendLine(summary) .AppendLine(); } return output.ToString(); } } class Program { static void Main() { Farm farm = new Farm("Old McDonald", string.Format("{0}-{1}-{0}-{1}-{2}", 'E', 'I', 'O')); Console.Write(farm.ToString()); } }
Translation |
---|
The “Old McDonald Had a Farm” song.
Read all about it here. AND, get ideas of animals to add for your own verses here! |
Under control
March 3, 2012
Posted by on While we’re on birds, this one is maybe a little more subtle, but simple.
It’s SQL (Microsoft-flavor).
CREATE TABLE Ducks ( Duck1 VARCHAR(20) , Duck2 VARCHAR(20) , Duck3 VARCHAR(20) , Duck4 VARCHAR(20) , Duck5 VARCHAR(20) ) INSERT INTO Ducks (Duck1, Duck2, Duck3, Duck4, Duck5) VALUES ('Donald Duck', 'Daffy Duck', 'Duck Tape', 'Rubber Ducky', 'Platypus Duck') SELECT * FROM Ducks
Translation |
---|
Get your ducks in a row.
Meaning and possible origins discussed at wiseGEEK. |
Keep what you have
February 27, 2012
Posted by on Another well known but seldom used saying. Two languages this time.
Bash:
mkdir hand mkdir bush echo "******" > hand/bird echo "***" > bush/bird1 echo "***" > bush/bird2 cat bush/bird1 bush/bird2 > bush/bothbirds birdinhandsize=$( cat hand/bird | wc -c ) birdsinbushsize=$( cat bush/bothbirds | wc -c ) if [ $birdinhandsize -eq $birdsinbushsize ]; then echo "Yep, they were right!" else echo "Wow, they were wrong all along!" fi
C#:
Location hand = new Location(); Location bush = new Location(); Bird b1 = Â Â Â new Bird() Â Â Â { Â Â Â Â Â Â Â Location = hand, Â Â Â Â Â Â Â Value = 6 Â Â Â }; Bird b2 = Â Â Â new Bird() Â Â Â { Â Â Â Â Â Â Â Location = bush, Â Â Â Â Â Â Â Value = 3 Â Â Â }; Bird b3 = Â Â Â new Bird() Â Â Â { Â Â Â Â Â Â Â Location = bush, Â Â Â Â Â Â Â Value = 3 Â Â Â };
Translation |
---|
A bird in the hand is worth two in the bush. Learn more about this phrase here. Thanks to jlinkels’ post here for a good way to count characters in a file. |
Needlework
February 23, 2012
Posted by on We use or hear some common phrases enough that they become part of our common speach. We may or may not know the phrase’s true meaning or its origin, yet the phrase is common to us. The phrase represented by the Java code below is definitely one I’d call “common,” even though it’s something I never say, and I never hear anyone else say it. Weird. I wonder where I learned it, then?!
Stitch(); Date doneTime = new Date(); if (doneTime.compareTo(SAFE_TIME) > 0) { Â Â Â for (int i = 0; i < 9; i++) { Â Â Â Â Â Â Â Stitch(); Â Â Â } }
Translation |
---|
A stitch in time saves nine.
Read about it here. |
Get out of the rain
February 22, 2012
Posted by on This one probably isn’t too hard to recognize.
It’s fun to try to figure out the best way in code to represent different things. Here it was a little of a challenge to find the best way to show the change in location of the animals involved.
public void MarchingSong() { string[] actions = { "suck", "tie", "climb", "shut", "take", "pick up", "pray to", "shut", "check", "say" }; string[] directObjects = { "thumb", "shoe", "tree", "door", "dive", "sticks", "heaven", "gate", "time", "the end!" }; Place belowGround = new Place() { Weather = "Dry" }; Place onGround = new Place() { Weather = "Wet" }; Place sky = new Place() { Weather = "Raining" }; Stack<Place> environment = new Stack<Place>(); environment.Push(belowGround); environment.Push(onGround); environment.Push(sky); for (int cnt = 1; cnt <= 10; cnt++) { Ant littleOne = null; Ant[,] ants = new Ant[cnt, cnt]; for (int x = 0; x < cnt; x++) { for (int y = 0; y < cnt; y++) { ants[x, y] = new Ant() { Size = Ant.GetRandomSize(), Place = onGround }; if (littleOne == null || ants[x, y].Size < littleOne.Size) { littleOne = ants[x, y]; } } } for (int z = 0; z < 2; z++) { AllAntsDo(ants, cnt, (ant) => ant.March()); AllAntsDo(ants, cnt, (ant) => ant.DoSomething("shout", "Hurrah! Hurrah!")); } AllAntsDo(ants, cnt, (ant) => ant.March()); littleOne.Stop(); littleOne.DoSomething(actions[cnt - 1], directObjects[cnt - 1]); AllAntsDo(ants, cnt, (ant) => { ant.March(); ant.Place = belowGround; // (get out of the rain) }); AllAntsDo(ants, cnt, (ant) => ant.DoSomething("shout", "Boom, Boom, Boom!"); } } private void AllAntsDo(Ant[,] ants, int dimension, Action<Ant> action) { for (int x = 0; x < dimension; x++) { for (int y = 0; y < dimension; y++) { action(ants[x, y]); } } }
Translation |
---|
“The Ants Go Marching” song, by Robert D. Singleton.
This is one of those songs that everyone just seems to know somehow. Part of our collective consciousness, like Boomdeyada and “I Know an Old Lady.” Hmm… there’s some ideas for future posts…! The song lyrics can be found here. |