Survival

Coding Exercise 1

Prerequisite Concepts 7
Key Concepts 10, 11, 12

Imagine one day you wake up and find yourself stranded on a beautiful desert island in the middle of the Pacific ocean. You don’t know how you got there and all you have aside from a swimsuit is a backpack full of Bricklayer functions and a note from NOAA. “Don’t be fooled by the sunny weather and gentle waves lapping on the shore” the note says, “a giant category 5 hurricane (called a cyclone in this part of the world) is headed straight for your island. Twenty four hours from now the island will be washed away and if it wasn’t for the picture shown below, no one would even believe the island ever existed.”

Tropical uninhabited island in the Pacific Ocean
Tropical uninhabited or desert island with only a beach and palm trees in the famous Blue Lagoon inside Rangiroa atoll, an island of the Bora Bora archipelago French Polynesia in the Pacific Ocean.

The only way to get off this island is to write a Bricklayer program whose length is 128 lines or less that when executed creates an artifact containing between 10,000 and 20,000 bricks. “Easy” you say, “I will simply create a circle having a sufficiently large radius. One such function call and it’s back to civilization for me. I’ll take a swim and then have a nap on the beach and then write my rescue program before the weather gets too rough”. It is late in the afternoon before the rumble of thunder on the distant horizon wakes you up from your nap. You open your backpack to find that it only contains Level_2 functions that create 1×1 bricks (e.g., put2D_1x1_BLUE, put2D_1x1_RED, and so on). The circle function is not there! After a brief moment of panic, you realize that you can create (i.e., declare) your own functions. “Whew” you say out loud. As you sit down and begin to code, the first raindrop hits your face…

Examples of what can be created are shown in Figures 1 – 3.

survival02
Figure 1: 11,520 bricks and 83 lines of well formatted code (including blank lines).
survival03
Figure 2: 11,360 bricks and 110 lines of well formatted code (including blank lines).
survival07
Figure 3: 13,312 bricks and 99 lines of well formatted code (including blank lines).