[PDF] Prolog Exercise Sheet 2 : Recursion and lists



Previous PDF Next PDF







Prolog Exercise Sheet 2 : Recursion and lists

Prolog Exercise Sheet 2 : Recursion and lists (content by Paul Bailey, 2001) October 2002 1 Write a predicate, list_to_term/2, which takes as its first argument a non-empty list of numbers and returns as its second argument a term composed of the numbers in the list joined by ’+’ operators An example of the behaviour of this predicate is:



Premiers exercices : element – longueur – retirer – dernier

Ecrire un prédicat Prolog add(L,A,L1) qui, recevant une liste de nombres L et un nombre A, renvoie la liste LplusA où tous les nombres de L ont été augmentés de A Exemple add([3,6,4],2,L) renvoie LplusA=[5,8,6] Donner l'arbre des sous-buts pour cet exemple



Prolog exercises - cvutcz

Prolog exercises Created by Lenka Novakova 1 print all elements of a list ?-print_list([a,b,c]) a b c print_list([]):-nl nl = newline print_list([HT]):-write(H





Examen N° : 01

Exercice 03 : (08 points) 1 Écrire le prédicat aumoins(X,N,L) qui est vrai si l’entier X apparaît au moins N fois dans la liste d’entiers L (3 points) 2 Écrire le prédicat supl(L,X) qui est vrai si X est plus grand ou égal à tous les éléments de la liste d’entiers L (2 points)



Prolog - TP3

Exercice 5 nombre d’occurrences d’un terme Ecrivez un pr edicat occurrence/3 occurrence(X,Liste,N) compte le nombre Nd’ el ements de la liste d ej a identique a X Cela signi e que ce pr edicat est d’un niveau m etalogique car Prolog ne doit pas essayer d’uni er les termes au risque de rajouter de termes identiques



Semaine 13: Programmation logique (1/2) Prolog

Prolog Le langage de programmation logique le plus répandu est Prolog Prolog est un acronyme pour Programmer avec la Logique Il a été développé dans les années 70 par Alain Colmerauer, au départ pour l'analyse syntaxique du langage naturel Prolog est utilisé dans des applications d'intelligence arti cielle, telles que



TP2 prolog L3 - INFO

1 Ecrire un prédicat prolog qui est vrai si x est un élément de la liste L 2 premier(E,L) est vrai si E est le premier élément de L 3 Ecrire un prédicat Prolog der qui trouve le dernier élément d’une liste L 4 Ecrire un prédicat Prolog avDer qui trouve le l'avant-dernier élément d’une liste L 5



TP de programmation fonctionnelle et logique Corrige´ du TP 4

Corrige´ du TP 4 : petits programmes Prolog 1 Calculer la longueur d’une liste size([],0) Calculer la moyenne des ´el ements´ d’une liste



Exercices de programmation en CAML

Exercice 3 Ecrire la fonction list of abr : ’a bin tree -> ’a listretournant une liste contenant les el ements de l’arbre pass e en param etre Exercice 4 Ecrire une fonction tri liste : (’a -> ’a -> bool) -> ’a list -> ’a list qui trie la liste pass ee en param etre a l’aide d’un ABR 1 3 2 Fonctions

[PDF] prolog cours pdf

[PDF] west side story tonight analyse

[PDF] west side story fiche technique

[PDF] tp fibre optique bac pro sen

[PDF] bac pro environnement nucléaire salaire

[PDF] fibre optique bac pro eleec

[PDF] bac pro techniques d'interventions sur installations nucléaires

[PDF] cours fibre optique bac pro sen

[PDF] 3x500 record du monde

[PDF] détection

[PDF] analyse et suivi des appels d’offres

[PDF] fiche descriptive facturation

[PDF] dsn arret de travail

[PDF] dsn prolongation arret de travail

[PDF] dsn signalement prolongation arret de travail

Prolog Exercise Sheet 2 : Recursion and lists

(content by Paul Bailey, 2001)

October 2002

1. Write a predicate,list_to_term/2, which takes as its first argument a non-empty list

of numbers and returns as its second argument a term composed of the numbers in the list joined by "+" operators. An example of the behaviour of this predicate is: | ?- list_to_term([1,2,3,4], X).

X = 1+(2+(3+4)) ?

yes | ?- list_to_term([9,9,9], X).

X = 9+(9+9) ?

yes | ?- list_to_term([44], X).

X = 44 ?

yes (Hint: careful choice of the base case will make things easier.)

2. Define two predicates,evenlength/1andoddlength/1, which take a list as their

argument, and succeed if that list has an even length and an odd length respectively. For example: | ?- evenlength([1,2,3,4]). yes | ?- oddlength([1]). yes

3. Define a predicatepalindrome/1which succeeds if its single argument is a list which

is the same in the forward and backward directions. For example: 1 | ?- palindrome([r,e,d,i,v,i,d,e,r]). yes

4. Define a predicateflatten/2, whose first argument is a list of any complexity, and

which succeeds by instantiating its second argument to a 'flattened" version of the list, which contains the contents of all of the embedded lists. For example: | ?- flatten([a, [[b]], [[], [d, e]]], X).

X = [a, b, d, e]

yes

5. Define a predicatecountatoms/2, which accepts a list containing atoms, numbers

and/or such lists, and 'returns" a list containing terms of the formItem=Countto show how many times anItemappears in any embedded list. For example: | ?- count_atoms([a, b, b, [[a], [c], b]], L).

L = [a=2, b=3, c=1]

yes Note that the order of the count terms in the result doesn"t matter; any order will do.

6. Define a predicatereplaceelements/4, which replaces all occurrences of a given

element in a list by another, and instantiates a given variable to the answer. The arguments should be, in order: (a) the element to be replaced; (b) the element to replace it with; (c) the list to do the replacing in; (d) a variable to be instantiated to the final list. (The predicate needn"t bother to delve inside lists within lists.) For example: | ?- replace_elements(pronoun(he),pronoun(we), [pronoun(he),verb(said),pronoun(he),verb(did)], L). L=[pronoun(we), verb(said), pronoun(we), verb(did)] yes 2quotesdbs_dbs9.pdfusesText_15