mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2012-07-25, 23:36   #1
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,703 Posts
Default Kids?

We are looking for something similar to Project Euler, except geared towards kids in the 6th to 8th grade range.

A list of problems to solve would be fine but an infrastructure to test and keep track of results would be ideal.

We would like the problems to get progressively harder and possibly force the young programmer to step outside their comfort zone a little each time.

Problems that take just a simple answer, like the ones at Project Euler, are great because we do not want to mess with file I/O or stuff like that. (We will be using Scratch.)

Ideas?
Xyzzy is offline   Reply With Quote
Old 2012-08-03, 08:02   #2
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,703 Posts
Default

Nobody?



We designed and assigned problem one, which is to accept input from the keyboard and, if the input is an integer equal to or between 1 and 1,000, output whether the input is prime or composite.

We think the parameters of this challenge are properly stated, but if you all see something wrong please let us know!

The "class" went well, we think. The test subject, age 11, showed us their final program, running, and we tried to break it. We are not, yet, at the point to critique code practices, although we did have the test subject print out the "code", annotate it and tape it to the wall. When asked why, we indicated that code reuse is "being lazy in a good way" and that very quickly (Less than a few hours for us!) most code is forgotten if not documented.

At each of the following points the test subject needed to go fix things:
  • Input not checked to make sure it was less than or equal to 1,000.
  • Input not checked to make sure it was greater than or equal to 1.
  • Input not checked to make sure it was an integer.
  • Output for "1" was not listed as "not prime or composite". (This one took a long time to figure out. We allowed the test subject to use Internet resources to figure it out.)
Overall we all had a lot of fun. The algorithm the test subject used was pure brute force but it worked. We have made problem two a challenge to make the program from problem one at least twice as fast. We subtly hinted to the test subject that it might be possible to increment through the loop with a different sized step and that there was no need to test all numbers below the input as possible factors. (We are trying to keep it simple enough to solve without ruining the experience.)

Anyways, the test subject earns $5 (!) for every correct program so we need a few more problems, so we can try to understand and solve them first, since the test subject is very motivated to earn money.

Thanks!

PS - The IDE for Scratch is very cool! Debugging is a lot of fun because it allows you to step through the program graphically.
Attached Thumbnails
Click image for larger version

Name:	1.gif
Views:	142
Size:	16.8 KB
ID:	8399  
Xyzzy is offline   Reply With Quote
Old 2012-08-03, 08:29   #3
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

11100000111012 Posts
Default

Some notes:

You say "check for int", but that pic you showed does no such thing, unless Scratch can determine on the fly if a string represents an int or not. In either case, I'd point out that in the IRL languages I'm familiar with, checking a string for an int is something the programmer has to do, even in a dynamically typed (or untyped) language, such as Python.
Code:
try:
    num = int(input("Please enter a number between 1 and 1000 inclusive"))
except ValueError:
    print("Error: Input is not a num. Aborting.") # Or perhaps loop here waiting for a good answer
    # Don't just catch errors, handle them nicely
else: # No exception, valid int
    do_print_primality() # etc...
I would consider using Python, because it definitely is among the most widely used (and most flexible) languages. Of course, as a disclaimer, I'm not sure if/what Scratch is usable IRL.

Also, what the heck is with the if n%1==0? That's trivially true for any natural number.

Finally, perhaps you might suggest/teach
Code:
if n > 1 and n <= 1000: # In Python, "if 1 < n <= 1000" is actually a valid conditional
  stuff()
elif n==1:
  print("Neither")
...as opposed to...
Code:
if n >= 1:
   if n==1:
      print("Neither")
   elif n <= 1000:
      stuff()


Edit: About coding practices, everything falls under something like:

Be clear -- fancy tricks aren't great if they aren't necessary, because they're often confusing
Be maintainable -- as you point out, you or anyone else should be able to come back to it and understand it from a cold start -- good docs help, but clear code helps more
You should be able to pass off the project to somebody else and have them dive right in after 1, maybe 2 read throughs.

Everything else like proper syntax, proper indentation, etc., falls under these not-really-different points. (Of course, there are exceptions to these rules, e.g. library code which isn't read except by a few people, and speed critical code like Prime95's asm, but nothing that your subject will write in the near future will fall under these categories.)

Last fiddled with by Dubslow on 2012-08-03 at 08:33
Dubslow is offline   Reply With Quote
Old 2012-08-03, 08:54   #4
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

1E1716 Posts
Default

Quote:
You say "check for int", but that pic you showed does no such thing, unless Scratch can determine on the fly if a string represents an int or not.
Quote:
Also, what the heck is with the if n%1==0? That's trivially true for any natural number.
That is how our test subject checked to make sure it was an integer.

1.5 mod 1 is 0.5, thus it is not an integer.
4 mod 1 is 0, thus it is an integer.

(This is sane, right? It works in the program!)

We are still digesting our test subject's thought process. We tried Python but our test subject lost interest very quickly. We were using this book/PDF. The test subject reacted violently to lines in the interpreter that went like this:

Code:
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/2
1
>>> 3.0/2
1.5
We will read and reply to your other thoughts tomorrow today since it is almost 4AM and we probably should get some sleep.
Xyzzy is offline   Reply With Quote
Old 2012-08-03, 09:09   #5
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×2,399 Posts
Default

Python 3 has changed that. It is not backwards compatible with Python 2, but it will do this:
Code:
bill@Gravemind:~βˆ°βˆ‚ python3
Python 3.2 (r32:88445, Dec  8 2011, 15:26:58) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 3/2
1.5
>>> 3//2
1

As for the int thing, what's this?
Code:
"this is a string" % 2
That causes a TypeError in Python. What happens when you type 'this is not a number' into that Scratch program?

Last fiddled with by Dubslow on 2012-08-03 at 09:11
Dubslow is offline   Reply With Quote
Old 2012-08-03, 15:24   #6
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

11110000101112 Posts
Default

Quote:
What happens when you type 'this is not a number' into that Scratch program?
Do you mean typing in garbage (text and/or symbols) at the input?

Input like that is handled by the first conditional statement.

Scratch also allows very large numbers to be used without any special type declarations.

It is designed to be for kids, so they (We think!) are focusing more on getting kids programming than spending hours worrying about syntax. Most of the programming is point-and-click. Our test subject spent several hours reading the first chapter of the previously linked Python book before attempting to program. With Scratch we started the IDE and the test subject was programming within a minute. Sure, the first program was a loop that made an annoying cat sound repeatedly, but it was a program that was done without any intervention on our part.

While we prefer a more structured (?) language, and we go to the extreme of flowcharting on paper first, we would much rather have our test subject program in Scratch than not at all. And, we think that solving problem one with no programming experience is a pretty good start. Of course, we guided the test subject a lot, but only by answering questions. We did not sit at the computer at all.

Scratch is certainly not fast nor optimized but if it ignites a fire for solving big problems by making them into a bunch of little problems, we will be pleased.

So we are still looking for program ideas, or maybe an appropriate textbook.

FWIW, this programming forum has many examples of our poor programming skills if you have the time to search for them. They are embarrassing but we have a lot of fun messing around.
Xyzzy is offline   Reply With Quote
Old 2012-08-03, 15:40   #7
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

22·32·281 Posts
Default

Quote:
Originally Posted by Xyzzy View Post
So we are still looking for program ideas, or maybe an appropriate textbook.
Classics include swapping two variables (lots of undergraduates have problems with that one); rather more difficult: sorting into numerical order; even more difficult: towers of Hanoi.


Paul
xilman is offline   Reply With Quote
Old 2012-08-03, 15:46   #8
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3·2,399 Posts
Default

Quote:
Originally Posted by xilman View Post
Classics include swapping two variables (lots of undergraduates have problems with that one); rather more difficult: sorting into numerical order; even more difficult: towers of Hanoi.


Paul
Ooohh, recursion... probably best saved for quite a bit further into the future

(PS Re swapping, Python lets you do this: `x, y = y, x` )
Dubslow is offline   Reply With Quote
Old 2012-08-03, 15:56   #9
Xyzzy
 
Xyzzy's Avatar
 
"Mike"
Aug 2002

7,703 Posts
Default

We have assigned problem three, which is to sum the first 100 prime numbers.

@ xilman - The next problem will involve swapping variables. We just need to figure out a way to make it interesting. Thanks for the idea!

We want to do some sorting exercises but first we need to look at if/how Scratch handles arrays. We do know that it is possible to address individual characters in a string, so that would work for a simple problem.

We are holding off on things like "Towers of Hanoi" or "Eight Queens" for a while.

Xyzzy is offline   Reply With Quote
Old 2012-08-03, 16:43   #10
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3·2,399 Posts
Default

Some links:

http://sixrevisions.com/resources/10...amming-skills/ -- not directly usable, but may provide some problem ideas (such as: create a ROT13 de/cipher program)

http://marshallbrain.com/kids-programming.htm -- Mentions a lot of things, Scratch and Python included

http://marekrychlik.com/node/417 -- excellent problem resource

My google search was "interesting programming problems for kids"
Dubslow is offline   Reply With Quote
Old 2012-08-03, 16:49   #11
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

8,369 Posts
Default

Quote:
Originally Posted by Xyzzy View Post
We have assigned problem three, which is to sum the first 100 prime numbers.

@ xilman - The next problem will involve swapping variables. We just need to figure out a way to make it interesting. Thanks for the idea!

We want to do some sorting exercises but first we need to look at if/how Scratch handles arrays. We do know that it is possible to address individual characters in a string, so that would work for a simple problem.

We are holding off on things like "Towers of Hanoi" or "Eight Queens" for a while.

variables -> make a list might work for an array. and it can as long as you can get the string into an array as characters in each index.

Last fiddled with by science_man_88 on 2012-08-03 at 17:39 Reason: changed he to the
science_man_88 is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
a numberphile like channel by kids science_man_88 science_man_88 0 2017-11-17 21:37
Remember kids, compressed air. TheMawn Lounge 1 2013-11-17 08:53
japan catastroph explained to kids firejuggler Lounge 15 2011-03-23 05:17

All times are UTC. The time now is 18:44.

Thu Oct 22 18:44:02 UTC 2020 up 42 days, 15:55, 2 users, load averages: 1.71, 1.95, 2.11

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.