Informatics2-2018/Lab03

A MathWikiből
(Változatok közti eltérés)
(Exercises)
3. sor: 3. sor:
 
= Exercises =
 
= Exercises =
  
== Mean nearest ==
+
=== Mean nearest ===
  
 
Write a function that finds an element in a list which is the nearest to the mean of the list.
 
Write a function that finds an element in a list which is the nearest to the mean of the list.
59. sor: 59. sor:
  
 
=== Pascal ===
 
=== Pascal ===
A Pascal-háromszög a binomiális együtthatók háromszög formában való elrendezése. Részletes leírás található pl. a magyar [https://hu.wikipedia.org/wiki/Pascal-h%C3%A1romsz%C3%B6g wikipédián].
+
The Pascal triangle consist of binomial coefficients, find details on [https://en.wikipedia.org/wiki/Pascal%27s_triangle Wikipedia].
A lényeg az, hogy az ''n.'' sor ''k.'' eleme az az ''"n alatt a k"'' binomiális együttható, és minden elem a felette levő kettő összege.
+
Írjuk meg a <tt>pascal</tt> nevű függvényt, ami visszaadja a Pascal-háromszög első néhány sorát listák listájaként. A függvény paramétere:
+
* ''n'', hogy hány sort számoljunk ki
+
  
Így tehát pl. <tt>pascal(4)</tt>-nek a következőt kell visszaadnia:
+
Write a function that calculates some lines of the triangle and returns it as a list of lists.
 +
First list is <tt>[1]</tt>, second is of length 2, and so on.
 +
 
 +
The function should have one parameter: ''n'', the number of rows to calculate.
 +
 
 +
For example the result of <tt>pascal(4)</tt> should be:
  
 
     [[1],
 
     [[1],
71. sor: 73. sor:
 
     [1, 3, 3, 1]]
 
     [1, 3, 3, 1]]
  
Az elemek kiszámolásához ne a binomiális együttható általános (faktoriálisos) képletét használjuk, hanem azt, hogy a felette levő két elem összege!
+
Use the fact that a coefficient is the sum of the two elements above it.
 
+
=== Cserebere ===
+
A bemenetünk egyrészt egy szó a ''szo'' nevű változóban, másrészt cserék egy sorozata, amit végre kell hajtani a szón, a ''cserek'' nevű változóban.
+
Így ''szo'' egy karakterlánc, ''cserek'' pedig egy lista, melynek minden eleme egy pár, ami a csere helyét, és az új betűt tartalmazza.
+
  
Ezeket a cseréket kell elvégezni a ''szo''-n és az így kapott sztringet visszaadni.
+
=== Replacement ===
 +
Write a function with two parameters: ''word'' is a string, and ''replaces'' a list of pairs where every pair is a number-character pair, like: <tt>(n, c)</tt>.
 +
You should replace the characters in ''word'' according to the ''replaces''. On pair represents that you should replace the ''n''<sup>th</sup> character to the new letter ''c''.
  
=== Név generátor ===
+
Return the new word after you performed the replacements.
Egy olyan számítógépes játékon dolgozunk, amiben rendszeresen találkozunk más, a számítógép által megszemélyesített, karakterekkel.
+
Ezeknek a karaktereknek számítógép véletlenszerűen választ nevet, azonban szeretnénk elkerülni hogy ugyanazt a nevet sokszor lássa a játékos.
+
Ezért ahelyett hogy egy listányi nevet megadtunk volna a játék készítésekor, inkább külön-külön egy listányi előtagot és utótagot adtunk meg, hogy ezekből rakja össze a karakterek neveit.
+
  
Írjuk meg a függvényt, ami az összes lehetséges nevet összerakja az adott elő és utótagok listája alapján.
+
For example replace <tt>[(0, 'm'), (2, 'm'), (2, 'm')]</tt> in <tt>"puppy"</tt> you get <tt>mummy</tt>.
* A függvény neve legyen <tt>nev_generator</tt>, és két paramétere legyen
+
* ''elotagok'', egy lista, amiben az előtagok szerepelnek karakterláncokként
+
* ''utotagok'', egy lista, amiben az utótagok vannak hasonlóan.
+
* A adja vissza az összes lehetséges összerakott nevet egy listában.
+
  
 +
=== Name generator ===
 +
You write a computer game where you have to choose name of your player. The name consists of a forst name and a last name where both first and last name come from a given list of possibilities.
  
 +
Generate all the possible names composed from the list of first names and list of last names.
  
 
[[Informatics2-2018/Lab02|previous]] [[Informatics2-2018#Labs|up]] [[Informatics2-2018/Lab04|next]]
 
[[Informatics2-2018/Lab02|previous]] [[Informatics2-2018#Labs|up]] [[Informatics2-2018/Lab04|next]]

A lap 2018. február 28., 18:27-kori változata

previous up next

Tartalomjegyzék

Exercises

Mean nearest

Write a function that finds an element in a list which is the nearest to the mean of the list. There should be one parameter, the list.

Increasing sublists

Write a function that finds increasing sublists with a given length within a given list. The function should have two parameters:

  • a list l
  • and a natural number n
  • return the list of n-long increasing sublists of l

Break down to subtasks:

  • first return the list of all n-long sublists of l
  • Check whether a sublist is increasing

Name conflict

We are throwing a party and there are a lots of unknown people there. We write their names in a list. Write a python function that decides whether there is a duplicate in the names (two person with the same name).

The function should have one parameter: the list of names.

Return True if there are at least two people with the same name, </tt>False</tt> is all the names are unique.

Hint:

Mind that do not compare ones name to itself, only to other's names.

Pronunciation

In Hungarian there are a lots of vowels and some words are hard to pronounce if there are a lots of consonants in them. For example "elorozza" has a good number of vowels, but the Slovakian "zmrzlina" has too many consonants.

Write a python function that decides whether a word has too many consonants or not.

  • Call the function pronunciation
  • with one parameter: word, the word in question
  • return the string "Hard" if the number of consonants are more (or equal) than twice the number of vowels.
  • return "Easy" otherwise.

Food courses

Suppose you have a really strict diet and you have a given number of calories what you should eat for dinner. You walk in a restaurant and they have the menu of soups and main dishes. Every item on the menu has a calorie value.

Can you choose the right dishes to exactly match your calorie intake?

Write a python function

  • called dishes
  • that have three parameters:
    • calorie, the number of calories you should eat
    • soups, a list containing calorie values for the soups
    • mains, a list containing calorie values for the main dishes
  • You should return True if there is a two-course meal that fits your diet (True otherwise).

Pascal

The Pascal triangle consist of binomial coefficients, find details on Wikipedia.

Write a function that calculates some lines of the triangle and returns it as a list of lists. First list is [1], second is of length 2, and so on.

The function should have one parameter: n, the number of rows to calculate.

For example the result of pascal(4) should be:

   [[1],
   [1, 1],
   [1, 2, 1],
   [1, 3, 3, 1]]

Use the fact that a coefficient is the sum of the two elements above it.

Replacement

Write a function with two parameters: word is a string, and replaces a list of pairs where every pair is a number-character pair, like: (n, c). You should replace the characters in word according to the replaces. On pair represents that you should replace the nth character to the new letter c.

Return the new word after you performed the replacements.

For example replace [(0, 'm'), (2, 'm'), (2, 'm')] in "puppy" you get mummy.

Name generator

You write a computer game where you have to choose name of your player. The name consists of a forst name and a last name where both first and last name come from a given list of possibilities.

Generate all the possible names composed from the list of first names and list of last names.

previous up next

Személyes eszközök