1 of 89

Have we been here before?

Algorithms + Loops

2 of 89

Have we been here before?

Algorithms + Loops

Where're the algorithms here?

Where're the loops here?

3 of 89

Have we been here before?

Algorithms + Loops

algorithm ~ step-by-step instruction(s)

loop ~ repeated action

4 of 89

Have we been here before?

Algorithms + Loops

most famous infinite loop?

loop ~ repeated action

5 of 89

scratch

6 of 89

scratch

7 of 89

Infinite loop?

HMC's "awesome things" competition

8 of 89

Infinite loop?

9 of 89

Computer Science

is applying algorithms

to data

in loops!

Data = information

10 of 89

Data: big example

Google Glass

100 years of HD: 60,000,000 GB

= 60 Petabytes

video: Google glass

C:\Users\Owner\Desktop\to_sort_more_recent\desktop_to_sort\desktop_to_sort_fall_15_in_pusd_workshop\WKauaiDay2

Data = information

11 of 89

There's lots of it to work with!

Data: the big picture

12 of 89

Data: a big example

Google Glass concerns

5/16/13

Is Google Glass dead or hibernating?

13 of 89

To work with data, it is always encoded: converted into a specific form by a set of rules.

Later, it can be decoded: changed back into its original form.

CS Data: encoding and decoding

14 of 89

To work with data, it is always encoded: converted into a specific form by a set of rules.

Later, it can be decoded: changed back into its original form.

CS Data: encoding and decoding

This is the essence of CS:

communication!

15 of 89

Yesterday we noted two things computers do:

(1) process data (arithmetic) (2) store/retrieve data

Amazingly, this is all that computers do!

16 of 89

Is this all that computers do?

(1) process data (arithmetic) (2) store/retrieve data

Let's see… Try listing some things we use computers for…

Is this all that computers do?

Which is the LARGER subset?

17 of 89

Data: it's what computers do!

And this is the vast majority of computer work!

We noted two things computers do:

(1) process data (arithmetic) (2) store/retrieve data

Rather than computers, they should be called datadogs.

18 of 89

One method of encoding a sentence is by having every letter correspond to a number.

For example:

AND 1 - 14 - 4

BUG .

19 - 09 - 07 - 14

Decoded data

Encoded data

Encoding + Decoding!

19 of 89

One method of encoding a sentence is by having every letter correspond to a number.

For example:

AND 1 - 14 - 4

BUG 2 – 21 - 7

SIGN 19 - 09 - 07 - 14

Decoded data

Encoded data

Encoding + Decoding!

Where's the algorithm here?

Where's the loop here?

20 of 89

One method of encoding a sentence is by having every letter correspond to a number.

For example:

AND 1 - 14 - 4

BUG 2 – 21 - 7

SIGN 19 - 09 - 07 - 14

Decoded data

Encoded data

Encoding + Decoding!

Algorithm

Loop

Loop output

21 of 89

Or, we could shift every letter by one spot

A B, B C, C D, .....

For example:

ZOO APP

END

NVEE

Decoded data

Encoded data

Encoding + Decoding!

Where's the algorithm here?

Where's the loop here?

22 of 89

Or, we could shift every letter by one spot

A B, B C, C D, .....

For example:

ZOO APP

END FOE

MUDD NVEE

Decoded data

Encoded data

Encoding + Decoding!

Algorithm

Loop

Loop output

23 of 89

Another encoding algorithm

Morse code encodes letters as dots and dashes

short sound: "dit"

long sound: "dah"

R

How does this chart represent Morse code?

What is the letter A in Morse code? What about the letter

?

24 of 89

Another encoding algorithm

Morse code encodes letters as dots and dashes

What is the encoding of SOS in Morse code? How about FOG?

short sound: "dit"

long sound: "dah"

orange = dash

white = dot

What is this word?

25 of 89

Encoding + Decoding

Challenges

26 of 89

The following slides contain encoded words.

    • Find the rules or pattern for each one!
    • This is the Algorithm
    • Decode each phrase: This is the Loop

For some, you will encode, instead of decode.

    • We will provide one example.
    • Then, you'll create your own encoding…

Decoding = Algorithm + Loop

27 of 89

�25-15-21 19-15-12-22-5-4 20-8-5 6-9-18-19-20 15-14-5

Every letter corresponds to a number.

A = 1, B = 2, C = 3, ...

See the table below:

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

28 of 89

�KVTU LFFQ TXJNNJOH

Every letter is shifted by one.

 

  • A = B
  • B = C
  • C = D, ...

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

29 of 89

�REVELC SI SECNETNES GNISREVER

(Use this space to work it out)

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

30 of 89

�SENTENCE WIT MISSIN LETTER AR CONFUSIN

(Use this space to work it out)

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

31 of 89

�UOY ERA YAWFLAH ENOD

(Use this space to work it out)

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

32 of 89

�VEREOYEN OLEVS OCPMTURE CSEICNE

(Use this space to work it out)

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

33 of 89

�VOWOLS ORO OMPORTONT ON SONTONCOS

Every vowel is now an “O” !

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

34 of 89

�IS IT CATS RAINING DOGS AND

(Use this space to work it out)

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

35 of 89

You will use these Morse Code rules to decode the next two secret messages.

Morse Code

36 of 89

Another algorithm ~ morse code

Morse code encodes letters as dots and dashes

orange = dash

white = dot

37 of 89

Morse Code

_ _ _ _ _ . _ . . . . .

_ . _ . _ _ _ _ . . . . . . . .

_ . _ . _ _ _ _ _ _ . _ . .

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

38 of 89

�Morse Code

_ . _ . _ _ _ _ . _ _ . . _ .

. _ _ . . _ . _ . . . _ _ . .

_ _ _ _ . . . . _ . _ _

_ _ _ . . _ . . _ . . . _ .

. . . . . . . . . . _ . .

(Use this space to work it out)

Encoded Sentence:

Algorithm

Loop to decode

Optional!

39 of 89

��PUPPIES ARE CUTE

Pig Latin

  • If a word begins with a consonant:
    • the consonant is moved to the end
    • and an “ay” is added.
  • If not:
    • only “ay” is added.

Note: This time you are encoding the sentence.

Algorithm

Loop to ENCODE

Decoded sentence

Conditionals!

40 of 89

Now, invent your own code. Write your algorithm here:

Next, write your encoded secret message here:

Then, put it on the top of the next page + TRADE!

Algorithm

Loop to Encode:

Original (decoded) sentence

something not too difficult…

We'll use the board…

41 of 89

(Use this space to work it out)

(Use this space to work it out)

Algorithm

… from the previous page

Encoded Sentence:

Loop to Decode

Trade this page with another team and try to decode each other's sentences!

42 of 89

Scratch coding challenges…

43 of 89

The "digital age" ...

For computers, all data is ultimately represented as a set of numbers.

With binary, all numbers can be represented as a series 1's and 0's.

44 of 89

Binary is just another code!

0

1

2

3

4

5

6

7

8

9

10

decimal

45 of 89

Binary is just another code!

000

001

010

011

101

110

111

0

1

2

3

4

5

6

7

8

9

10

decimal

binary

46 of 89

Consider this much spam:

Why do we use 37 to encode this amount?

47 of 89

The 7 means "seven ones"

The 3 means "three tens"

Together, they represent the total amount (what we call thirty-seven)

3 7

3*10

7*1

tens

ones

37

48 of 89

Our numbers...

Decimal is based on the number 10.

ones

tens

hun- dreds

4 3 7

How is each column value getting larger?

49 of 89

In binary, the columns increase x 2

In decimal, the columns increase x 10

3 7

tens

ones

1 0

twos

ones

That's the difference!

in binary

50 of 89

In binary, the columns increase x 2

In decimal, the columns increase x 10

3 7

tens

ones

1 0

twos

ones

That's the difference!

in binary

2

ones

in decimal

=

51 of 89

Computers' numbers

Binary is based on the number 2.

ones

twos

fours

1 0 1 0

How is each column value getting larger?

What should this column value be?

52 of 89

Decoding binary decimal

Suppose the computer holds this binary number:

ones

twos

fours

1 1 0 1

eights

Let's decode it into decimal:

53 of 89

Practice

From binary to decimal:

From decimal to binary:

101

1011

10000

101010

Binary

Decimal

1

2

4

14

33

1

2

4

8

16

32

54 of 89

Try these!

From binary to decimal:

From decimal to binary:

1001

110

11010

10101

3

14

25

52

Binary

Decimal

55 of 89

Acting out in binary…

We need 110 volunteers...

Don't worry -- you'll only have bit parts in this.

56 of 89

Acting out in binary…

(1) Challenge the class!

have the "bits" create any number and the class has to figure out what it is

(2) Challenge the bits!

have the class suggest a number and challenge the "bits" to create it in binary

(3) Patterns in counting

have the cards count up + down and have the class find the patterns

(4) Even / Odd / More!

have everyone determine patterns in binary #s

57 of 89

but why do computers use binary… ?

58 of 89

How many different symbols can occupy each digit location in a number?

37

The problem is the number of digits!

59 of 89

How many different symbols can occupy each digit location in a number?

37

There can be ten different digits!

07 17 27 37 47 57 67 77 87 97

The problem is the number of digits!

60 of 89

A computer has to differentiate physically among all its possibilities.

Ten symbols is too many!

ten symbols ~ ten different voltages

This is too difficult to replicate billions of times

What digits are these?

engineering!

0

1

2

3

4

5

6

7

8

9

Ouch!

61 of 89

A computer has to differentiate physically among all its possibilities.

Easy!

Two symbols is easier!

What digits are these?

two symbols ~ two different voltages

ten symbols ~ ten different voltages

0

1

2

3

4

5

6

7

8

9

0

1

62 of 89

The "digital age" ...

For computers, all data is ultimately represented as 0s and 1s, in binary.

Could you encode a lego tower in binary... ?

Then, have someone else decode it back into the same Lego tower?

63 of 89

ImagineDecomposeSpecify Binarize – Execute – Compare – Debug!

Codes and Data

Lego towers

… in binary

64 of 89

Secret Fortress Construction Challenge

64

You should have two identical LEGO block kits.

Set the extra kit aside, and use one kit to build a LEGO fortress:

  1. Find a secluded spot to build your secret fortress. Don’t let anyone else see it!
  2. Place your Lego baseplate on top of the template on page 2. Note the x and y axes are 0, as usual.
  3. [First-timer advice] Keep your tower to the lower-left corner, where x and y are 7 or less
  4. Write the English instructions for building your tower… (page 3)
  5. Create a binary encoding (the legend) for each type and color of your Legos. (page 3)
  6. Translate the English instructions to binary instructions for your tower! (page 4)
  7. Be sure to copy over the legend, as well!
  8. [Optional] Create a single line of 0s and 1s that you will send to the other team.
  9. [Optional] Text or email that single line of 0s and 1s to the other team.
  10. [Optional] Reassemble the other team's single line of 0s and 1s into binary instructions:
  11. Swap! Make sure you have the chart of the other team's binary instructions
  12. Make sure you copy the other team's legend with their binary encoding
  13. Convert their binary instructions back to English instructions using the legend.
  14. Try to build their secret fortress!
  15. When both teams are done, compare the fortresses you’ve created.
  16. Were you successful? Why or why not?
  17. Debug! If something went wrong, find where it went wrong -- which step of the process was it?!

There are lots of background materials…

(we'll go light on these for now)

65 of 89

Imagine – Decompose – Specify – Binarize – Execute – Compare – Debug!

from ideas to binary – and back

66 of 89

Imagine – Decompose – Specify – Binarize – Execute – Compare – Debug!

Codes and Data

67 of 89

67

68 of 89

68

How could you tell someone how to build this tower – if they could not SEE it!

69 of 89

69

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

Secret Fortress Base Template

x

y

We definitely need to be able to describe positions of Legos!

70 of 89

70

Block

Color

Brick Type

Orientation

X

Y

Sample

Red

2x4

Horizontal

6

4

0

Red

2x3

Vertical

0

0

1

Yellow

2x3

Horizontal

2

0

2

Yellow

2x2

Vertical

1

1

3

4

5

6

7

8

Color

Red

001

Your Legend

Brick Type

2 x 4

010100

Orientation

Horizontal

00

Vertical

01

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

Fill in the chart below with English and numeric instructions for your fortress.

Follow the sample line, which says “put the sample block, which is a red 2x4 block, horizontally, with its bottom left corner at the position given by the x-coordinate 6 and the y-coordinate 4.”

Then, fill in the legend to create an encoding for all the bricks you used.

For example, a 2x4 block might be represented with 010100, since 010 is 2 in binary, and 100 is 4 in binary.

Chart A. Your team's English Instructions

Let's go!

71 of 89

71

Block

Color

Brick Type

Orientation

X

Y

Sample

001

010100

00

0110

0100

0

(Red)

(2x3)

Vertical

(0)

(0)

1

(Yellow)

(2x3)

Horizontal

(2)

(0)

2

(Yellow)

(2x3)

Vertical

(1)

(1)

3

(Red)

(2x3)

Vertical

(1)

(2)

4

5

6

7

8

Color

Red

001

Brick Type

2 x 4

010100

Orientation

Horizontal

00

Vertical

01

Copy the legend you created on the last page to this page.

Then, translate the instructions in Chart A to binary.

Converting information into binary allows a computer to store it and communicate it. Computers use an electric signal to represent the 1s and no signal to represent the 0s.

Your Legend

Chart B. Your team's binary Instructions

& convert to binary…

Now, we fill the legend…

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

72 of 89

72

Block

Color

Brick Type

Orientation

X

Y

Sample

001

010100

00

0110

0100

0

001 (Red)

010011 (2x3)

01 Vertical

0000 (0)

0000 (0)

1

010 (Yellow)

010011 (2x3)

00 Horizontal

0010 (2)

0000 (0)

2

010 (Yellow)

010010 (2x2)

01 Vertical

0001 (1)

0001 (1)

3

001 (Red)

010010 (2x2)

01 Vertical

0001 (1)

0010 (2)

4

5

6

7

8

Orientation

Horizontal

00

Vertical

01

Copy the legend you created on the last page to this page.

Then, translate the instructions in Chart A to binary.

Converting information into binary allows a computer to store it and communicate it. Computers use an electric signal to represent the 1s and no signal to represent the 0s.

Your Legend

Chart B. Your team's binary Instructions

My answer…

Color

Red

001

Yellow

010

Brick Type

2 x 4

010100

2 x 3

010011

2 x 2

010010

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

73 of 89

73

Block

Color

Brick Type

Orientation

X

Y

Sample

001

010100

00

0110

0100

0

001

010011

01

0000

0000

1

010

010011

00

0010

0000

2

010

010010

01

0001

0001

3

001

010010 (

01

0001

0010

4

5

6

7

8

Orientation

Horizontal

00

Vertical

01

Copy the legend you created on the last page to this page.

Then, translate the instructions in Chart A to binary.

Converting information into binary allows a computer to store it and communicate it. Computers use an electric signal to represent the 1s and no signal to represent the 0s.

Your Legend

Chart B. Your team's binary Instructions

just the bits!

Color

Red

001

Yellow

010

Brick Type

2 x 4

010100

2 x 3

010011

2 x 2

010010

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

74 of 89

74

Block

Color

Brick Type

Orientation

X

Y

Sample

001

010100

00

0110

0100

0

001

010011

01

0000

0000

1

010

010011

00

0010

0000

2

010

010010

01

0001

0001

3

001

010010 (

01

0001

0010

4

5

6

7

8

Color

Red

001

Yellow

010

Brick Type

2 x 4

010100

2 x 3

010011

2 x 2

010010

Orientation

Horizontal

00

Vertical

01

Copy the legend you created on the last page to this page.

Then, translate the instructions in Chart A to binary.

Converting information into binary allows a computer to store it and communicate it. Computers use an electric signal to represent the 1s and no signal to represent the 0s.

Your Legend

Chart B. Your team's binary Instructions

Differentiating delivery

Extra challenge: text the lines of bits

Usual: just swap binary pages (this one)

Simpler: just swap English pages (previous)

- swap bits -

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

75 of 89

75

Orientation

Horizontal

00

Vertical

01

Their Legend

Color

Red

001

Yellow

010

Brick Type

2 x 4

010100

2 x 3

010011

2 x 2

010010

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

Transferring the bits!

Try it!

Take a picture of your binary instructions of 0s and 1s

Next, send a text or email with the bits of your tower.

Then, decode the instructions & build the same tower!

Finally, compare the original tower with the new one – and debug any differences!

76 of 89

76

Block

Color

Brick Type

Orientation

X

Y

Sample

Red

2x4

Horizontal

6

4

0

Yellow

2x3

Horizontal

1

0

1

Red

2x3

Vertical

2

0

2

Red

2x2

Vertical

0

3

3

Yellow

2x2

Vertical

3

1

4

5

6

7

8

Orientation

Horizontal

00

Vertical

01

Translate the other team's instructions to English instructions.

Chart D. Other team's English Instructions

Their Legend

Color

Red

001

Yellow

010

Brick Type

2 x 4

010100

2 x 3

010011

2 x 2

010010

Decode…

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

77 of 89

77

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

DECODED Fortress!

x

y

See if they match!

78 of 89

DECODED Fortress!

See if they match!

79 of 89

79

Bug tracker…

How many differences were they between the original and DECODED towers?

Find where the differences happened and make a mark for each location of these "bugs"

If you want to actually draw bugs, even better!

Translating from tower to English

Translating from English to binary

Transferring the bits

Translating from binary to English

Translating from English to tower

80 of 89

Secret Fortress Construction Challenge

80

You should have two identical LEGO block kits.

Set the extra kit aside, and use one kit to build a LEGO fortress:

  1. Find a secluded spot to build your secret fortress. Don’t let anyone else see it!
  2. Place your Lego baseplate on top of the template on page 2. Note the x and y axes are 0, as usual.
  3. [First-timer advice] Keep your tower to the lower-left corner, where x and y are 7 or less
  4. Write the English instructions for building your tower… (page 3)
  5. Create a binary encoding (the legend) for each type and color of your Legos. (page 3)
  6. Translate the English instructions to binary instructions for your tower! (page 4)
  7. Be sure to copy over the legend, as well!
  8. [Optional] Create a single line of 0s and 1s that you will send to the other team.
  9. [Optional] Text or email that single line of 0s and 1s to the other team.
  10. [Optional] Reassemble the other team's single line of 0s and 1s into binary instructions:
  11. Swap! Make sure you have the chart of the other team's binary instructions
  12. Make sure you copy the other team's legend with their binary encoding
  13. Convert their binary instructions back to English instructions using the legend.
  14. Try to build their secret fortress!
  15. When both teams are done, compare the fortresses you’ve created.
  16. Were you successful? Why or why not?
  17. Debug! If something went wrong, find where it went wrong -- which step of the process was it?!

Now, the real thing…

Pairs, pair up!

81 of 89

81

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

Secret Fortress Base Template

x

y

Don't show the other team your tower!

82 of 89

82

Block

Color

Brick Type

Orientation

X

Y

Sample

Red

2x4

Horizontal

6

4

0

1

2

3

4

5

6

7

8

Color

Red

001

Your Legend

Brick Type

2 x 4

010100

Orientation

Horizontal

00

Vertical

01

Fill in the chart below with English instructions for your fortress.

The sample line is ONLY an example. Don't use that brick!

Also, fill in the legend to create an encoding for all the bricks you used.

For example, a 2x4 block might be represented with 010100,

since 010 is 2 in binary, and 100 is 4 in binary.

Chart A. Your team's English Instructions

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

83 of 89

83

Block

Color

Brick Type

Orientation

X

Y

Sample

001

010100

00

0110

0100

0

1

2

3

4

5

6

7

8

Color

Red

001

Brick Type

2 x 4

010100

Orientation

Horizontal

00

Vertical

01

Copy the legend from the prior page to this page.

Then, translate the instructions in Chart A to binary.

Your Legend

Chart B. Your team's binary Instructions

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

84 of 89

84

Extra -- Transferring the bits!

Try it!

Take a picture of your binary instructions of 0s and 1s

Next, send a text or email with the bits of your tower.

Then, decode the instructions & build the same tower!

Finally, compare the original tower with the new one – and debug any differences!

Color

Red

001

Brick Type

2 x 4

010100

Orientation

Horizontal

00

Vertical

01

Their Legend

Differentiating delivery:

Spicy: actually text the bits!

Medium: just swap binary pages (images).

Mild: just swap English pages (images)

Numbers

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

85 of 89

85

Block

Color

Brick Type

Orientation

X

Y

Sample

001

010100

00

110

100

0

1

2

3

4

5

6

7

8

Color

Red

001

Brick Type

2 x 4

010100

Orientation

Horizontal

00

Vertical

01

Numbers

0

000

1

001

2

010

3

011

4

100

5

101

6

110

7

111

Translate the other team's instructions to English instructions.

And… build the tower!

Chart D. Other team's English Instructions

Their Legend

86 of 89

86

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

0

DECODED Fortress!

x

y

See if they match!

87 of 89

87

Bug tracker…

How many differences were they between the original and DECODED towers?

Find where the differences happened and make a mark for each location of these "bugs"

If you want to actually draw bugs, even better!

Translating from tower to English

Translating from English to binary

Transferring the bits

Translating from binary to English

Translating from English to tower

88 of 89

Imagine – Decompose – Specify – Binarize – Execute – Compare – Debug!

Codes and Data

89 of 89