KöMaL - Középiskolai Matematikai és Fizikai Lapok
A lap

Rendelje meg a KöMaL-t!

VersenyVizsga portál


Matematika oktatási portál

I. 339. Prolog is a functional programming language, in which facts and logical statements can be formulated. These formulae may contain concrete data and unknown quantities. For example, one can simply declare which teacher has which lesson on which day and hour: tanít(kovács,fizika,szerda,4). In this example, ``tanít'' means ``teaches'', ``kovács'' is the teacher's name, ``fizika'' is physics and ``szerda'' is Wednesday. Words beginning with a lower-case letter in a formula represent facts, while words beginning with an upper-case letter are variables or unknowns. Unknowns in the statements get values when the program is executed. Execution begins with checking the truth of a statement called the target statement. Suppose, for example, that the target statement is tanít(Ki,Mit,szerda,4). (Here ``Ki'' is ``Who'' and ``Mit'' is ``What subject''.) Then Prolog would evaluate this formula as true by replacing the unknowns by the values \text{\rm{Ki}}=\text{\rm{kov\'acs}} and \text{\rm{Mit}}
=\text{\rm{fizika}}. You can learn more about Prolog (in Hungarian) by reading the book Prologban programozni könnyű by Zsuzsanna Márkusz.

The Personal Edition of Visual Prolog is a freely downloadable Prolog environment suitable for learning the language. In its PIE project you can simply formulate your statements. You can have more information on Visual Prolog by visiting the http://www.visual-prolog.com site and reading the Fundamental Visual Prolog #1 and #2 online materials.

Lists also exist in Prolog, and the common list operations as usual in other functional languages can be performed on them. With the help of lists, more information can be put into a factual statement. The following list contains some basic data for the present exercise, showing the number of points (``5'' in the first example below; ``pont'' is ``point(s)'') a given contestant (``kiss_tamás'') was awarded for a particular problem (``problem 330'') in a KöMaL contest (``type i'' in the first example):

pont( [kiss_tamás,i,330,5], [benedek_andrea,b,4500,0], ...,[kiss_tamás,i,340,10] ).

Based on this list, answer each of the following questions by creating a Prolog formula with the given name and parameter(s).

1. How many contestants (= ``DB'') submitted (= ``beküld'') the solution of problem I. 330 - beküld_i330(DB)?

2. How many (= ``hány'') solutions with more than 0 points (= ``nemnulla'') were submitted altogether in the contest type P -hány_nemnulla(P,DB)?

3. How many points (= ``pont'') did each contestant (= V, ``versenyző'') get for problem B. 4500. - pontok_b4500(V,Pont)?

4. Who (= ``kik'') are the contestants of contest type C (the result is a list (= ``Lista'') of names with each name occurring only once) - kik_c(Lista)?

5. In which contest type (= P, ``pontverseny'') and for which task (= F, ``feladat'') did the contestants get the smallest number of points altogether, and how many points - legkevesebb(P,F,Pont)?

You should submit your Prolog source i339.pro that can be executed in the PIE system.

(10 points)

Deadline expired on 10 February 2014.

Google Translation (Sorry, the solution is published in Hungarian only.)

A feladat megoldását a következő állomány tartalmazza: i339mo.pro.

Statistics on problem I. 339.
1 student sent a solution.
10 points:Kiss 107 Ádám.

  • Problems in Information Technology of KöMaL, January 2014

  • Támogatóink:   Ericsson   Cognex   Emberi Erőforrás Támogatáskezelő   Emberi Erőforrások Minisztériuma   Nemzeti Tehetség Program    
    MTA Energiatudományi Kutatóközpont   MTA Wigner Fizikai Kutatóközpont     Nemzeti
Kulturális Alap   ELTE   Morgan Stanley