fork download
  1. <?php
  2.  
  3. define('N', 14 );
  4. define('K', 88 );
  5. define('_', '_' );
  6. define('A', 'A' );
  7. define('Lst', 'Lst');
  8. define('Rez', 'Rez');
  9. define('Cdr', 'Cdr');
  10. define('CdrRez', 'CdrRez');
  11. $hashtable = [
  12. 13 => 'N1 is N - 1',
  13. 87 => 'K1 is K - 1',
  14. '_' => ''
  15. ];
  16. function fu() {
  17. global $hashtable;
  18. $code = 'fu(' . @implode(', ', func_get_args()) . ')';
  19. $hash = '0x' . sprintf('%08x', crc32($code));
  20. $hashtable[$hash] = $code;
  21. return $hash;
  22. }
  23. function remove_each_nth() {
  24. global $hashtable;
  25. $code = 'remove_each_nth(' . implode(', ', func_get_args()) . ')';
  26. $hash = '0x' . sprintf('%08x', crc32($code));
  27. $hashtable[$hash] = $code;
  28. return $hash;
  29. }
  30. function append() {
  31. global $hashtable;
  32. $code = 'append(' . implode(', ', func_get_args()) . ')';
  33. $hash = '0x' . sprintf('%08x', crc32($code));
  34. $hashtable[$hash] = $code;
  35. return $hash;
  36. }
  37.  
  38. function prolog() {
  39. global $hashtable;
  40. foreach(func_get_args() as $argument) {
  41. $parts = str_split($argument, 10);
  42. array_walk($parts, function(&$v, $k)use($hashtable) { $v = isset($hashtable[$v]) ? $hashtable[$v] : ' :- ' . $hashtable[-$v];});
  43. echo implode(".\n", $parts) . ', ';
  44. }
  45. }
  46. $foo = 1;
  47. $bar = 1;
  48. $baz = 0;
  49. prolog($foo?
  50. fu([], _, _, []).
  51. fu(Lst, N, 0, Rez) :-
  52. append([_], Cdr, Lst), $bar?
  53. fu(Cdr, N, N, Rez).
  54. fu(Lst, N, K, Rez) :-
  55. append([A], Cdr, Lst),
  56. $K1 = K - 1,
  57. fu(Cdr, N, $K1, CdrRez), $baz?
  58. append([A], CdrRez, Rez).
  59. remove_each_nth(Lst, N, Rez) :-
  60. $N1 = N - 1,
  61. fu(Lst, $N1, $N1, Rez).
  62. _);
  63.  
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
fu(Array, _, _, Array).
fu(Lst, 14, 0, Rez), fu(Cdr, 14, 14, Rez).
fu(Lst, 14, 88, Rez), K1 is K - 1, fu(Cdr, 14, 87, CdrRez),  :- N1 is N - 1, fu(Lst, 13, 13, Rez).
,