fork download
  1. :- set_prolog_flag(verbose,silent).
  2. :- prompt(_, '').
  3. :- use_module(library(readutil)).
  4.  
  5. fact(0,1):-!.
  6. fact(N,Res2):-N2 is N-1,fact(N2,Res),Res2 is Res*N.
  7.  
  8. f(N2):-member(N,[9,8,7,6,5,4,3,2,1,0]),fact(N,N2).
  9.  
  10. g(_,[],[],[]):-!.
  11. g(N,Ns,[P|Ps],[M|Res]):-P2 is N//P,
  12. N2 is N mod P,
  13. length(Ls,P2),
  14. append(Ls,[M|Rs],Ns),
  15. append(Ls,Rs,Ns2),
  16. g(N2,Ns2,Ps,Res).
  17.  
  18. main:-
  19. process,
  20.  
  21. process:-
  22. /* your code goes here */
  23. findall(P,f(P),Ps),
  24. g(999999,[0,1,2,3,4,5,6,7,8,9],Ps,Ans),
  25. write(Ans),
  26.  
  27. :- main.
Success #stdin #stdout 0.04s 7080KB
stdin
Standard input is empty
stdout
[2,7,8,3,9,1,5,4,6,0]