HUN
Minden feladat 1-1 pontot ér. 2/1. packing
Amikor utazáshoz pakolunk,
sokszor nem fér minden
be a táskánkba amit szívesen elvinnénk.
A függvény neve
legyen packing, két paramétere legyen: - meret,
ami azt mutatja, hogy hány kilónyi csomag fér a hátizsákunkba
- holmik,
az elpakolandó dolgok súlyának fontosság szerint csökkenő
sorrendben. Összesen több mint meret.
A függvény
adja vissza a holmik lista első k elemének
az összegét, ahol igaz, hogy az első k+1 elem összege
már nagyobb lenne mint meret. (Ha valami már nem fér be
a táskába, akkor az annál kevésbé fontos dolgokat már akkor se
pakoljuk be, ha azok beférnének.)
2/2. evaluate
Egy íjászverseny végén a kell kiértékelni egy versenyző
teljesítményét. Ehhez a evaluate nevű függvény megírása
a feladat. A függvény paraméterei: - target,
egy pár, ami a célpont x és y koordinátáját tartalmazza
- és l,
egy lista, ami a versenyző lövéseinek x és y
koordinátáját tartalmazza.
Adott egy függvény, pointvalue,
ami kiszámolja egy lövés pontértékét, ha megadjuk a lövés relatív
pozícióját a célponthoz képest. Számoljuk ki a versenyző
pontját úgy, hogy összeadjuk az összes lövésének az értékét.
import mathdef pointvalue(x,
y): dist = math.hypot(x, y) if dist > 10: return
0 else: return 10 - int(dist)def evaluate(target, l):
pass #TODO
2/3. product_x
Írjunk python függvényt, ami megmondja
a legkisebb
számot aminek a számjegyeinek szorzata egy adott szám.
A
függvény neve legyen product_x, egy paramétere legyen,
az x
A függvény egy egész számmal térjen vissza,
ami megfelel a feltételeknek.Segítség:
- Előbb
írjuk meg a jegyek függvényt, mely egy kapott számra
megadja a számjegyeinek a szorzatát.
- Ezt a függvényt
legegyszerűbb úgy megírni, ha a számot string-é alakítjuk
az str(szám) függvénnyel. Ekkor már indexekkel elérjük a különböző
számjegyeket. Ezeket pedig visszaalakíthatjuk egésszé az int(számjegy)
függvénnyel.
2/4. magic_square
A bűvös négyzet alatt általában egy olyan táblázatot
értünk, aminek minden sorában, oszlopában ugyanannyi a számok
összege. Írjunk függvényt, ami leellenőrzi, hogy egy adott
táblázat bűvös négyzet-e.
A
függvény neve legyen magic_square, és egy paramétere legyen: - tablazat,
egy táblázat amiben egész számok vannak. (listák listája)
A függvény True
-val
vagy False
-al térjen vissza attól függően
hogy a táblázatban minden sor és oszlop összege megegyezik-e.
ENG
All problems worth 1-1 point.2/1. packing
You want to go to
a hike and you have more stuff than your backpack.Write a function
that decides what to bring along!The function should be called packing
and have two parameters: - volume the size of
your backpack
- stuff a list of your stuff,
it is a list of the volumes of each item ordered by relevance:
most important first
The function should have to return
the total volume what you managed to pack.If you pack the first k
items then return the sum of their sizes.Adding the next element
would exceed the backpack.You don't pack less important stuff
even if it would fit better then the more important stuff.
2/2. evaluate
We organise an archery contest and
we need a function to evaluate the score of the players.Write
a function called evaluate with two parameters: - target:
a list of length 2, the (x, y) coordinates of the target
l:
a list of the hits of the competitor, this list contains (x,
y) coordinate pairs.
The function pointvalue
is already written and calculates the point of a given shot and
we have to calculate the sum of the shots to get the total score.To
evaluate one shot you have to call the function pointvalue
with
the relative coordinates of the target and the current shot.That
function calculates the length of that vector (distance from
the target) and converts it to points.What you have
to do is to sum up the point values of the list of shots and
return the total score.
import mathdef pointvalue(x,
y): dist = math.hypot(x, y) if dist > 10: return
0 else: return 10 - int(dist)def evaluate(target, l):
pass #TODO
2/3. product_x
For a given number x
calculate the smallest positive integerfor which the product
of the digits is equal to the original number.For example
if x=12 the number 26 has digits 2 and 6and their product
is equal to 12.Also 26 is the smallest number with this property.Write
a function called product_x with one parameter: x.
Return
the smallest number with this property.Hint
To do this
you need two functions:- digits returns the list
of digits. You can do this by converting the number to stringthen
iterating over the letters and convert them back to integers
and put them in a list
- The function product_x
should go through every integer from 1 and check whether the
product of digits is correct. Return the number if it is correct.
Also this will be the smallest number with this property
2/4. magic_square
Write
a function that checks a magic square.A table (list of lists)
is a magic square if - all of its rows sum up to the
same value
- all of its columns sum up to the same
value
- the row and column sums are equal
If
any of those requirements fail then it is not a magic square.The
function magic_square should have one parameter: the table (list
of lists of numbers).The list will not be empty and every element
will be a sublist with the same length (square).Return True
if it is a magic square and False otherwise.