Part 1
Expressions
arithmetic, dfns, order of execution
-
Without using a computer, evaluate the following expressions. Then, use an APL interpreter to check your answers.
3×2+4
4÷2+6-2
3+2 2×2
4+2 6×2
(3+(6×(2+3)))
(3+(6×2)+3)
3+6×(2+3)
((3+6)×2+3)
((3+6)×3)+3
((3+6×2)+3)
2×7-6+3
(2×7)-6+3
-
The average daily temperatures, in degrees Celcius, for 7 days are stored in a variable
t_allweek
.t_allweek ← 11.7 8.6 9.7 14.2 6.7 11.8 9.2
Use APL to compute the follwing:
- The highest daily temperature
- The lowest daily temperature
- The range of (difference between the largest and the smallest) temperatures
- Each temperature rounded to the nearest whole number
-
Rewrite the following expressions so that they do not use parentheses.
(÷a)×b
(÷a)÷b
(a+b)-5
(a+b)+5
Simple Functions
The following problems can be solved with single-line dfns.
-
Eggs
A recipe serving 4 people uses 3 eggs. Write the function
Eggs
which computes the number of eggs which need cracking to serve⍵
people. Using a fraction of an egg requires that a whole egg be cracked.Eggs 4 3 Eggs 100 75 Eggs ⍳12 1 2 3 3 4 5 6 6 7 8 9 9
-
The formula to convert temperature from Celsius (\(T_C\)) to Fahrenheit (\(T_F\)) in traditional mathematical notation is as follows:
\[T_F = {32 + {{9}\over{5}}\times {T_C}}\]Write the function
CtoF
to convert temperatures from Celcius to Farenheit.
CtoF 11.3 23 0 16 ¯10 38 52.34 73.4 32 60.8 14 100.4
Generating Sequences
-
A Mathematical Notation
Use APL to evaluate the following
-
\(\prod_{n=1}^{12} n\) (multiply together the first twelve integers)
-
\(\sum_{n=1}^{17}n^2\) (add together the first seventeen squared integers)
-
\(\sum_{n=1}^{100}2n\) (add together the first one hundred positive even integers)
-
\(\sum_{n=1}^{100}2n-1\) (add together the first one hundred odd integers)
-
In TMN, the following expression is equal to
0
, why does the following return70
in APL?84 - 12 - 1 - 13 - 28 - 9 - 6 - 15 70
-
-
Pyramid Schemes
-
Sugar cubes are stacked in an arrangement as shown by Figure 1.
Figure 1. Stacked sugar cubes This stack has
4
layers and a total of30
cubes. How many cubes are there in a similar stack with467
layers? -
Now consider the stack in Figure 2.
Figure 2. Differently stacked sugar cubes The arrangement in Figure 2 has
4
layers and84
cubes. How many cubes are there in a similar stack with812
layers? -
Now look at Figure 3.
Figure 3. This is just a waste of sugar cubes by now... The stack in Figure 3 has
3
"layers" and36
cubes in total. How many cubes are there in a similar stack with68
"layers"?
-
-
Write a function
To
which returns integers from⍺
to⍵
inclusive.3 To 3 3 3 To 4 3 4 1 To 7 1 2 3 4 5 6 7 ¯3 To 5 ¯3 ¯2 ¯1 0 1 2 3 4 5
BONUS: What if
⍺>⍵
?
3 To 5 3 4 5 5 To 3 5 4 3 5 To ¯2 5 4 3 2 1 0 ¯1 ¯2