Open a new file.
You have a choice. Some of the problems below are about language or linguistics, some are about mathematics, and some are about art. Choose any three that interest you and do them.
"Tableau 1" by Piet Mondrian
Mondrian wasn't at all random in his choice of colors and locations, but even some random choices can be interesting. A snap script can produce designs like these.
To keep your code clear, you may want to create separate blocks that specialize in boundary and fill and choosing locations and calculating size.
snap has no fill with color
block. One way to make such a block is
To get bright colors, use set pen shade to 100
, and you get a good collection of colors with
clear
the stage and try In order to do this, you will need to be able to change a letter into a number, add 1 to that number, and then change the new number back to a letter. The blocks and
will help you do that. Experiment with them to see how they work.
encode
block the input z
, what does it report? If that's not what you would like it to report, change it. decode
block.factorial
block n!
block to report 1 if n = 0. Then fully test n!
again to make sure it works as it should. triangular number n
that adds all of the whole numbers from 1 through n:$$1 + 2 + 3 + \cdots + (n - 1) + n$$ When its input is 4, your block should report 10 (that is, 1 + 2 + 3 + 4). Define your block so that triangular number 0
reports 0. n mod i
will tell you if i is a divisor of n.number-of-divisors 10
should also report 4 because, of the numbers from 1 through 10, only 1, 2, 5, and 10 are divisors of 10. Experiment to find several numbers that have an odd number of divisors.
Edit it and give it inputs that let you produce pictures like these. You don't have to use script variables.
Experiment with various inputs.
Set "flat line ends" and create a block that draws pictures like this. It will be convenient to use script variables
raise (n) to the power (b)
block to make it work for negative integer exponents. digit sum
that adds up the digits in a number. So, for example digit sum 7
should report 7, and digit sum 12
should report 3, and digit sum 126
should report 9 (the sum of 1, 2 and 6). You may find these blocks useful. repeated digit sum
, which keeps taking the digit sum
until the result is a single digit. For example, the digit sum of 238 is 2+3+8=13, which is more than a single digit. The digit sum of 13 is 1+3=4, which is a single digit. So the repeated digit sum of 238 is 4.divisible by 3?
and divisible by 9?
. A number is divisible by 3 if its repeated digit sum is 0, 3, 6, or 9; it's divisible by 9 if its digit sum is 0 or 9.
multiples of 7 algorithm
block that takes any whole number as input and then puts it through this process:
Test it first on several multiples of 7 (small and large) and make sure that, for multiples of 7, it reports only the results 14, 7, 0, -7, and -14. Also test it on several numbers that are not multiples of 7; for those numbers, it should never report 14, 7, 0, -7, or -14.
mod
, but before computers were widespread, algorithms like these greatly simplified some computations.