2022 Review 3
(Final for grades 8 and 12.)
Part I
Day 1 for multi-day classes.
-
Make an animation where clicking or dragging the mouse makes an light orange rectangle with one corner at the mouse’s position.
- There is a 40 pixel orange border around the rectangle.
- There are a whole number of size 20 stars, positioned as below.
- The number of stars adjusts so they just almost fill the width and height of the light orange rectangle (so that adding one more will be wider than the rectangle, for example).
See the video for an animation.
-
(
twoth
) Given a list of numbers, if there are more multiples of two than multiples of three, change the sign of all of the multiples of two. Otherwise add one to each multiple of three.2a. Write two useful check-expects. 2b. Write the function
twoth
.
Part II
Day 2 for multi-day classes.
-
A hexagonal grid can be seen as “even columns” and “odd columns”. Let $w=50$ be the side length of a regular hexagon. Consecutive hexagons have centers separated horizontally by $3w/2$. The odd numbered columns also have centers offset vertically by $w \sqrt{3}/2$, which is half of the height of the hexagon.
3a. Construct this grid any way you can figure out.
3b. Write
hex-posn->xy : posn -> posn
by following the design process. (Check-expects!!)3c. Construct the grid using
for/fold
, reworking 3a as needed.(define hex (regular-polygon 50 6 "outline" "black"))
-
(Game of 2048) We will represent one row of the board of 2048 by a list of four numbers, with 0 representing the empty square. When you “slide” the board left, pairs of same-value numbers combine and others move so the zeros are all on the right. Write the function
slide-left
.slide-left: (Listof Number) -> (Listof Number) (check-expect (slide-left (list 0 0 0 2)) (list 2 0 0 0)) (check-expect (slide-left (list 0 2 0 4)) (list 2 4 0 0)) (check-expect (slide-left (list 8 8 0 0)) (list 16 0 0 0)) (check-expect (slide-left (list 8 16 16 16)) (list 8 32 16 0))