Mathematical and Physical Journal
for High Schools
Issued by the MATFUND Foundation
 Already signed up? New to KöMaL?

# Problem I. 289. (March 2012)

I. 289. Dominoes are fun to play with. Each piece contains two nonnegative integers and the corresponding number of dots. We say that a domino set is an $\displaystyle N$-set ($\displaystyle 0\le N\le 10$), if these integers fall between 0 and $\displaystyle N$. Two domino pieces are considered to be identical if the pairs of numbers on them (sorted into ascending order) are the same. A set of dominoes does not contain identical dominoes.

For example, a 2-set contains the following pieces: [0 0] [0 1] [0 2] [1 1] [1 2] [2 2].

Your first task is to create the elements of an $\displaystyle N$-set by using a functional algorithm. The input of the function creating the set is the value of $\displaystyle N$, while the output is the ordered sequence of the dominoes, as in the example. (Példa'' is example, dominó'' is domino, and Eredmény'' is the result.)

Your second task is to create a function that gives the total number of dots of an $\displaystyle N$-set. (Pöttyszám'' is number of dots.)

In a family some children have domino sets, but they are mixed up during the play. Your third task is to select those pieces which occur more than once. The input of your function is the unsorted list of dominoes, while the output is the ordered list similar to the example. (Többször'' is more than once.)

We recommend using Imagine Logo as a programming environment, but you can solve the task by using programming languages following the von Neumann model (such as C, C++, Pascal, ...). During your solution, apart from the inputs and outputs, you should use only the functional aspects of the programming language. Do not use variables. Repetition should be accomplished through recursion only. Try and decompose your solution into as many parametrizable functions as possible. You can read more about functional programming in problem I. 259.

Your source code (i289.imp Imagine Logo Project, i289.pas, i289.cpp, ...) and a text file i289.txt -- describing your functions and giving the name of the developer environment to use for compiling -- should be submitted in a compressed file i289.zip.

(10 pont)

Deadline expired on April 10, 2012.

Sorry, the solution is available only in Hungarian. Google translation

Megoldásokról:

Elsősorban imagine, de visual basic, freepascal és c++ nyelvű megoldások is érkeztek. A funkcionális nyelvek, így a logo nyelv logikájának a rekurzív megoldási módszer elvárása testhez álló volt.

Állítsunk elő N méretű dominókészletet!

Példa: dominó 3 Eredmény: [[0 0] [0 1] [0 2] [0 3] [1 1] [1 2] [1 3] [2 2] [2 3] [3 3]]

Készítsünk függvényt, amely egy N nagyságú dominókészlet összes pöttyeinek számát adja meg!

Példa: pöttyszám 2 Eredmény: 12, pöttyszám 3 Eredmény: 30

Megjegyzés: az eredmény képlettel is kiszámítható: n(n+1)(n+2)/2.

Mintamegoldásként Fényes Balázs 9. osztályos (Budapest, Szerb Antal Gimnázium) tanuló visual basic nyelvű megoldását: i289.vb

és Kucsma Levente István 9. osztályos (Eger, Dobó István Gimnázium) tanuló imagine nyelvű: I289.IMP megoldását közöljük.

### Statistics:

 11 students sent a solution. 10 points: Fényes Balázs, Gema Barnabás, Kucsma Levente István, Szabó Levente, Tegzes Tamás, Varga 256 Erik. 9 points: Beleznay Soma, Kalló Kristóf. 6 points: 3 students.

Problems in Information Technology of KöMaL, March 2012