PROG0310 - Peninsula

An island is a piece of land that is surrounded on all sides by water. When a piece of land is not an island, because it is joined to the continent (small area compared to the size of the land), it is called a peninsula. In all other cases it is said that the land is part of the mainland.

stromboli
Stromboli is a small volcanic island in the Tyrrhenian Sea and is part of the Aeolian or Lipari Islands, a volcanic archipelago north of Sicily, Italy. The island has an area of 12.6 square kilometres and is 918 metres high.
iberisch schiereiland
The Iberian Peninsula is a part of Europe that is located south of the Pyrenees. The peninsula is surrounded by the Mediterranean Sea, the Atlantic Ocean and the Bay of Biscay. The area is 582,530 km².

Assignment

In this exercise we work with text files, each containing a detail of a map. This detailed map is described on the basis of a number of text lines that all have the same length. The map contains a continental landmass of which pieces are marked with a hash (#) and a second land mass of which the parts are designated by the letter S. Pieces of sea are indicated by a space. Asked is to determine whether the land mass that is designated by the letters S is an island, a peninsula or part of the continent. To do this, just follow these steps:

  • Write a function landmass to which the location of a text file must be passed as an argument. This text file should contain a detailed map as described above. The function must return a tuple $(r,o)$, where $r$ represents the number of touch points that the mainland has with the land mass that is designated by the letters S. This is calculated as the number of pieces marked with a hash that touch on at least one piece marked with the letter S above, below, left or right. The value $o$ represents the surface of the landmass that is designated by the letters S, expressed as the total number of pieces that are marked with the letter S.
  • Use the function landmass to write a function landtype that can be used to determine if a land mass is an island, a peninsula or a part of the mainland. This function has two parameters: i) a parameter to which the location must be passed from a text file that refers to a detailed map as described above, and ii) an optional parameter ratio to which a floating point number (default 0.05) can be passed . If the landmass that is designated by the letters S has no points of contact with the mainland, the function must return a string with the text island. Otherwise, it must be determined whether the ratio of the number of touch points divided by the area of the land is less than or equal to the value of the parameter ratio. If that is the case, a string with the text peninsula should be returned. Otherwise, a string with the text mainland must be returned.

Example

In the following interactive session we assume that the files landmass1.txt, landmass2.txt and landmass3.txt  are in the current directory.

>>> landmass('landmass1.txt')
(0, 196)
>>> landmass('landmass2.txt')
(6, 169)
>>> landmass('landmass3.txt')
(8, 45)

>>> landtype('landmass1.txt')
'island'
>>> landtype('landmass2.txt')
'peninsula'
>>> landtype('landmass3.txt')
'mainland'
>>> landtype('landmass3.txt', ratio=0.2)
'peninsula'

Een eiland is een stuk land dat aan alle kanten omgeven is door water. Wanneer een stuk land net geen eiland vormt omdat het via een smalle landengte (smal in vergelijking met de grootte van het stuk land) verbonden is met het vasteland, dan spreekt men van een schiereiland. In alle andere gevallen zegt men dat het stuk land deel uitmaakt van het vasteland.

stromboli
Stromboli is een klein vulkaaneiland in de Tyrreense Zee en maakt deel uit van de Eolische of Liparische eilanden, een vulkanische archipel ten noorden van Sicilië, Italië. Het eiland heeft een oppervlakte van 12,6 vierkante kilometer, en is 918 meter hoog.
iberisch schiereiland
Het Iberisch Schiereiland is een deel van Europa dat zich ten zuiden van de Pyreneeën bevindt. Het schiereiland wordt omgeven door de Middellandse Zee, de Atlantische Oceaan en de Golf van Biskaje. De oppervlakte bedraagt 582.530 km².

Opgave

In deze opgave werken we met tekstbestanden die telkens een detail van een landkaart bevatten. Deze detailkaart wordt beschreven aan de hand van een aantal tekstregels die allemaal dezelfde lengte hebben. De kaart bevat een landmassa vasteland waarvan de stukken worden aangeduid met hekjes (#) en een tweede landmassa waarvan de stukken worden aangeduid met de letter S. Stukken zee worden aangeduid met een spatie. Gevraagd wordt om te bepalen of de landmassa die wordt aangeduid met de letters S een eiland, een schiereiland of een deel van het vasteland voorstelt. Hiervoor ga je als volgt te werk:

  • Schrijf een functie landmassa waaraan de locatie van een tekstbestand als argument moet doorgegeven worden. Dit tekstbestand moet een detailkaart bevatten zoals die hierboven werd beschreven. De functie moet als resultaat een tuple $(r, o)$ teruggeven. Hierbij stelt $r$ het aantal raakpunten voor die het vasteland heeft met de landmassa die wordt aangeduid met de letters S. Dit wordt berekend als het aantal stukken aangeduid met een hekje, die boven, onder, links of rechts raken aan minstens één stuk aangeduid met de letter S. De waarde $o$ stelt de oppervlakte van de landmassa voor die wordt aangeduid met de letters S, uitgedrukt als het totaal aantal stukken die met de letter S gemarkeerd worden.
  • Gebruik de functie landmassa om een functie landsoort te schrijven die kan gebruikt worden om te bepalen of een landmassa een eiland, een schiereiland of een deel van het vasteland voorstelt. Deze functie heeft twee parameters: i) een parameter waaraan de locatie moet doorgegeven worden van een tekstbestand dat verwijst naar een detailkaart zoals die hierboven werd beschreven en ii) een optionele parameter verhouding waaraan een floating point getal (standaardwaarde 0,05) kan doorgegeven worden. Indien de landmassa die wordt aangeduid met de letters S geen raakpunten heeft met het vasteland, dan moet de functie een string met de tekst eiland teruggeven. Anders moet nagegaan worden of de verhouding van het aantal raakpunten gedeeld door de oppervlakte van het stuk land kleiner of gelijk is aan de waarde van de parameter verhouding. Als dat het geval is moet een string met de tekst schiereiland teruggegeven worden. Anders moet een string met de tekst vasteland teruggegeven worden.

Voorbeeld

Bij onderstaande interactieve sessie gaan we ervan uit dat de bestanden landmassa1.txt, landmassa2.txt en landmassa3.txt zich in de huidige directory bevinden.

>>> landmassa('landmassa1.txt')
(0, 196)
>>> landmassa('landmassa2.txt')
(6, 169)
>>> landmassa('landmassa3.txt')
(8, 45)

>>> landsoort('landmassa1.txt')
'eiland'
>>> landsoort('landmassa2.txt')
'schiereiland'
>>> landsoort('landmassa3.txt')
'vasteland'
>>> landsoort('landmassa3.txt', verhouding=0.2)
'schiereiland'

Added by:Peter Dawyndt
Date:2013-01-20
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.