Chess board distance $\max( x_0-x_1, y_0-y_1 )$

Vergelijkbare documenten
The colour of a pixel in a bit map picture can be presented in different ways. For this assignment, we distinguish two categories:

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE. Toets Inleiding Kansrekening 1 8 februari 2010

Country recognition. Assignment

Add the standing fingers to get the tens and multiply the closed fingers to get the units.

Classification of triangles

Daylight saving time. Assignment

Chromosomal crossover

Christmas party. Preparation. Assignment

The genesis of the game is unclear. Possibly, dominoes originates from China and the stones were brought here by Marco Polo, but this is uncertain.

SAMPLE 11 = + 11 = + + Exploring Combinations of Ten + + = = + + = + = = + = = 11. Step Up. Step Ahead

Calculator spelling. Assignment

After that, the digits are written after each other: first the row numbers, followed by the column numbers.

ALGORITMIEK: answers exercise class 7

L.Net s88sd16-n aansluitingen en programmering.

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

MyDHL+ Van Non-Corporate naar Corporate

Earth Similarity Index

Opgave 2 Geef een korte uitleg van elk van de volgende concepten: De Yield-to-Maturity of a coupon bond.

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

Genetic code. Assignment

L.Net s88sd16-n aansluitingen en programmering.

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Examination 2DL04 Friday 16 november 2007, hours.

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

i(i + 1) = xy + y = x + 1, y(1) = 2.

B1 Woordkennis: Spelling

Engels op Niveau A2 Workshops Woordkennis 1

The mitochondrial genome has bases and codes for 37 genes: 13 polypeptides, 22 trnas and 2 ribosomal RNAs.

ANGSTSTOORNISSEN EN HYPOCHONDRIE: DIAGNOSTIEK EN BEHANDELING (DUTCH EDITION) FROM BOHN STAFLEU VAN LOGHUM

The first line of the input contains an integer $t \in \mathbb{n}$. This is followed by $t$ lines of text. This text consists of:

(1) De hoofdfunctie van ons gezelschap is het aanbieden van onderwijs. (2) Ons gezelschap is er om kunsteducatie te verbeteren

Quality requirements concerning the packaging of oak lumber of Houthandel Wijers vof ( )

Preschool Kindergarten

Luister alsjeblieft naar een opname als je de vragen beantwoordt of speel de stukken zelf!

z x 1 x 2 x 3 x 4 s 1 s 2 s 3 rij rij rij rij

Solar system. Assignment

General info on using shopping carts with Ingenico epayments

Four-card problem. Input

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE. Toets Inleiding Kansrekening 1 7 februari 2011

LDA Topic Modeling. Informa5ekunde als hulpwetenschap. 9 maart 2015

Pure Bending. A beam satisfying above given requirements are shown below: Why this surface is called neutral will be explained later in the lecture.

Installatie van Windows 10 op laptops. Windows 10 installation on laptops

Meetkunde en Lineaire Algebra

Introductie in flowcharts

Handleiding Zuludesk Parent

Centre of mass. Define a class Atom that supports the following methods:

Bijlage 2: Informatie met betrekking tot goede praktijkvoorbeelden in Londen, het Verenigd Koninkrijk en Queensland

Assignment. Example. is surrounded by exactly 3 coloured cells.

S e v e n P h o t o s f o r O A S E. K r i j n d e K o n i n g

Ae Table 1: Aircraft data. In horizontal steady flight, the equations of motion are L = W and T = D.

Ius Commune Training Programme Amsterdam Masterclass 15 June 2018

Hidato. Assignment. A hidato (left) and its solution (right).

04/11/2013. Sluitersnelheid: 1/50 sec = 0.02 sec. Frameduur= 2 x sluitersnelheid= 2/50 = 1/25 = 0.04 sec. Framerate= 1/0.

Find Neighbor Polygons in a Layer

LONDEN MET 21 GEVARIEERDE STADSWANDELINGEN 480 PAGINAS WAARDEVOLE INFORMATIE RUIM 300 FOTOS KAARTEN EN PLATTEGRONDEN

Chapter 4 Understanding Families. In this chapter, you will learn

Esther Lee-Varisco Matt Zhang

MyDHL+ ProView activeren in MyDHL+

The 15 puzzle invented by Noyes Chapman consisted of a $4 \times 4$ grid of which the field are numbered from 1 to 15.

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Tentamen Calculus B (2WBB1) op maandag 28 januari 2013, 14:00 17:00 uur

Meetkunde en Lineaire Algebra

Ius Commune Training Programme Amsterdam Masterclass 16 June 2016

Settings for the C100BRS4 MAC Address Spoofing with cable Internet.

Het beheren van mijn Tungsten Network Portal account NL 1 Manage my Tungsten Network Portal account EN 14

Ontpopping. ORGACOM Thuis in het Museum

RECEPTEERKUNDE: PRODUCTZORG EN BEREIDING VAN GENEESMIDDELEN (DUTCH EDITION) FROM BOHN STAFLEU VAN LOGHUM

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE. Toets Inleiding Kansrekening 1 22 februari 2013

Ius Commune Training Programme Amsterdam Masterclass 22 June 2017

FRAME [UPRIGHT MODEL] / [DEPTH] / [HEIGHT] / [FINISH] TYPE OF BASEPLATE P Base plate BP80 / E alternatives: ZINC finish in all cases

Example. >>> rowkey('u') 1 >>> rowkey('a') 2 >>> rowkey('z') 3 >>> rowkey('?')

Cambridge Assessment International Education Cambridge International General Certificate of Secondary Education. Published

NMOZTMKUDLVDKECVLKBVESBKHWIDKPDF-WWUS Page File Size 9,952 KB 29 May, 2016

Group work to study a new subject.

Het Effect van Verschil in Sociale Invloed van Ouders en Vrienden op het Alcoholgebruik van Adolescenten.

Tentamen Objectgeorienteerd Programmeren

Travel Survey Questionnaires

Hertentamen 8D040 - Basis beeldverwerking

Meetkunde en Lineaire Algebra

Example. >>> airmap = Map() >>> airmap.eruption(0, 0) >>> airmap.ashcloud {(0, 0)} >>> airmap.spread()

0515 DUTCH (FOREIGN LANGUAGE)

CBSOData Documentation

Graphic Design. Keuzevak GD1. Raul Martinez-Orozco / raul@thecombine.nl)

Geachte Bezoeker, Adresgegevens

Basic operations Implementation options

Academisch schrijven Inleiding

Take Home Assignment. Introduction to Modeling. Week 7.

Firewall van de Speedtouch 789wl volledig uitschakelen?

CHROMA STANDAARDREEKS

Online Resource 1. Title: Implementing the flipped classroom: An exploration of study behaviour and student performance

Davide's Crown Caps Forum

MyDHL+ Uw accountnummer(s) delen

Huiswerkopgave Inleiding Modelleren Hoofdstuk 7

Meetkunde en Lineaire Algebra

Concept of Feedback. P.S. Gandhi Mechanical Engineering IIT Bombay

It s all about the money Group work

Vogelhuisje. Samenvatting. Aan te pakken problemen: Context. Doelen. Aansluiting bij de werkelijkheid. Vaardigheden

Buzzword bingo Buzzword bingo bul shit bingo

De grondbeginselen der Nederlandsche spelling / Regeling der spelling voor het woordenboek der Nederlandsche taal (Dutch Edition)

The upside down Louisa tutorial by Dorothée: Noortjeprullemie.blogspot.be Written for Compagnie M.: m.com

Registratie- en activeringsproces voor de Factuurstatus Service NL 1 Registration and activation process for the Invoice Status Service EN 10

Transcriptie:

Trail If you look up a route between two points $p_0$ and $p_n$ with Google Maps, the itinerary is given based on a number of intermediate points $$p_0, p_1, p_2, \ldots, p_n$$ If we write the distance between two consecutive points $p_i$ and $p_{i+1}$ as $d(p_i, p_{i+1})$, the total distance of the route equals $$\sum_{i=0}^{n - 1} d(p_i, p_{i+1})$$ If the route ends back in its starting point, we have to add the distance $d(p_n, p_0)$ at the end. In this assignment, we represent the co-ordinates of a point $p$ as a tuple $(x, y)$. Based on this representation, the distance between two points $p_0 = (x_0, y_0)$ and $p_1 = (x_1, y_1)$ can be defined in different ways. The most intuitive distance is the Euclidean distance, that corresponds with the distance from a bird's-eye view. In practice, however, this distance isn't always as useful. T h e Manhattan-distance is an alternative distance that gets its name from the typical street pattern of Manhattan. There, all streets either stand perpendicular with regard to each other or they are parallel. In this case, the distance is given as the sum of the subtraction of the $x$ coordinates and the subtraction of the $y$ co-ordinates. This is equal to the road you would take from one point to another if you were only allowed to walk parallel with the $x$ and $y$ axis. T h e Chebyshev distance or the chessboard distance gets its name from the fact that it corresponds with the amount of moves a chess piece king needs to cross a discrete grid. This number is given by the maximum of the subtraction of the $x$ co-ordinates and the subtraction of the $y$ co-ordinates. In the table below you will find an overview of the various formulas for the distance between two points $(x_0, y_0)$ en $(x_0, y_0)$ as defined by the linear measures above. name Euclidian distance formula $\sqrt{(x_0-x_1)^2 + (y_0-y_1)^2}$ Manhattan distance $ x_0-x_1 + y_0-y_1 $ Chess board distance $\max( x_0-x_1, y_0-y_1 )$ Preparation In Python, functions are objects themselves, which is the reason why you can use them like any other object. In particular, you can appoint functions to variables or pass them as an argument to other function. Look at the three functions below as an example. def repeat(value, function, amount): for i in range(amount): value = function(amount) return value def increment(value):

return value + 1 def decrement(value): return value - 1 Below you will find an example of how these functions can be used. Verify how Python reacts if you consecutively execute the following instruction within the interactive Python session in which you first have the functions above defined. Make sure you understand why you get a certain value and what happens exactly in the interactive session before moving on to the actual assignment. >>> increment(5) >>> decrement(101) >>> repeat(5, increment, 3) >>> repeat(5, decrement, 3) >>> repeat(5, decrement, increment(3)) Assignment In this assignment, we represent a point as a tuple of two real numbers the indicate the $x$ and $y$ co-ordinates of a point in a surface. Asked: 1. Write three functions euclidean, manhattan and chessboard that correspond with the concepts of the same name for the concept distance as they are defined in the table. To each of these functions two points should be given as an argument. The functions must print as a result the distance between the points given, in accordance with the distance formula. 2. Write a function track. This function has an obligatory parameter points to which a list of points must be given the function must print the total distance if we travel from one point on the list to another. Apart from the obligatory parameter, the function also has two optional parameters: cycle: a Boolean value can be given to this parameter, indicating whether the end of the tour is equal to its starting point (True) or not (False). The standard value of this parameter is False. distance: a distance function can be given to this parameter which is used for the calculation of the total distance between two consecutive points. If no value has been given for this distance, the Euclidean distance is used as a standard. Example >>> euclidean((42.36, 56.78), (125.65, 236.47)) 198.05484139500354 >>> manhattan((42.36, 56.78), (125.65, 236.47)) 262.98 >>> chessboard((42.36, 56.78), (125.65, 236.47)) 179.69 >>> track([(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)]) 21.861273201261746 >>> track(cycle=true, points=[(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)]) 42.60956710702662 >>> track([(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)], distance=manhattan) 23.45 >>> track([(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)], cycle=true, distance=manhattan) 45.42

Als je een route tussen twee punten $p_0$ en $p_n$ opzoekt via Google Maps, dan wordt de routebeschrijving gegeven op basis van een aantal tussenpunten $$p_0, p_1, p_2, \ldots, p_n$$ Als we de afstand tussen twee opeenvolgende punten $p_i$ en $p_{i+1}$ noteren als $d(p_i, p_{i+1})$, dan is de totale afstand van de route gelijk aan $$\sum_{i=0}^{n - 1} d(p_i, p_{i+1})$$ Als de route terug eindigt op zijn beginpunt, dan moeten we hier finaal nog de afstand $d(p_n, p_0)$ bij optellen. In deze opgave stellen we de coördinaten van een punt $p$ voor als een tuple $(x, y)$. Op basis van deze voorstelling kan de afstand tussen twee punten $p_0 = (x_0, y_0)$ en $p_1 = (x_1, y_1)$ op verschillende manieren gedefinieerd worden. De meest inituitieve afstand is de Euclidische afstand, die overeenkomt met de afstand in vogelvlucht. In de praktijk is deze afstand echter niet altijd even bruikbaar. D e Manhattan-afstand is een alternatieve afstand die zijn naam dankt aan het typische stratenpatroon van Manhattan. Daar staan alle straten ofwel loodrecht op elkaar of lopen ze evenwijdig met elkaar. In dit geval wordt de afstand gegeven als de som van het verschil van de $x$-coördinaten en het verschil van de $y$-coördinaten. Dit komt overeen met de weg die je zou afleggen om van het ene punt naar het andere punt te gaan als je enkel evenwijdig met de $x$as en de $y$-as zou mogen wandelen. D e Chebyshev-afstand of de schaakbordafstand dankt zijn naam aan het feit dat ze op een discreet rooster overeenkomt met het aantal zetten die het schaakstuk koning nodig heeft om van het ene punt naar het andere punt te gaan. Dit aantal wordt gegeven door het maximum van het verschil van de $x$-coördinaten en het verschil van de $y$-coördinaten. In onderstaande tabel vind je een overzicht van de verschillende formules voor de afstand tussen twee punten $(x_0, y_0)$ en $(x_0, y_0)$ zoals die wordt gedefinieerd door bovenvernoemde afstandsmaten. naam formule Euclidische afstand $\sqrt{(x_0-x_1)^2 + (y_0-y_1)^2}$ Manhattan-afstand $ x_0-x_1 + y_0-y_1 $ schaakbordafstand $\max( x_0-x_1, y_0-y_1 )$ Voorbereiding In Python zijn functies zelf ook objecten, waardoor je ze kunt gebruiken zoals alle andere objecten. In het bijzonder kun je functies toekennen aan variabelen of doorgeven als argument aan andere functies. Bekijk bijvoorbeeld onderstaande drie functies. def herhalen(waarde, functie, aantal): for i in range(aantal): waarde = functie(waarde) return waarde def verhogen(waarde):

return waarde + 1 def verlagen(waarde): return waarde - 1 Hieronder staat een voorbeeld van hoe deze functies gebruikt kunnen worden. Ga na hoe Python reageert als je achtereenvolgens de volgende instructies uitvoert binnen een interactieve Python sessie waarin je eerst zorgt dat bovenstaande functies gedefinieerd werden. Verzeker jezelf ervan dat je goed begrijpt waarom je een bepaalde waarde krijgt en wat er juist gebeurt in de interactieve sessie vooraleer je verder gaat met de eigenlijke opgave. >>> verhogen(5) >>> verlagen(101) >>> herhalen(5, verhogen, 3) >>> herhalen(5, verlagen, 3) >>> herhalen(5, verlagen, verhogen(3)) Opgave In deze opgave stellen we een punt voor als een tuple van twee reële getallen die de $x$- en de $y$-coördinaat van een punt in het vlak voorstellen. Gevraagd wordt: 1. Schrijf drie functies euclidisch, manhattan en schaakbord die corresponderen met de gelijknamige concepten voor het begrip afstand zoals die in bovenstaande tabel gedefinieerd werden. Aan elk van deze functies moeten twee punten als argument doorgegeven worden. De functies moeten als resultaat telkens de afstand teruggeven tussen de twee gegeven punten, overeenkomstig de corresponderende afstandsformule. 2. Schrijf een functie parcours. Deze functie heeft een verplichte parameter punten waaraan een lijst van punten moet doorgegeven worden. De functie moet de totale afstand teruggeven die afgelegd wordt als men achtereenvolgens alle punten uit de lijst aandoet. Naast deze verplichte parameter, heeft de functie ook nog twee optionele parameters: cycle: aan deze parameter kan een Booleaanse waarde doorgegeven worden die aangeeft of men op het einde van de rit terugreist naar het beginpunt (True) of niet (False). De standaardwaarde van deze parameter is False. afstand: aan deze parameter kan een afstandsfunctie doorgegeven worden, die bij de berekening van de totale afstand gebruikt wordt om de afstand tussen twee opeenvolgende punten te bepalen. Als geen waarde wordt doorgegeven voor deze afstand, dan wordt standaard de Euclidische afstand gebruikt. Voorbeeld >>> euclidisch((42.36, 56.78), (125.65, 236.47)) 198.05484139500354 >>> manhattan((42.36, 56.78), (125.65, 236.47)) 262.98 >>> schaakbord((42.36, 56.78), (125.65, 236.47)) 179.69 >>> parcours([(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)]) 21.861273201261746 >>> parcours(cycle=true, punten=[(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)]) 42.60956710702662 >>> parcours([(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)], afstand=manhattan)

23.45 >>> parcours([(6.59, 6.73), (4.59, 5.54), (5.33, -13.98)], cycle=true, afstand=manhattan) 45.42