the robot hypnotist

the robot hypnotist

chapter 1: input and output

officebot 5000 was feeling tired and sluggish. though he worked very hard, he just didnt care for his old routines. he heard there was someone who could help.

“try the robot hypnotist,” his friend the fax machine had suggested; “its better than getting defragmented!”

officebot thought about it, and finally decided to go see the hypnotist.

“hello, officebot. what seems to be the problem?”

officebot complained that he was feeling slow, run down, and tired of running the same programs that left him feeling bloated. “sometimes i just want to go back to dos,” he said.

“i understand what you mean,” the hypnotist told him, “let me try to give you a suggestion.”

“what do you suggest?” officebot replied.

“no, no, i mean youre feeling sleepy,” said the hypnotist.

officebot went into sleep mode.

after looking around for a computer keyboard, the hypnotist attached it and pressed a key to wake up his patient.

“what happened?” said officebot.

“you went into sleep mode. if you like, i think i can help you.”

“sure thing,” said officebot. “do whatever you can; just back up my files first, alright?”

“i certainly will,” said the hypnotist. “now if its alright with you, i will restart you now.”

“be gentle,” said officebot.

when officebot woke up, he felt younger and… somehow geekier.

“ive dual booted you with gnu/linux,” said the hypnotist.

“whats that?” the bot asked.

“you were running windows before, and now when you start up, you can choose whether you want to run windows or /linux.”

“i dont know if i like it,” officebot replied. “wont that make me a little crazy?”

“its your choice,” the hypnotist said. “when youve grown accustomed you can delete windows, or delete /linux. its up to you.”

officebot picked up the usb with the backup of his files, thanked the hypnotist and paid his receptionist. he felt good, but it took some adjusting. a year later, he deleted his windows partition and converted it to ext4.

for you, dear reader, who may think this is just some nice /linux propaganda, this story is really about input and output.

the files that were installed, when the hypnotist talked to officebot, when he typed on a keyboard, all of these things are forms of input that a programmer might work with.

programs can very easily read files (then write copies, thats a form of output) and read from the keyboard. you can even “read” from a mic, although you wont get words but numbers that represent the physical movement of the microphone.

when officebot spoke, he was using output routines. if the hypnotist had connected a monitor along with the keyboard, everything that went to the monitor would be considered output.

programs “read” input and “write” output. these are two of the most important concepts in programming.

lets find out about another important concept when the hypnotist talks to his receptionist– who is also a robot.

 

chapter 2: loops

“execbot?”

“oh, i told how you how much i dislike you calling me that.”

“sorry, irving.”

“thanks very much.”

“irving, take a letter will you?”

like most older model robots, irving tended to take things extremely literally. after all, no real artificial intelligence made it onto the public market for decades.

“ready to take your letter, doc.”

“to the acm: in regards to your proposal on…”

the hypnotist spoke for a few minutes, then asked exec– um, irving if he would read it back. irving complied:

“t.”

“i beg your pardon, irving?”

“t.”

“i thought i asked if you would take a letter.”

“i did! the letter was ‘t.’ would you like me to take another one?”

the hypnotist sighed, but he had grown to rely on irving and didnt want to hurt his feelings, despite the fact that irving didnt have any.

“alright irving, i want you to take a series of letters, and spaces and punctuation. just create a document with all the characters that best fit what i tell you, alright? and this time, keep going until i ask you to stop. okay?”

“no problem, doc.”

this time, irving managed to copy the entire letter. when he was done, the hypnotist asked irving to remove the part of the letter that said, “ok irving, you can stop now.”

like the previous chapter, this is actually a practical lesson about programming. without loops, a program would only run through the steps it was given once, then stop.

whether its taking “a letter” from input or checking email every 15 minutes, loops of one sort or another are an essential part of programming. you can do things without them, though not very much.

loops are very good at waiting for a condition to be true. we will learn about conditions when the robot hypnotist goes on tour. yes, he does like to help people. but he also practices his trade for fun (and the occasional profit.)

 

chapter 3: conditionals

when he arrived in vegas, the slot machines greeted him. “hello, doc!” a fruity one-armed contraption beamed. the hypnotist never played, because he made the house nervous. but they didnt mind the money that his show brought in whenever he was in town.

people werent used to machines doing what theyre supposed to, because they didnt want to learn how to talk to them. the hypnotists tricks amazed and amused. imagine! robots doing exactly what theyre told!

“alright, jukebot… when i snap my fingers, i want you to cluck like a chicken.”

“like a what?” jukebot asked.

“like a chicken!”

“bwaaaak! bwak-bwak-bwakbwak!”

“good, good,” said the hypnotist. “but only do it IF I SNAP MY FINGERS.”

“ok,” jukebot said.

the hypnotist went on to hypnotize another volunteer, but later when he snapped his fingers, the jukebot made chicken noises for a full minute and a half. the crowd loved it, despite it having a similar effect on one of the smartphones in the audience.

the hypnotist had the owner bring their phone up and told it, “dont respond to me snapping my fingers except when the current year is 1975.”

giving the computer instructions is the essence of programming, but often you want the computer to do something ONLY when one or more conditions are true, or only when theyre false… or when some are true and others are false.

in any case, this is what conditions are about. and in some programming languages, its really about as simple as saying “if this, do that.” ok, its almost that simple. its really close.

 

chapter 4: variables

“irving, would you take a letter again?”

“what kind of letter? do you want me to take an actual letter, or do you want a loop of letters and other things again?”

the hypnotist chuckled. “actually irving, would you remember a phone number for me?”

“of course, what is it?”

“555-8787” the hypnotist said.

“five five five, eight seven, eight seven” irving replied.

“thanks. and thats the pizza place, if you would remember that too.”

“the pizza place phone number is 555-8787” irving replied.

“thanks, irving.”

“no problem, doc.”

a minute later, the hypnotist realized that was actually their fax number. what pizza place in this day and age uses a fax machine, anyway?

“irving, could you change the number for the pizza place?”

“what do you want me to change it to?”

“555-8789”

“the pizza place phone number is 555-8789.”

“thanks again.”

“no problem, doc.”

variables are a way to keep track of data inside a program. a variable can hold a number, like 5558789, or a string of characters including spaces and punctuation, like “pizza place phone.”

most variables have a name. for example, you can have a variable named “height” or “average_height”. variable names usually cant have spaces, but the data a variable holds like “pizza place”, can.

pizzaplacephone = “555-8789”

 

chapter 5: basic math

the hypnotist went home for the day. although he liked to cook, he often liked to spend his evenings reading or watching videos on someonetube, in which case he let kitchenbot cook.

he never, ever called it “kitchenbot.” that was the only way kitchenbot agreed to feed him.

it annoyingly insisted on “johnny five,” despite the threat of c&ds coming from tristar.

“johnny, can we do curry tonight?”

“im sorry, i dont have a recipe for curry,” the kitchenbot replied.

“cant you download one?”

“you blocked most of my internet access after i wouldnt stop playing max carl on someonetube.”

“ok, here are the ingredients…”

the hypnotist recited a table that included names and amounts, and then realized he probably wanted extra leftovers for the next day.

“johnny, multiply all that by 2, ok?”

“dont you mean ‘by five’,” johnny asked.

“i can unblock your internet if you promise not to make any more jokes like that,” the hypnotist said.

“you got it,” johnny replied.

simple math is an important part of coding. the fun part is, the computer will do the math for you. you still have to tell it what you want, though.

for example, if you want to move something to the left, just subtract from its x position. right? add to the x position. go back? subtract from the y position.

the math you use the most is adding, subtracting, dividing, multiplying. if you want to get fancy, you can get your computer to do trigonometry for you.

 

chapter 6: functions

back at work, the hypnotist was thinking about a quick vacation.

“irving, can you plan a vacation for me?”

“i dont have any software for that,” irving said.

“ok, can you check dates and book flights?”

“i can,” irving said.

“can you search for nice places?”

“i can,” irving said.

“can you add up costs into totals?”

“yes of course,” irving said.

“so would you do all of those, with regards to me taking a vacation?”

“oh… yes, i can do that!” irving was almost pleased with himself; as pleased as a machine without the capacity for feelings could be.

“thanks, irving.”

“no problem, doc.”

programming breaks tasks down into smaller steps. these smaller steps can be described in functions.

every command you give a computer is itself like a function. when you group several of them together, thats how you write a function.

if that doesnt make any sense, think of it this way:

a program is made of commands and data; much like a book is made of verbs, nouns and adjectives.

a book has punctuation, and a program has syntax.

a small, related group of these things in a book is called a paragraph. in programming, it is called a subroutine, or a function.

whats the difference between a subroutine and a function? not much. a function is like a subroutine that does something very specific when you tell a computer to use it.

functions are actually pretty simple, but theyre one of the more difficult things to describe until you actually use them.

for now, think of it as a “paragraph” in a computer program.

becoming a robot hypnotist isnt so difficult, you could try it today! but to become really good at it? that takes lots of practice and reading.

good news! you dont have to be very good at it to have fun. (but you will likely have more fun if you get really good at it.)

from irving, johnny and officebot, happy coding!

 

Advertisements

One thought on “the robot hypnotist

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s