Kalibracija laserja

Rok za oddajo: sreda, 29. december 2021, 15.00

Marsovske ladje se zdaj boljše skrivajo in SOVA jim ni več kos. Na srečo je priskočila na pomoč moskovska sadjarska zadruga MOSSAD z dvema funkcijama.

  • r(koordinate) vrne polmer kroga, katerega središče je na podanih koordinatah. Koordinati podamo s terko, na primer r((5.25, 8.625)).
  • notranji(koordinate) vrne množico središč vseh krogov, ki se nahajajo neposredno znotraj kroga s podanim središčem. Pri krogih na spodnji sliki bo za krog s središčem v (0, 10) vrnil le tri (večje) kroge, ne pa dveh, ki sta potem še bolj znotraj.

Tidve funkciji sta podani. Kako delujeta, ni pomembno; MOSSAD-u bi bilo ljubše, če ne veš.

Zaradi konstrukcijskih zahtev (vsak krog je pritrjen z vijakom skozi središče in na Marsu nimajo vijakov, ki bi bili daljši od debeline dveh plošč) se nikoli ne zgodi, da bi imela dva kroga isto središče.

Pred napadom bo potrebno natančno kalibrirati moč laserjev in jih pravilno usmeriti. Moč laserja mora biti enaka površini vseh krogov, ki sestavljajo ladjo. Laser je potrebno usmeriti v središče najmanjšega kroga, ki sestavlja ladjo.

Obvezna naloga

Napiši naslednji funkciji.

  • povrsina(koord) vrne skupno površino vseh krogov, ki sestavljajo ladjo s središčem, podanim s terko koord.

  • najmanjsi(koord) vrne središče najmanjšega izmed krogov, ki sestavljajo ladjo.

To je vaja iz rekurzije, torej morata biti funkciji rekurzivni. V izogib skušnjavam in čudnim rešitvam, dodatne funkcije niso dovoljene, funkciji pa ne smeta imeti dodatnih argumentov (niti s privzetimi vrednostmi).

Dodatna naloga

Funkciji naj bosta napisani v eni vrstici.

Na ta način sta pravzaprav preprostejši. Pozorno preberi dokumentacijo funkcije min.

O testih

Testi uporabljajo tri postavitve ladij. Kažejo jih spodnje slike, le da se vzorec pri drugi in tretji nadaljuje, tako da imamo tam tisoče in tisoče krogov.


Martian ships are now hiding better and the Slovenian Intelligence Agency SOVA can no longer track them. Fortunately, a Moscow Fruit company MOSSAD provided their equipment and two functions.

  • r(koordinate) returns the radius of a circle with the center at the given coordinates. Coordinates are specified as, e.g. r((5.25, 8.625)).
  • notranji(koordinate) return the set of centers of all circles directly inside the circle with the given center. For instance, for the circle at (0, 10) in the above picture, the function returns three circles and not all five (that would include those that are not directly within circle at (0,10)).

These two functions are given. How they work is unimportant; MOSSAD would appreciate if you don't stick your nose where it doesn't belong.

Due to constructional limitations (each circle is fixed using a screw through its center and Martians do not have screws longer than the depth of two plates) no two circles share the same center.

Before commencing the attack, we'll need to calibrate the power of lasers and target them. The power must equal the total area of all circles belonging to the ship. The laser must target the center of the smallest circle.

Mandatory task

Write the following functions.

  • povrsina(koord) return the total surface of all circles belonging to the ship whose outer circle's center is at the given coordinates.

  • najmanjsi(koord) return the center of the smallest circle in the ship (including indirect circles).

This homework is about recursion, thus functions must be recursive. To avoid temptations and strange solutions, extra functions are forbidden, and the two function mustn't have any additional arguments (not even with default values).

Extra task

Implement these two functions in a single line (each).

This is actually easier. Carefully read documentationa about function min.

About tests

Tests use three configurations of ships, as shown in the above images. The pattern in the second and the third continues, so we may have thousands and thousands of circles.