/* Count in octal (Rosetta code) in Picat. http://rosettacode.org/wiki/Count_in_octal """ Task Produce a sequential count in octal, starting at zero, and using an increment of a one for each consecutive number. Each number should appear on a single line, and the program should count until terminated, or until the maximum value of the numeric type in use is reached. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. % import cp. main => go. /* Alternative ways: - to_oct_string(N) - to_radix_string(N,8) - printf("%o\n",N) 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 ... 17615737040105402212262317777777774 17615737040105402212262317777777775 17615737040105402212262317777777776 17615737040105402212262317777777777 17615737040105402212262320000000000 17615737040105402212262320000000001 17615737040105402212262320000000002 17615737040105402212262320000000003 17615737040105402212262320000000004 */ go => N = 0, while(true) println(to_oct_string(N)), N := N + 1 end, nl. go => true. go2 => gen(N), println(to_oct_string(N)), fail, nl. % gen(0). % gen(N) :- % gen(N2), % N2 = N+1. % gen(0). % gen(X) :- % gen(X0), % X = X0 + 1. gen(I) :- gen(0, I). gen(I, I). gen(I, J) :- I2 is I + 1, gen(I2, J).