Advertisement
przemko

Korutyny -- strumienie

Jun 12th, 2017
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.44 KB | None | 0 0
  1. % strumienie.pl
  2.  
  3. main(N) :-
  4.     drukowanie(S1),
  5.     podwajanie(S2, S1),
  6.     numlist(1, N, S2).
  7.  
  8. podwajanie(IN, OUT) :-
  9.     freeze(IN,
  10.            (   IN = [H | IN_]
  11.            ->  H2 is 2 * H,
  12.                OUT = [H2 | OUT_],
  13.                podwajanie(IN_, OUT_)
  14.            ;   OUT = [])).
  15.  
  16. drukowanie(IN) :-
  17.     freeze(IN,
  18.            (   IN = [H | IN_]
  19.            ->  writeln(H),
  20.                drukowanie(IN_)
  21.            ;   true)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement