/* Binary digits (Rosetta code) in Picat. http://rosettacode.org/wiki/Binary_digits """ Create and display the sequence of binary digits for a given non-negative integer. The decimal value 5 should produce an output of 101 The decimal value 50 should produce an output of 110010 The decimal value 9000 should produce an output of 10001100101000 The results can be achieved using built-in radix functions within the language (if these are available), or alternatively a user defined function can be used. The output produced should consist just of the binary digits of each number followed by a newline. There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. /* Picat has a built-in to_binary_string/1 (and the more general to_radix_string/2) to convert an integer to a binary string. */ go => foreach(I in [5,50,900]) println(to_binary_string(I)) end. go2 => foreach(I in 0..15) printf("%10w\n",to_binary_string(I)) end, nl. fib(0) = 1. fib(1) = 1. fib(N) = fib(N-1) + fib(N-2).