Skip to content

2017-4: Slice(s) of Pie(s)

Write a function that calculates and returns the areas of 0 or more pie slices. The left argument is 0 or more angles (in degrees). The right argument is 0 or more pie diameters. If the number of angles and diameters are not equal to each other (and neither is a single number), a LENGTH ERROR should be generated.

💡 Hint: If you use APL properly, you should not have to check for the length of either argument – it will just work.

Examples:

      60 (your_function) 12 
18.84955592 
      0 (your_function) 12  ⍝ 0 degree slice
0
      60 (your_function) 0  ⍝ 0 diameter pie
0
      60 (your_function) 9 12 15  ⍝ 60 degree slices of 3 different pies
10.60287521 18.84955592 29.45243113 
      60 90 120 (your_function) 12 ⍝ 3 different size slices of the same pie 
18.84955592 28.27433388 37.69911184
      60 90 120 (your_function) 9 12 15 ⍝ different sizes of different pies
10.60287521 28.27433388 58.90486225 
      60 90 120 (your_function) 9 12 ⍝ 3 slices, 2 pies? 
LENGTH ERROR
your_function ←

Solutions

Video Thumbnail YouTube

Chat transcript Code on GitHub