Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Tuesday, February 20, 2018

What is your function? More excuses to delay bedtime


J1 (5th grader, looking for an excuse to stay up): What are you working on?

J0: I'm writing a review of a book.

J1: The one we got from math circle (Martin Gardner's Perplexing Puzzlers and Tantalizing Teasers)? 

J0: No, the one about Funvillians.


From Natural Math!


J1: Tell them that it was fun!

J0: You really enjoyed reading it. I'll make sure to mention that. I was thinking that we should have used it as an inspiration to make our own adventures.

J1: You mean, like creating new characters with their own powers? We could have heroes who control fire and ice, some others that can go forward and backward in time.

J0: Is that how the Funvillian powers worked? I thought they needed to have inputs. For example Marge's power only works on two exactly identical objects.

J1: Sure, the current time is an input and the output is the time in 5 minutes. Or another one can do the reverse.

[pause, maybe he's starting to go to sleep?]
J1: Or... maybe we could make up some adventures where the Funvillians from the story have to solve their own challenges.  They could meet some villains... not Villians! (laughing)

J1: The one who can duplicate things ... what if that power could be used on people? After they were copied, would they all have to do the same things? For example, if I were copied and I raised my arm, would the other one have to raise his arm, too? Could they think different thoughts?

J0: Well, when they copied two toys, they could play with the toys separately. The toys didn't have to do identical things.

J1: Oh! But what if they were changed a tiny amount? Would they still be considered identical and could they get reduced down to one copy?

J0: I don't know. Where do you think the powers come from?

J1: maybe from living in their magical land. Probably when they have spent enough time there, a power develops.

J0: There, so that's what I'm going to write about. Thanks!

J1: Remember to tell them it was fun!


On Fridays for the last several months, my fifth grader and I have been spending 2 hours in the evening doing math together. By that time of the week, I'm not always feeling energetic enough to properly plan an activity or exploration. Looking to give myself a break, last week, I brought Sasha Fradkin's book Funville Adventures for J1 to read during the session.

He was engrossed and finished it with some amount of time to spare. Maybe 90 minutes of reading, leaving us 30 minutes to discuss.  He had read the addendum, so was already primed for talking about functions. In addition, he still remembered past conversations about "function machines" and programming functions. Using the characters as references, though, he found it much more intuitive to understand invertible and non-invertible functions. We talked about examples of arithmetic functions that were similar to different characters' powers and had fun giving examples of what would happen if different characters used their powers in succession.

The experience, so far, suggests that this is a helpful model for understanding functions, more human and vivid than what we'd previously done with function machines.

And remember, it was fun!
(now go to bed!)

Monday, March 9, 2015

Projects: Finale (programming class 18)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

This was our last class of the term, so we spent the time working on finishing the projects.
For each project, there are many potential extensions, but everyone has made a complete program (or very, very nearly complete).

Programs can all be found here: Class Projects.

Plan of work today:
  • Titus: (1) instructions for the game (2) webcam version?
  • Win: (1) correct flow, (2) add fractions?
  • Boongie: (1) how do players win? (2) is the penalty condition working the way you want?
  • Gun: (1) penalty for hitting the walls, (2) winning condition, (3) finish maze 

Monday, February 23, 2015

Send me a message and projects 3 (programming class 17)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Reminder, this is our standard lesson plan for the rest of the term:
  1. New or review concepts
  2. Exercises related to the projects
  3. Project work

New/Review

Today, we had three new concepts: while loops, objects, and message passing. This was clearly too much for everyone to understand everything, so I focused on the while loops. My reason for introducing the other ideas and short programs was to give Titus some tools for his project.
These exercises and discussions were based on these two programs from the pencilcode guide:
While
Talking about while gave a natural opportunity to talk about for again. We had two segments to the conversation, first comparing while vs for, then deciding which is best for different scenarios.
  • Do you know how many iterations you want, before you start to loop? If so, use a for loop, if not, while.
  • Eating: while hungry, eat. If you use a for loop, you may either still be hungry or explode!
  • brushing teeth: while mouth feels dirty, brush your teeth.
  • Putting on socks: for [1..2] put on a sock
  • Cleaning vegetables for stir fry: while veggie bowl has food, clean and chop veggies
  • Adding eggs to a cake: for [1..numEggs], crack an egg and add it to your wet ingredients
  • etc 
This was a really good conversation as each kid had a chance to think about the funny outcome if you used a for when while was more sensible.

Shared Memory
We didn't talk extensively about the concept of an object. Like while/for, objects would pair naturally with arrays, but we also haven't talked a lot about them. For now, the kids should understand that the object is something like a chest of drawers with the drawers given their own names.

As our exercise, we extended the pencilcode guide program to use a button and add an extra value to create this program where the turtle's angle of rotation is entered through the input boxes and the distance moved each step is increased by the button:

Message Passing
Like shared memory,we didn't spend a lot of time on this new concept. However, inspired by Kan wondering why the program stopped responding to his button clicks, we slightly modified the guide program to use a while loop instead of the for loop. Our version is here.

Project exercises

Next week, I will focus the practice/exercises/review on concepts we've learned that are being used in the projects.

Projects and homework

As a reminder, I have stored copies of their work up to the start of today's class in this folder: Project Directory. The homework this week:
  • Kan: finish drawing his maze. Next module is to decide what penalty he wants when the turtle runs into the wall. This is the same assignment as last week. Unfortunately, he overwrote his maze drawing program sometime during the week.
  • Boongie. implement the penalty when the turtle runs into the wall, the turtle bounces back to a previous shell in the maze. There are several ways to do this and I'm curious to see his approach.
  • Win: create functions to ask subtraction, multiplication, and division questions. Another area to think about are gradations in how hard the questions are.
  • Titus: Use the shared memory and message passing code ideas we learned about today to check to see if the player chooses a match.

Monday, February 16, 2015

Functions review and projects 2 (programming class 16)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Reminder, this is our standard lesson plan for the rest of the term:
  1. New or review concepts: For loops, functions, if statements. Often, this will be integrated with the exercises.
  2. Exercises related to the projects
  3. Project work

New/Review

The new concept today was the random function. We played with three snippets of code to understand how this works and, of course, keep practicing for loops:

  1. Generate 4 random integers between 1 and 10 (inclusive)
  2. Modify the previous program to multiple your random numbers by 10
  3. Change the first program to generate numbers in [10, 100]
We had a good discussion about these programs: first identifying the ranges for possible values, then drawing Venn diagrams and talking about intersections and subsets. This opportunity to talk about additional math concepts is one of the extra dividends from the programming class.

Using the random function has many applications for games. In the projects this term, I expect that Kan and Boongie will use it to help create new mazes each time the program is run, Win will use it to generate a new set of math questions, and Titus will use it to shuffle the picture cards.

For our review, I wanted to reinforce the ideas related to functions. In one of our last sessions, we realized that the kids didn't really understand function definitions, calls, and variables. This time, i gave them three code snippets:

  • Define hypotenuseStep1(a, b) = a+b
  • Define hypotenuseStep2(a,b) = a*a + b*b
  • Define hypotenuseFinal(a,b) = sqrt(a*a+b*b)
I wanted to see if they could figure out how to call the function and whether they would do anything with the output. After many interesting attempts, we went through the details again and explained how the components work. In retrospect, I should have given them a function that would generate visual output once called. As it was, they needed to get two things right (call the function correctly and write the output) in order to get positive feedback.

Project Exercises

As noted above, the exercises on random have several potential applications in the projects. The other exercise today was most directly related to Win's project. We combined for loops, random, and write statements to loop through some math statements.

Here are some ideas for future project exercises, particularly using functions:
(1) reset/restart the game
(2) B: draw random gaps in circles for maze
(3) Gan: maybe randomize drawing of maze, depends on how he plans to structure the maze
(4) T: check to see if chosen cards match the next picture symbol

Projects and homework

The students are all making reasonable progress on their projects. I have stored copies of their work up to the start of today's class in this folder: Project Directory. The homework this week:

  • Kan: finish drawing his maze. Next module is to decide what penalty he wants when the turtle runs into the wall.
  • Boongie. implement the penalty when the turtle runs into the wall, the turtle bounces back to a previous shell in the maze. There are several ways to do this and I'm curious to see his approach.
  • Win: create a looping function so that they get a second chance for an incorrect answer. Next module is to think about gradations in how hard the questions are.
  • Titus: arrange the memory cards into a grid, randomize each time the game is played, if possible. Next module is to think about how to check to see if the player chooses a match. 


Sunday, February 8, 2015

Magic Cards (programming 15, projects 1)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Today, we began to focus on the projects for this term. These are the kids project ideas:
  • Gun and Boongie are both making mazes
  • Win is making a math worksheet game to quiz the younger students in arithmetic
  • Titus is making a version of the memory match game
We plan to follow this agenda for the rest of the term:
  1. New or review concepts
  2. Exercises related to the projects
  3. Project work

New/Review

Today, we integrated this activity with the project exercises. For the future sessions, the three concepts we want to keep discussing are:
  • For loops: the kids are close to mastering these
  • Functions: still some confusion about the essential features, function calls and arguments
  • If statements: introduced this week, but will take more discussion.

Project Exercises

These exercises have several objectives. First, I want to help the students with their projects. Each exercise has at least one idea that can be used directly, or with small modification, in someone's project.

Second, I wanted them to really understand the concepts in the exercises. This group does best when they have a mix of experimentation, discussion, and explanation. Short snippets of code serve very well to catalyze these. It is also very useful to have them work on some material in common. In particular, during the experimentation, it is nearly guaranteed that at least one of the students will do something that nicely illustrates a critical aspect of the idea they are learning.

Third, I wanted to continue to make sure that everyone would have exposure to the interesting ideas in each project.

Here are student examples of the three exercises:
Clicking done by Boongie

If...Else done by Win

Forever and Turn done by Titus

Project Work

Boongie focused his time on drawing his maze. Gun tried to figure out a way to block the turtle from going through the barriers once he has drawn his maze. Win expanded the if-else pattern from the exercises, introducing variables to his write statements and random values. Titus added mini pictures to the outside of his memory game playing area.

Homework

For the most part, each student has different homework based on their project.
  • Gun and Boongie: draw the outline of the mazes
  • Win: work on how to respond when the player enters an incorrect answer and think about how to loop for multiple questions.
  • Titus: fill out the pictures on the boundary circle

Monday, January 26, 2015

Creepy Eyes (programming class 14)

Who: Baan Pathomtham Grade 5
Where: at school
when: Monday morning for 2 hours

Note: These activities were based on this program I found in the pencilcode activity directory: Son of Eyes. This was a very productive class because it helped tease out many misconceptions about functions and variables.

Homework Discussion

Reviewing the students' accounts this weekend, I saw some programs written for geometry (great!) but no more progress on the function machines and nothing that indicated they had thought about their projects for this term. As a result, we did not discuss homework today ;-<

Simple Function

The first challenge was to figure out what this program does:
makeeye = (x, y) ->
    b = new Sprite
    drawon b
    dot black, 30
    dot white, 28
    fd 7
    dot limegreen, 14
    b.clip()
    home()
    drawon window
    b.moveto x, y
    forever ->
        b.turnto lastmouse
makeeye -1, 45
ht() 
As usual, reproducing the program and watching it perform was an acceptable strategy. Through the course of this warm-up, we had a chance to review a lot of the mechanics of writing programs, particularly the use of spacing Coffeescript/pencilcode.

Creepy functions and power loops

As a next version, I gave them a suggestion to integrate this code snippet into their earlier program:
for [0...10]    x = random [-200..200]
    y = random [-200..200]
For the most part, they understood what the loop was doing and were comfortable with that piece. However, integrating it with the makeeyes function proved to be a significant challenge and was really helpful for showing that none of the students yet understand the structure of a function. Essentially, no one knew how to run the function again or to run it with new input variables. We stopped the experimenting and talked about the key components of a function:
  1. Name and definition
  2. Input variables
  3. Body
  4. function call: function name and inputs
After this discussion, they seemed to be clearer about how functions work, but we will need to review again at least one more time.

A funny surprise

I showed the students one version I made of the creepy eyes program. Gun was the first to test it out. I encourage you to try it out several times with different input variables. See if you can find the little surprise I included for one of our precocious learners.

Homework

This term, we want each of the students to work on a project of their own. The homework this week is to write out a detailed description of the project they want to develop. As no one had previously thought about potential projects, we gave them the following categories as suggestions:
  • A game: there are many types, including animated games, text-based games, playing against a computer or against a friend, etc
  • An animation or a movie
  • A drawing (for example, an animal or plant they've learned from Ajarn Wachara)
  • A tool to explain some mathematics to the younger students

Sunday, December 14, 2014

Our function machines (programming class 13)

who: Baan Pathomtham Grade 5 class
where: at school
when: Monday morning (bright and early!)

Ah, lucky number 13.

Homework discussion

We started by trying to figure out Titus's function machine.  This was a good continuation of our function game last time as he didn't have a chance to present a mystery function. Why don't you have a go:

Here is a link to his function machine so you can test more inputs.

While examining the output of the function S, we noticed that the results often included a repeating decimal.  For example, putting 5 into the machine gives us 12.142857142857142 (which should continue, up to the precision of the computer's calculation). This gave us a chance for a short conversation about repeating decimals and rational numbers.

I'd note that figuring out the underlying function was quite hard for the kids.

We then talked about where the other three got stuck on the homework and then spent the rest of the class helping them work through different associated issues.

The four function machines

Eventually, everyone got their function machines working, at least to the level of taking an input and giving us an output. Of course, Titus's is linked above. He is working on extensions, particularly making a loop.

Here is Gun's:
 
Boongie's:

and Win's:


My function machine

As an example with some extra functionality, I showed them my function machine. At first, we entered numbers as input and it seemed pretty silly.  Then, they got a surprise when they tried something else:

Homework

The kids have two homework assignments:
  1. Extend their function machines to incorporate functionality from my program fctMchn_2.  Example extensions: add a loop so the user can try multiple inputs, animate the input and output, keep a list of the input-output pairs that have already been tried. They should feel free to make changes as this code isn't necessarily as clean or simple as it could be.
  2. Think of a project for next term. Perhaps they want to build a game, an animated presentation, something to demonstrate more mathematical concepts, a beautiful picture or they have other ideas? Encourage them to explore the following to spark some thoughts: gym.pencilcode.net, guide.pencilcode.net, other pencilcode user accounts, or have them do an online search.