Mercury 勉強メモ

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

2014-04-01から1ヶ月間の記事一覧

Fizz Buzz

MercuryでFizz Buzz問題を解いてみました。 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 Fizz Buzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 Fizz Buzz

九九の表を出力するプログラム

Mercuryで掛け算の九九の表を出力するプログラムを作りました。 1 2 3 4 5 6 7 8 9 2 4 6 8 10 12 14 16 18 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 10 15 20 25 30 35 40 45 6 12 18 24 30 36 42 48 54 7 14 21 28 35 42 49 56 63 8 16 24 32 …

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]