Problem Set 1
1.#
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
Solutions:
⌈/t_allweek 14.2
⌊/t_allweek 6.7
(⌈/t_allweek)-⌊/t_allweek 7.5
⌈ t_allweek - 0.5 12 9 10 14 7 12 9
2.#
A Mathematical Notation
Use APL to evaluate the following
- \(\prod_{n=1}^{12} n\).
- \(\sum_{n=1}^{17} n^2\).
- \(\sum_{n=1}^{100}2n\).
- \(\sum_{n=1}^{100} (2n-1)\).
- 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
Solutions:
×/⍳12 479001600
+/(⍳17)*2 1785
+/2×⍳100 10100
+/(2×⍳100)-1 10000
- This becomes
(84 - (12 - (1 - (13 - (28 - (9 - (6 - 15)))))))
Hence effectively \(84-12+1-13+28-9+6-15\)
3. Pyramid Schemes#
![]() | ![]() | ![]() |
- Sugar cubes are stacked in an arrangement as shown by Figure 1. This stack has
4
layers and a total of30
cubes. How many cubes are there in a similar stack with467
layers? - The arrangement in Figure 2 has
4
layers and84
cubes. How many cubes are there in a similar stack with812
layers? - The stack in Figure 3 has
3
"layers" and36
cubes in total. How many cubes are there in a similar stack with68
"layers"?
Solutions:
+/(⍳467)*2 34058310
+/(¯1+2×⍳812)*2 713849500
+/(⍳68)*3 5503716
4.#
Rewrite the following expressions so that they do not use parentheses.
(÷a)×b
(÷a)÷b
(a+b)-5
(a+b)+5
Solutions:
b×÷a
orb÷a
÷a×b
¯5+a+b
a+b+5