Mercury 勉強メモ

関数論理型言語 Mercury を勉強するブログです.

P-99

P-99: 4.04 Binary search trees (dictionaries)

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. t(3, t(2, t(1, nil, nil), nil), t(5, nil, t(7, nil, nil))) Yes No

P-99: 4.02 Construct completely balanced binary trees

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. t('x', t('x', t('x', nil, nil), nil), t('x', nil, nil)) t('x', t('x', nil, t('x', nil, nil)), t('x', nil, nil)) t('x', t('x', nil, nil), t('x', t('x', nil, nil), nil)) t(…

P-99: 4.01 Check whether a given term represents a binary tree

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. Mercuryでは以下のようなユーザ定義型でTreeを表すので、形式のチェックは不要。 :- type tree(T) ---> t(T, tree(T), tree(T)) ; nil.

P-99: 3.05 Huffman code

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. [{'a', "0"}, {'b', "101"}, {'c', "100"}, {'d', "111"}, {'e', "1101"}, {'f', "1100"}]

P-99: 3.04 Gray code

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["000", "001", "011", "010", "110", "111", "101", "100"]

P-99: 3.03 Truth tables for logical expressions (3)

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. no no no yes no no yes yes no yes no yes no yes yes yes yes no no yes yes no yes yes yes yes no yes yes yes yes yes

P-99: 3.02 Truth tables for logical expressions (2)

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. yes yes yes yes no yes no yes no no no no

P-99: 3.01 Truth tables for logical expressions

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. yes yes yes yes no yes no yes no no no no

P-99: 2.11 Compare the two methods of calculating Euler's totient function

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. $ time ./p99_39a 4032 real 0m12.336s user 0m12.340s sys 0m0.005s $ time ./p99_39b 4032 real 0m1.221s user 0m1.216s sys 0m0.006s 2.10 の解法のほうが高速だった。 a) b)

P-99: 2.10 Calculate Euler's totient function phi(m) (2)

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. 4

P-99: 2.09 Calculate Euler's totient function phi(m)

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. 4

P-99: 2.08 Determine whether two positive integer numbers are coprime

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. yes

P-99: 2.07 Determine the greatest common divisor of two positive integer numbers

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. 9 9

P-99: 2.06 A list of Goldbach compositions

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. 前半 10 = 3 + 7 12 = 5 + 7 14 = 3 + 11 16 = 3 + 13 18 = 5 + 13 20 = 3 + 17 後半 992 = 73 + 919 1382 = 61 + 1321 1856 = 67 + 1789 1928 = 61 + 1867 2078 = 61 + 2017 2438 = …

P-99: 2.05 Goldbach's conjecture

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. {5, 23}

P-99: 2.04 A list of prime numbers

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

P-99: 2.03 Determine the prime factors of a given positive integer (2)

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. [{3, 2}, {5, 1}, {7, 1}]

P-99: 2.02 Determine the prime factors of a given positive integer

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. [3, 3, 5, 7]

P-99 2.01 Determine whether a given integer number is prime

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. Yes

P-99: 1.28 Sorting a list of lists according to length of sublists

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. a) [["o"], ["d", "e"], ["d", "e"], ["m", "n"], ["a", "b", "c"], ["f", "g", "h"], ["i", "j", "k", "l"]] b) [["i", "j", "k", "l"], ["o"], ["a", "b", "c"], ["f", "g", "h"], …

P-99: 1.27 Group the elements of a set into disjoint subsets

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. a) ["aldo", "beat"]["carla", "david", "evil"]["flip", "gary", "hugo", "ida"] ["aldo", "beat"]["carla", "david", "flip"]["evil", "gary", "hugo", "ida"] ["aldo", "beat"]["c…

P-99: 1.26 Generate the combinations of K distinct objects chosen from the N elements of a list

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["a", "b", "c"] ["a", "b", "d"] ["a", "b", "e"] ["a", "b", "f"] ["a", "c", "d"] ["a", "c", "e"] ["a", "c", "f"] ["a", "d", "e"] ["a", "d", "f"] ["a", "e", "f"] ["b", "c",…

P-99: 1.25 Generate a random permutation of the elements of a list

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["f", "e", "a", "c", "b", "d"]

P-99: 1.24 Lotto: Draw N different random numbers from the set 1..M

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. [3, 14, 25, 42, 17, 49]

P-99: 1.23 Extract a given number of randomly selected elements from a list

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["e", "h", "f"]

P-99: 1.22 Create a list containing all integers within a given range

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. [4, 5, 6, 7, 8, 9]

P-99: 1.21 Insert an element at a given position into a list

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["a", "alfa", "b", "c", "d"]

P-99: 1.20 Remove the K'th element from a list

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. b ["a", "c", "d"]

P-99: 1.19 Rotate a list N places to the left

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["d", "e", "f", "g", "h", "a", "b", "c"] ["g", "h", "a", "b", "c", "d", "e", "f"]

P-99: 1.18 Extract a slice from a list

P-99: Ninety-Nine Prolog Problemsの問題にMercuryで解答していきます. ["c", "d", "e", "f", "g"]