CODING PUZZLES

[Solutions are shown after the puzzles]

Coding Puzzle 1: Number patterns (Scratch)

Go to https://scratch.mit.edu/projects/453644929/editor

Run the code. You should get the list of numbers shown below.

1. Edit the code to get each of the following:

2. Edit the code to list the odd numbers 1-19 in reverse order: 19, 17, 15, 13, 11, 9, 7, 5, 3, 1.


Coding Puzzle 2: Number sums (Scratch)

  1. Go to https://scratch.mit.edu/projects/457027214/editor
  2. Run the code. You should get the lists of numbers and sums shown on the right.
  3. Edit the code to list and find the sum of numbers 10, 20, 30, and 40. Can you predict their sum?
  4. Edit the code to list and find the sum of numbers 100, 200, 300, and 400. Can you predict their sum?
  5. Edit the code to list and find the sum of numbers 11, 22, 33, and 44. Can you predict their sum?
  6. Edit the code to list and find the sum of numbers 111, 222, 333, and 444. Can you predict their sum?

Coding Puzzle 3: Number patterns (Python)

EVEN NUMBERS

  1. Go to cscircles.cemc.uwaterloo.ca/console and enter and run the code below. It will list the first 5 even numbers.
  1. Edit the code to list the first 10 even numbers.
  2. Edit the code to list the even numbers 6 to 20.

ODD NUMBERS

  • Edit the code to list:
    • The first 5 odd numbers
    • The odd numbers 11 to 25

NATURAL NUMBERS

  • Edit the code to list:
    • The first 10 natural numbers
    • The natural numbers 10 to 20

Coding Puzzle 4: Number sums (Python)

NATURAL NUMBERS & THEIR SUMS

  1. Go to cscircles.cemc.uwaterloo.ca/console
  2. Enter and run the code below. It will list the first 4 natural numbers and their sums.
  • Edit the code to find the sum of numbers 10, 20, 30, and 40. Can you predict their sum?
  • Edit the code to find the sum of numbers 100, 200, 300, and 400. Can you predict their sum?
  • Edit the code to find the sum of numbers 11, 22, 33, and 44. Can you predict their sum?
  • Edit the code to find the sum of numbers 111, 222, 333, and 444. Can you predict their sum?

SOLUTIONS

Coding Puzzle 1: Number patterns (Scratch)

1.A.  set number to 6                                                 

1.B.  set number to 1; change number by 2

1.C.  set number to 2; change number by 2              

1.D.  set number to 3; change number by 3

1.E.  set number to 500; change number by 500                                                      

2.  set number to 19; change number by -2   


Coding Puzzle 2: Number sums (Scratch)

3. To print multiples of 10, make these edits:

a. Set number to 10

b. Change number by 10

4. To print multiples of 100, make these edits:

a. Set number to 100

b. Change number by 100

5. To print multiples of 11, make these edits:

a. Set number to 11

b. Change number by 11

6. To print multiples of 111, make these edits:

a. Set number to 111

b. Change number by 111


How Puzzle 2 Code Works

The code calculates and lists the natural numbers and their sums.

  • Using set number to 1 and change number by 1, the code calculates and lists numbers 1-4.
  • Using set sum to 0 and set sum to sum + number, the code calculates and lists the sums of the numbers 1-4.

Variations
  1. To list and find the sums of odd numbers, edit change number by 1 to change number by 2.
  2. To list and find the sums of even numbers, edit set number to 1 to set number = 2 and change number by 1 to change number by 2.

Coding Puzzle 3: Number patterns (Python)


Coding Puzzle 4: Number sums (Python)


HOW PUZZLE 4 CODE WORKS

The code calculates and prints natural numbers and their sums.

  • Using number = 1 and number = number + 1, the code calculates and lists the numbers 1-4.
  • Using SUM = 0 and SUM = SUM + number, the code calculates and lists the sums of the numbers.

VARIATIONS

  1. To list and find the sums of odd numbers, change number = number + 1 to number = number + 2.
  2. To list and find the sums of even numbers, change number = 1 to number = 2, and number = number + 1 to number = number + 2.