Logo notas.itmens

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:

  1. The highest daily temperature
  2. The lowest daily temperature
  3. The range of (difference between the largest and the smallest) temperatures
  4. Each temperature rounded to the nearest whole number

Solutions:

  1.       ⌈/t_allweek
    14.2
  2.       ⌊/t_allweek
    6.7
  3.       (⌈/t_allweek)-⌊/t_allweek
    7.5
  4.       ⌈ t_allweek - 0.5
    12 9 10 14 7 12 9

2.#

A Mathematical Notation

Use APL to evaluate the following

  1. \(\prod_{n=1}^{12} n\).
  2. \(\sum_{n=1}^{17} n^2\).
  3. \(\sum_{n=1}^{100}2n\).
  4. \(\sum_{n=1}^{100} (2n-1)\).
  5. In TMN, the following expression is equal to 0, why does the following return 70 in APL?
      84 - 12 - 1 - 13 - 28 - 9 - 6 - 15  
70

Solutions:

  1.       ×/⍳12
    479001600
  2.       +/(⍳17)*2
    1785
  3.       +/2×⍳100
    10100
  4.       +/(2×⍳100)-1
    10000
  5. This becomes
 (84 - (12 - (1 - (13 - (28 - (9 - (6 - 15)))))))

Hence effectively \(84-12+1-13+28-9+6-15\)

3. Pyramid Schemes#

Article Image
Figure 1. Stacked sugar cubes
Article Image
Figure 2. Differently stacked sugar cubes
Article Image
Figure 3. This is just a waste of sugar cubes by now...
  1. Sugar cubes are stacked in an arrangement as shown by Figure 1. This stack has 4 layers and a total of 30 cubes. How many cubes are there in a similar stack with 467 layers?
  2. The arrangement in Figure 2 has 4 layers and 84 cubes. How many cubes are there in a similar stack with 812 layers?
  3. The stack in Figure 3 has 3 "layers" and 36 cubes in total. How many cubes are there in a similar stack with 68 "layers"?

Solutions:

  1.       +/(⍳467)*2
    34058310
  2.       +/(¯1+2×⍳812)*2
    713849500
  3.       +/(⍳68)*3
    5503716

4.#

Rewrite the following expressions so that they do not use parentheses.

  1. (÷a)×b
  2. (÷a)÷b
  3. (a+b)-5
  4. (a+b)+5

Solutions:

  1. b×÷a or b÷a
  2. ÷a×b
  3. ¯5+a+b
  4. a+b+5