Roman numerals. Assignment

Vergelijkbare documenten
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.

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

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

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

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

Calculator spelling. Assignment

Genetic code. Assignment

Country recognition. Assignment

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

Daylight saving time. Assignment

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

Solar system. Assignment

Classification of triangles

Chromosomal crossover

MyDHL+ Van Non-Corporate naar Corporate

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

General info on using shopping carts with Ingenico epayments

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

L.Net s88sd16-n aansluitingen en programmering.

Buzzword bingo Buzzword bingo bul shit bingo

Introductie in flowcharts

L.Net s88sd16-n aansluitingen en programmering.

Preschool Kindergarten

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

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

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

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

ALGORITMIEK: answers exercise class 7

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:

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

Earth Similarity Index

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

Christmas party. Preparation. Assignment

Four-card problem. Input

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

8+ 60 MIN Alleen te spelen in combinatie met het RIFUGIO basisspel. Only to be played in combination with the RIFUGIO basicgame.

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

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

Demultiplexing reads FASTA format genome sequencing reads run

DBMS. DataBase Management System. Op dit moment gebruiken bijna alle DBMS'en het relationele model. Deze worden RDBMS'en genoemd.

Tentamen Objectgeorienteerd Programmeren

DALISOFT. 33. Configuring DALI ballasts with the TDS20620V2 DALI Tool. Connect the TDS20620V2. Start DALISOFT

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

Plotten. technisch tekenwerk AUTOCAD 2000

Esther Lee-Varisco Matt Zhang

Intermax backup exclusion files

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

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGES. Tentamen Inleiding Kansrekening 1 27 maart 2013

Handleiding Zuludesk Parent

liniled Cast Joint liniled Gietmof liniled Castjoint

Data Handling Ron van Lammeren - Wageningen UR

BE Nanoregistry Annual Public Report

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

Homework assignment 7 (Intensionality)

Find Neighbor Polygons in a Layer

I.S.T.C. Intelligent Saving Temperature Controler

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

Today s class. Digital Logic. Informationsteknologi. Friday, October 19, 2007 Computer Architecture I - Class 8 1

Handleiding Installatie ADS

AE1103 Statics. 25 January h h. Answer sheets. Last name and initials:

Group work to study a new subject.

CTI SUITE TSP DETAILS

VOORSTEL TOT STATUTENWIJZIGING UNIQURE NV. Voorgesteld wordt om de artikelen 7.7.1, 8.6.1, en te wijzigen als volgt: Toelichting:

Basic operations Implementation options

MyDHL+ ProView activeren in MyDHL+

Firewall van de Speedtouch 789wl volledig uitschakelen?

Alle opgaven tellen even zwaar, 10 punten per opgave.

Large word squares are dramatically harder to make than small ones. To date, the largest anyone has managed to find are composed of 9-letter words:

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

Example. Dutch language lesson. Dutch & German Language Education Pieter Wielick

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

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

Uitgifte nieuwe circulatie- en herdenkingsmunten

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

LDAP Server on Yeastar MyPBX & tiptel 31xx/32xx series

Map showing countries shaded by their position in the Happy Planet Index (2006). The highestranked countries are bright green, the lowest are brown.

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

Karen J. Rosier - Brattinga. Eerste begeleider: dr. Arjan Bos Tweede begeleider: dr. Ellin Simon

OPEN TRAINING. Onderhandelingen met leveranciers voor aankopers. Zeker stellen dat je goed voorbereid aan de onderhandelingstafel komt.

Deel 1: schriftelijk deel


Meetkunde en Lineaire Algebra

Ontpopping. ORGACOM Thuis in het Museum

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

Bin packing and scheduling

Workflow en screenshots Status4Sure

OVERGANGSREGELS / TRANSITION RULES 2007/2008

DBMS SQL. Relationele databases. Sleutels. DataBase Management System. Inleiding relationele databases. bestaan uit tabellen.

Datamodelleren en databases 2011

MyDHL+ Uw accountnummer(s) delen

Citation for published version (APA): Oderkerk, A. E. (1999). De preliminaire fase van het rechtsvergelijkend onderzoek Nijmegen: Ars Aequi Libri

NCTS - INFORMATIE INZAKE NIEUWIGHEDEN VOOR 2010

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

B1 Woordkennis: Spelling

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

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

TOEGANG VOOR NL / ENTRANCE FOR DUTCH : lator=c&camp=24759

Interface tussen Stuurbediening en Sony autoaudio

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

This appendix lists all the messages that the DRS may send to a registrant's administrative contact.

Transcriptie:

Roman numerals In ancient Rome a numeric system was used based on Roman numerals for the representation of integers. This numeric system is not a positional system, but an additive system in which the value of the integer is determined as the total sum of the digits used in the representation. The numbers one to ten can be expressed as Roman numerals as follows: I, II, III, IV, V, VI, VII, VIII, IX a n d X. Negative numbers and the zero value cannot be represented in the Roman numeric system. The Roman numeric system has largely become in disuse since the fourteenth century, in favor of the decimal numeric system that is based on Arab digits. However, Roman numeral are still in common use today in some applications, such as in numbering kings having the same name (e.g. Louis XIV of France), in numbering annual events and in numbering centuries in some countries (e.g. XIXe siècle). In the Roman numeric system, integers are represented using symbols, the actual digits, where each symbol has a certain value independent of the position where it occurs in the integer representation. The symbols used in the Roman numeric system are: symbol value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 The order of the Roman digits in the integer representation is not random. The values of the individual digits are added, except if a symbol with a lower value is immediately followed by a symbol with a higher value: in that case, the lower value is subtracted instead of being added. The rules for representing integers using Roman numerals has been very loose in Ancient times. As such, in its credits the BBC used the typographically more elegant representation MIM for the year 1999, instead of MCMXCIX. Assignment PEP 313 was a proposal to extend the Python programming language with support for the representation of Roman numerals as a literal data type. This proposal was rejected by Guido Van Rossum, who created the Python language and is nicknamed the Benevolent Dictator for Life (BDFL). However, since it is possible to extend Python by defining new data types, it is possible that we create or own data type to represent Roman numerals in Python. In order to do so, you proceed as follows: Write a function roman2arab that converts a given string that only contains Roman digits (upper case or lower case) into the integer representation of the same number. Write a function arab2roman that converts a given integer into the string representation of the same number using Roman digits (upper case only). This representation should be determined by traversing the following table from left to right. As long as the remaining

integer value is larger then or equal to the current value from the table, the corresponding combination of Roman digits is appended to the Roman numeral. The current value is then subtracted from the integer value. As soon as the current value is lower then the remaining integer value, we traverse to the next position in the table. M CM D CD C XC L XL X IX V IV I 1000 900 500 400 100 90 50 40 10 9 5 4 1 Define a class Roman that can be used to represent Roman numerals in Python. New objects of this class can be initialized either by an integer value $i$ (where $1 \leq i < 4000$) or by a string $s$ that only contains Roman digits (upper case and/or lower case). All other values passed while initializing an object of the class should result in an AssertionError being thrown with the message invalid roman numeral. The conversion of a Roman numeral to a string obtained using the built-in functions str() and repr() should give the integer value represented in Roman digits (upper case, as generated by the function arab2roman) and the converstion to an integer obtained using the built-in function int() should give the integer value in Arab digits. Make sure that the sum, difference and product of two Roman numerals can be computed using the operators +, - and *. The evaluation of these operations should result in a new Roman numeral. Example >>> roman2arab('mdccccx') >>> arab2roman() 'MCMX' >>> int(roman('mdccccx')) >>> int(roman('mcmliv')) 1954 >>> int(roman('mcmxc')) 1990 >>> rsum = Roman('MDCCCCX') + Roman('MCMXC') >>> isinstance(rsum, Roman) >>> print(rsum) MMMCM >>> difference = Roman('MCMXC') - Roman('MDCCCCX') >>> isinstance(difference, Roman) >>> str(difference) 'LXXX' >>> product = Roman('CMX') * Roman('III') >>> isinstance(product, Roman) >>> product MMDCCXXX >>> print(roman('mdccccx')) MCMX >>> Roman(1234) MCCXXXIV >>> Roman(4321)

AssertionError: invalid roman numeral >>> Roman('ABCDEF') AssertionError: invalid roman numeral >>> Roman(3.14) AssertionError: invalid roman numeral In het oude Rome gebruikte men een talstelsel gebaseerd op Romeinse cijfers voor het weergeven van natuurlijke getallen. Dit talstelsel is geen positiestelsel, maar een additief stelsel waarin de waarde van het voorgestelde getal bepaald wordt door het totaal van de samenstellende symbolen. De getallen één tot en met tien worden met Romeinse cijfers geschreven als: I, II, III, IV, V, VI, VII, VIII, IX en X. Negatieve getallen en het getal nul kunnen niet voorgesteld worden in Romeinse cijfers. Het talstelsel is sinds de veertiende eeuw grotendeels verlaten ten voordele van het decimaal talstelsel gebaseerd op Arabische cijfers. In sommige toepassingen zijn Romeinse cijfers echter nog steeds in gebruik, bijvoorbeeld bij de nummering van vorsten met dezelfde naam (bijv. Lodewijk XIV), bij de nummering van jaarlijkse events en bij de nummering van eeuwen in sommige landen (bijv. XIXe siècle). In het talstelsel met Romeinse cijfers worden getallen genoteerd met symbolen, de eigenlijke cijfers, waarvan elk een bepaalde waarde heeft die onafhankelijk is van de positie die het cijfer in het getal inneemt. De Romeinse cijfers zijn: symbool waarde I 1 V 5 X 10 L 50 C 100 D 500 M 1000 De volgorde van de Romeinse cijfers in een getal is niet willekeurig. De waarden van de losse cijfers worden bij elkaar opgeteld, behalve als een lager cijfer vóór een hoger cijfer staat: in dat geval wordt het lagere cijfer er van afgetrokken. De regels voor het schrijven van getallen met Romeinse cijfers lijken in de Oudheid zeer los te zijn geweest. Zo gebruikte de BBC voor de aftiteling in het jaar 1999 het typografisch elegante jaartal MIM in plaats van MCMXCIX. Opgave PEP 313 was een voorstel om de Python programmeertaal uit te breiden met ondersteuning voor Romeinse getallen. Dit voorstel werd echter niet goedgekeurd. Omdat Python toelaat om nieuwe gegevenstypes te definiëren, is het echter mogelijk om zelf een gegevenstype voor Romeinse getallen toe te voegen aan Python. Hiervoor ga je als volgt te werk: Schrijf een functie romeins2arabisch die een gegeven string die enkel bestaat uit Romeinse cijfers (hoofdletters of kleine letters) omzet naar een integervoorstelling van hetzelfde getal. Schrijf een functie arabisch2romeins die een gegeven integer omzet naar de stringvoorstelling van dezelfde waarde in Romeinse cijfers (enkel hoofdletters). Deze omzetting kan

gebeuren door onderstaande tabel van links naar rechts te doorlopen. Zolang de resterende integerwaarde groter of gelijk is aan de getalwaarde uit de tabel, voeg je de combinatie van Romeinse cijfers op de corresponderende positie achteraan toe aan het Romeins getal. De integerwaarde wordt daarna verlaagd met de getalwaarde. Van zodra d e resterende integerwaarde kleiner is dan de getalwaarde uit de tabel, spring je één positie naar rechts in de tabel. M CM D CD C XC L XL X IX V IV I 1000 900 500 400 100 90 50 40 10 9 5 4 1 Definieer een klasse Romeins waarmee Romeinse getallen kunnen voorgesteld worden in Python. Nieuwe objecten van deze klasse kunnen zowel geïnitialiseerd worden met een integerwaarde $i$ (waarvoor $1 \leq i < 4000$) of met een string $s$ die enkel bestaat uit Romeinse cijfers (hoofdletters of kleine letters). Voor andere initialisatiewaarden moet de klasse een AssertionError opwerpen met de string ongeldig romeins cijfer. De conversie van een Romeins getal naar een string bekomen met de ingebouwde functies str() e n repr() geeft de getalwaarde in Romeinse cijfers (hoofdletters, zoals gegenereerd door de functie arabisch2romeins) en de conversie naar een integer bekomen met de ingebouwde functie int() geeft de getalwaarde in Arabische cijfers. Zorg ervoor dat de som, het verschil en het product van twee Romeinse getallen kan berekend worden aan de hand van de operatoren +, - en *. De evaluatie van deze bewerkingen moet resulteren in een nieuw Romeins getal. Voorbeeld >>> romeins2arabisch('mdccccx') >>> arabisch2romeins() 'MCMX' >>> int(romeins('mdccccx')) >>> int(romeins('mcmliv')) 1954 >>> int(romeins('mcmxc')) 1990 >>> som = Romeins('MDCCCCX') + Romeins('MCMXC') >>> isinstance(som, Romeins) >>> print(som) MMMCM >>> verschil = Romeins('MCMXC') - Romeins('MDCCCCX') >>> isinstance(verschil, Romeins) >>> str(verschil) 'LXXX' >>> product = Romeins('CMX') * Romeins('III') >>> isinstance(product, Romeins) >>> product MMDCCXXX >>> print(romeins('mdccccx')) MCMX >>> Romeins(1234)

MCCXXXIV >>> Romeins(4321) >>> Romeins('ABCDEF') >>> Romeins(3.14)