PROG0357 - Lotto

no tags 

Lotto is a form of lottery in which a given number of balls are drawn from a larger pool. Players can tick their own numbers on a lotto form. The higher the amount of matching numbers between the form and the balls drawn, the bigger the prize.

lotto

Several European countries have their own lottery systems, that mainly differ in the total number of balls played with, the number of balls that are drawn and the number of ticks allowed on the lotto form. In Belgium and in the Netherlands, players can tick (from October 2011 onwards) six numbers on a form from the series of numbers between 1 and 45. In the eighties and nineties the Dutch lotto was played with 40 balls and until September 2011 the Belgian lottery was played with 42 balls. Players in the United Kingdom and Germany can choose from the numbers 1 to 49. Seven balls are drawn in the Belgian lottery. This was also the case in the Netherlands until 2 March 2008. After this date the rules of the lottery were changed and only six balls were drawn.

Assignment

Write a function lottery that can be used to simulate a lotto draw. The function should have two optional parameters count and maximum. The number of balls $c$ to be drawn can be passed to the parameter count (default value 6). The total number of balls $m$ can be passed to the parameter maximum (default value 42). As such, the balls are numbered 1 to $m$. You may assume that $c \leq m$. The function should return a string that contains a strictly increasing list of $c$ integers, where the integers are separated from each other with a space, a dash (-) and another space. For each integer $n$ it must hold that $1 \leq n \leq m$. Make sure that each of the $m$ balls have equal probability of being drawn by the function.

Example

>>> lottery()
'2 - 17 - 22 - 27 - 35 - 40'
>>> lottery(count=8)
'5 - 13 - 15 - 31 - 34 - 36 - 39 - 40'
>>> lottery(maximum=21)
'1 - 5 - 6 - 8 - 17 - 20'
>>> lottery(count=4, maximum=38)
'16 - 20 - 35 - 37'
>>> lottery(maximum=256, count=12)
'6 - 12 - 39 - 47 - 87 - 132 - 179 - 208 - 213 - 231 - 240 - 249'

De lotto is een vorm van loterij die voornamelijk bekend is vanwege de genummerde balletjes, waarvan er een aantal getrokken worden. Deelnemers mogen zelf hun eigen nummers aankruisen op een lottoformulier. Hoe groter het aantal overeenkomstige nummers tussen het formulier en de getrokken balletjes, hoe groter de geldprijs.

lotto

Diverse Europese landen hebben elk hun eigen lottosysteem, waarbij de verschillen voornamelijk zitten in het aantal genummerde balletjes, het aantal balletjes dat getrokken wordt en het aantal nummers dat op een formulier mag aangekruist worden. Zo kan men in Nederland en België (vanaf oktober 2011) 6 nummers aankruisen uit de nummers 1 tot en met 45. In de jaren '80 en '90 werd er in Nederland nog met 40 balletjes gespeeld en tot september 2011 werd er in België slechts met 42 balletjes gespeeld. In het Verenigd Koninkrijk en Duitsland heeft men de keuze uit de nummers 1 tot en met 49. In onder andere de Belgische lotto worden er zeven balletjes getrokken. Dit was tot 2 maart 2008 in Nederland ook het geval. Vanaf deze datum is het systeem veranderd en worden er maar zes balletjes meer getrokken.

Opgave

Schrijf een functie loterij waarmee een lottotrekking kan gesimuleerd worden. De functie moet twee optionele parameters aantal en maximum hebben. Aan de parameter aantal kan doorgegeven worden hoeveel balletjes $a$ er moeten getrokken worden (standaardwaarde 6). Aan de parameter maximum kan doorgegeven worden uit hoeveel balletjes $m$ er moet getrokken worden (standaardwaarde 42). De balletjes zijn daarbij dus genummerd van 1 tot en met $m$. Je mag ervan uitgaan dat $a \leq m$. De functie moet een string teruggeven die een strikt stijgende lijst van $a$ natuurlijke getallen beschrijft, waarbij de getallen van elkaar gescheiden zijn door een spatie, een koppelteken (-) en nog een spatie. Voor elk getal $n$ moet gelden dat $1 \leq n \leq m$. Zorg ervoor dat elk van de $m$ balletjes evenveel kans maakt om door de functie getrokken te worden.

Voorbeeld

>>> loterij()
'2 - 17 - 22 - 27 - 35 - 40'
>>> loterij(aantal=8)
'5 - 13 - 15 - 31 - 34 - 36 - 39 - 40'
>>> loterij(maximum=21)
'1 - 5 - 6 - 8 - 17 - 20'
>>> loterij(aantal=4, maximum=38)
'16 - 20 - 35 - 37'
>>> loterij(maximum=256, aantal=12)
'6 - 12 - 39 - 47 - 87 - 132 - 179 - 208 - 213 - 231 - 240 - 249'


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