Programming The Robot from Diary of a Wimpy Kid
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Programming The Robot from Diary of a Wimpy Kid

My daughter Lily has been reading her first ever novel, ' Diary of a Wimpy Kid' (recommended by Joe Cooney) and one part of the book led her to do some programming with me. Yay for reading! Yay for programming! and yay for my daughter!

Here's the story that inspired her:

We got to work. Someone had the idea that you can say your name to the robot and it can say it back to you.

Robot says "Hi BOB it is very nice to meet you BOB."

But then someone else pointed out that you shouldn't be able to use bad words for your name, because the robot shouldn't be able to curse. So we decided we should come up with a list of all the bad words the robot shouldn't be able to say.

We came up with all the regular bad words, but then Ricky Fisher came up with twenty more the rest of us had never even heard before.

So Ricky ended up being one of the most valuable contributors on this project.

Right before the bell rang, Mr Darnell came back in the room to check on our progress. He picked up the piece of paper we were writing on and read it over.

Mr Darnell looks over the piece of paper

To cut a long story short, Independent Study is cancelled for the rest of the year.

Diary of Wimpy Kid, Jeff Kinney

I said to Lily we could make a program like that and—get this—she was actually excited about the idea. So we sat down together and made a program. I asked for her help with every bit of it. Here is how it went:

namespace feedback
{
    using System;
    using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello.");

            while (true)
            {
                Console.WriteLine("What is your name?");
                var name = Console.ReadLine();
                Console.WriteLine("Hi " + name + " it is very nice to meet you " + name + ".");
            }
        }
    }
}

Next we put in a secret codeword, 'Exit' that you could use when you want to stop.

if (name == "exit")
{
    break;
}

And then a secret codeword so if it recognised you it would change color:

if (name == "Lily")
{
    Console.ForegroundColor = ConsoleColor.Magenta;
}
else
{
    Console.ResetColor(); 
}

Lily said we could make it say your name backwards! So I tried this...

var backwardsName = name.Reverse();
Console.WriteLine("Hello " + backwardsName);

But instead of printing the name backwards, this printed...

Hello System.Linq.Enumerable+<ReverseIterator>‌d__a0`1[System.Char]

Try explaining THAT to a 6 year old.

It was easier to do it like this:

var backwardsName = "";

foreach (var letter in name)
{
    backwardsName = letter + backwardsName;
}

Console.WriteLine("Hello " + backwardsName);

That worked much better.

Now Lily had an even better idea. What if the robot said a different word for every letter of their name.

My work friends will know that Phonetic Alphabets are something we play with quite a bit, in order to make dealing with IT support easier. But Lily independently came up with this idea, without any prompting from me.

So if you're name is Leon it would say "Hello Lemon-Echo-Octopus-Nose". Or words to that effect.

                var wordyName = "";
                foreach (var letter in name.ToUpperInvariant())
                {
                    letterNumber = Convert.ToInt32(letter) - 65;
                    if (letterNumber >= 0 && letterNumber < AlphabetWords.Length)
                    {
                        wordyName += AlphabetWords[letterNumber] + " ";
                    }
                }
                
                Console.WriteLine("Hello " + WordyName);

And this relied on coming up with a big alphabetic list of words. We had fun doing this together.

static string[] AlphabetWords = { 
    "Apple",
    "Bunya-Mountains",
    "Custard",
    "Dirt",
    "Eyeball",
    "Funny",
    "Gorilla-Gnome",
    "Hexaphone",
    "Igloo",
    "Jellybean",
    "Kitten",
    "Lolly",
    "Monkey",
    "NO!!!!",
    "Octopus",
    "Penny",
    "Queen",
    "Rhino",
    "Sugar",
    "Trickster",
    "Up",
    "Viking",
    "Warrior",
    "Xray-fish",
    "Yucky",
    "Zebra"};

Well, there it is. And a big thumbs up to Jeff Kinney for teaching people from an early age that user input is not to be trusted.





'Rich' on Tue, 07 Jan 2014 02:33:25 GMT, sez:

I recently did something very similar with my 6 year old son - coincidentally, also a fan of those books.

The fun levels went even higher when we made the computer actually speak the responses.

We used a Mac (with the built in 'say' command), but I'm sure there is an equivalent for Windows users too.



'System.Linq.Enumerable+<ReverseIterator>d__a0`1[System.Char]' on Wed, 08 Jan 2014 02:12:10 GMT, sez:

You called?




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. Incivility is not tolerated, such comments are deleted.

 

I'm the co-author of TimeSnapper, a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

I wrote this, and use it every day for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. You should use NimbleText, you handsome devil!

 

Articles

The Canine Pyramid The Canine Pyramid
Humans: A Tragedy. Humans: A Tragedy.
ACK! ACK!
OfficeQuest... Gamification for the Office Suite OfficeQuest... Gamification for the Office Suite
New product launch: NimbleSET New product launch: NimbleSET
Programming The Robot from Diary of a Wimpy Kid Programming The Robot from Diary of a Wimpy Kid
Happy new year 2014 Happy new year 2014
Downtime as a service Downtime as a service
The Shape of Your Irrationality The Shape of Your Irrationality
This is why I don't go to nice restaurants any more. This is why I don't go to nice restaurants any more.
A flowchart of what programmers do at work all day A flowchart of what programmers do at work all day
The Telepresent Man. The Telepresent Man.
Interview with an Ex-Microsoftie. Interview with an Ex-Microsoftie.
CRUMBS! Commandline navigation tool for Powershell CRUMBS! Commandline navigation tool for Powershell
Little tool for making Amazon affiliate links Little tool for making Amazon affiliate links
Extracting a Trello board as markdown Extracting a Trello board as markdown
hgs: Manage Lots of Mercurial Projects Simultaneously hgs: Manage Lots of Mercurial Projects Simultaneously
You Must Get It! You Must Get It!
AddDays: A Very Simple Date Calculator AddDays: A Very Simple Date Calculator
Google caught in a lie. Google caught in a lie.
NimbleText 2.0: More Than Twice The Price! NimbleText 2.0: More Than Twice The Price!
A Computer Simulation of Creative Work, or 'How To Get Nothing Done' A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown! NimbleText 1.9 -- BoomTown!
Line Endings. Line Endings.
**This** is how you pivot **This** is how you pivot
Art of the command-line helper Art of the command-line helper
Go and read a book. Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator The 'Should I automate it?' Calculator

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker



[powered by Google] 

How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

InfoText - amazing search for SharePoint
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
Aussie Bushwalking
BrisParks :: best parks for kids in brisbane
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2012 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy