/* a^nb^nc^n in Picat v3. From comp.lang.prolog 2008-01-22. Using DCG. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import v3_utils. import cp. main => go. % Generate [],abc,aabbcc, ... go ?=> anbncn(Ls, []), println(Ls), % restrict the length (Ls.len < 100 -> fail ; true), nl. go => true. % Using v3_utils.phrase go2 ?=> phrase(anbncn,Ls), println(Ls), % restrict the length (Ls.len < 100 -> fail ; true), nl. go2 => true. % From https://stackoverflow.com/questions/28893324/what-does-mean-in-prolog % Generate N=9 (length: 3*9 = 27) go3 ?=> start(9,Ls,[]), println(Ls), println(len=Ls.len), fail, nl. go3 => true. % Get the N of a sequence go4 ?=> start(N,"aabbcc",[]), println(n=N), fail, nl. go4 => true. anbncn --> n_x(N, a), n_x(N, b), n_x(N, c). n_x(0, _) --> []. n_x(s(N), X) --> [X], n_x(N, X). %Yielding: % % %?- anbncn(Ls, []). % %@ Ls = [] ; % %@ Ls = [a, b, c] ; % %@ Ls = [a, a, b, b, c, c] ; % %@ Ls = [a, a, a, b, b, b, c, c, c] a % %@ Yes % From https://stackoverflow.com/questions/28893324/what-does-mean-in-prolog start(N) --> as(N), bs(N), cs(N). as(N) --> {N #> 0, M #= N-1}, [a], as(M). as(0) --> []. bs(N) --> {N #> 0, M #= N-1}, [b], bs(M). bs(0) --> []. cs(N) --> {N #> 0, M #= N-1}, [c], cs(M). cs(0) --> [].