Advertisement
algorithmuscanorj

pizza hut chesse predator mice

Dec 20th, 2012
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 5.70 KB | None | 0 0
  1. (*
  2.  
  3.   Written on my host machine:
  4.  
  5.   * 32-bit Intel Atom with 160Gb Hdd 1Gb Ram,
  6.   * Slackware GNU Linux distro version 14
  7.   * Free Pascal Compiler 2.6.2
  8.  
  9.     Elder draft at http://pastebin.com/f6up8Zqb -- Don't use such brain-damage code (It has at least 4 ugly bugs already fixed here).
  10. *)
  11.  
  12. program a_first_half_factorial_of_terms_for_a217626;
  13.  
  14. label
  15.   The_end;
  16.  
  17. (*
  18.  
  19. Devised and released for documentation purposes under the terms of use of
  20. "The On-Line Encyclopedia Of Integer Sequences" (OEIS.org).
  21.  
  22. For details please visit: http://www.oeis.org
  23.  
  24.  
  25. Dear user/reader:
  26. -----------------
  27.  
  28. When it is used properly, this code should help you to find the first ( (12!/2)-1 ) terms
  29. of A217626, a task for which you need to have stored at least the first ( (12!/2)+1 ) terms
  30. of A215940.
  31.  
  32. The idea behind this processing was taken from a test session under PARI/GP like:
  33.  
  34. x=[6,0,1,2,3,4,5,7,8,9,10,11];
  35. z=sum(y=1,12,x[y]*12^(12-y));
  36. print(z);
  37.  
  38. This program is not expensive in lines of code and extra details such as tech checkings...
  39. It is assumed here that you know what you are doing when messing with it, for this
  40. subtle reason previously mentioned, this code goes without any warranty whatsoever.
  41.  
  42. *)
  43.  
  44. const
  45.   base=12;
  46.   faked_base=10;
  47.  
  48. type
  49.   ptr_int64= ^int64;
  50.   ptr_pizza= ^pizza;
  51.   pizza= array [1..base] of int64;
  52.  
  53. const
  54.   either_napole_or_sicilian: ptr_pizza = nil; (* PLEASE, always remember to initialize this properly!!! *)
  55.   swissknife: ptr_int64 = nil; (* The same principle applies here *)
  56.  
  57.   (*
  58.  
  59.     Dear user,
  60.    
  61.     Sorry: You need to change properly the following two arrays when modifying base.
  62.    
  63.     My apologizes for this.
  64.    
  65.   *)
  66.  
  67.   power: pizza=
  68.   (base*base*base*base*base*base*base*base*base*base*base,
  69.    base*base*base*base*base*base*base*base*base*base,
  70.    base*base*base*base*base*base*base*base*base,
  71.    base*base*base*base*base*base*base*base,
  72.    base*base*base*base*base*base*base,
  73.    base*base*base*base*base*base,
  74.    base*base*base*base*base,
  75.    base*base*base*base,
  76.    base*base*base,
  77.    base*base,
  78.    base,
  79.    1);
  80.  
  81.   faked_power: pizza=
  82.   (faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
  83.    faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
  84.    faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
  85.    faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
  86.    faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
  87.    faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
  88.    faked_base*faked_base*faked_base*faked_base*faked_base,
  89.    faked_base*faked_base*faked_base*faked_base,
  90.    faked_base*faked_base*faked_base,
  91.    faked_base*faked_base,
  92.    faked_base,
  93.    1);
  94.    
  95. var
  96. vbase,
  97. vfaked_base: int64;
  98. input_f:text;
  99. input_s:string;
  100. delta_A_operand,
  101. delta_B_operand,
  102. current,
  103. last: int64;
  104. register: array [1..10000] of int64;
  105.  
  106. function f(x:char):byte;
  107. var
  108.   ans:byte;
  109. begin
  110.   if (x in ['a'..'z']) then begin
  111.     ans:=10+ord(x)-ord('a');
  112.   end else if (x in ['0'..'9']) then begin
  113.     ans:=ord(x)-ord('0');
  114.   end else begin
  115.     ans:= 255;
  116.   end;
  117.   f:=ans;
  118. end;
  119.  
  120. function g(y:string):int64;
  121. var
  122.   ans:int64;
  123.   k:byte;
  124. begin
  125.   ans:=0;
  126.   if (length(y) = base) then for k:= 1 to base do begin
  127.     ans:= ans + f(y[k])*either_napole_or_sicilian^[k];
  128.   end;
  129.   g:=ans;
  130. end;
  131.  
  132. function p(q:longint):int64;
  133. var
  134.   ans:int64;
  135.   u:longint;
  136. begin
  137.   ans:=1;
  138.   if (q >= 1) then begin
  139.      for u:= 1 to q do begin
  140.     ans:= ans*faked_base;
  141.      end;
  142.   end;
  143.   p:=ans;
  144. end;
  145.  
  146. function h(b:longint; z:int64):int64;
  147. var
  148.   ans,
  149.   cz:int64;
  150.   k,
  151.   w:longint;
  152. begin
  153.   ans:=z;
  154.   if (b <> faked_base) then begin
  155.     ans:=0;
  156.     cz:=z;
  157.     k:=1;
  158.     while (cz >= b) do begin
  159.       register[k]:= cz mod b;
  160.       cz:= cz div b;
  161.       k:=k+1;
  162.     end;
  163.     register[k]:=cz;
  164.     for w:= k downto 1 do begin
  165.       ans:= ans+register[w]*p(w-1);
  166.     end;
  167.   end;
  168.   h:=ans;
  169. end;
  170.  
  171. (*
  172.     The filename of the data intended to be processed here should be
  173.     passed as the first and unique parameter in the command line
  174.     invocation to this program. The output is made directly to the
  175.     console, so normally you should redirect it to a file in order
  176.     to save the answer (Just a term of A217626 in each line, like
  177.     in a b-file but without including the offsets at left)
  178. *)
  179.  
  180. begin
  181.  
  182.   vbase:= base; (* Don't touch this!*)
  183.   vfaked_base:= faked_base; (* Don't touch this!*)
  184.  
  185.   (* Do you want to see sparks?... disable the following enclosed block. ... It was a joke, dont do it.*)
  186.   (* * )
  187.   ( * *)  
  188.   if (vbase <= 10) then begin
  189.     either_napole_or_sicilian:= @faked_power;
  190.     swissknife:= @vfaked_base;
  191.   end else begin
  192.     either_napole_or_sicilian:= @power;
  193.     swissknife:= @vbase;
  194.   end;
  195.   (* * )
  196.   ( * *)  
  197.  
  198.   if (paramcount() = 1) then begin
  199.     assign(input_f, paramstr(1));
  200.     (*$i-*)reset(input_f);(*$i+*)
  201.     if (IOResult = 0) then begin
  202.       readln(input_f, input_s);
  203.       delta_A_operand:= g(input_s);
  204.       last:=0;
  205.       while (not eof(input_f)) do begin
  206.     readln(input_f,input_s);
  207.     delta_B_operand:= g(input_s);
  208.     current:= h(swissknife^, (delta_B_operand-delta_A_operand) div (swissknife^-1) );
  209.     writeln(current-last);
  210.     last:= current;
  211.       end;
  212.     end else begin
  213.       writeln('Unexpected error when processing: ',paramstr(1),'; **ABORTING**');
  214.       goto The_end;
  215.     end;
  216.     close(input_f);
  217.   end else begin
  218.     writeln('You must specify one and only one filename as invocation parameter. Please try again.');
  219.   end;
  220.   The_end:
  221. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement