Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- Written on my host machine:
- * 32-bit Intel Atom with 160Gb Hdd 1Gb Ram,
- * Slackware GNU Linux distro version 14
- * Free Pascal Compiler 2.6.2
- Elder draft at http://pastebin.com/f6up8Zqb -- Don't use such brain-damage code (It has at least 4 ugly bugs already fixed here).
- *)
- program a_first_half_factorial_of_terms_for_a217626;
- label
- The_end;
- (*
- Devised and released for documentation purposes under the terms of use of
- "The On-Line Encyclopedia Of Integer Sequences" (OEIS.org).
- For details please visit: http://www.oeis.org
- Dear user/reader:
- -----------------
- When it is used properly, this code should help you to find the first ( (12!/2)-1 ) terms
- of A217626, a task for which you need to have stored at least the first ( (12!/2)+1 ) terms
- of A215940.
- The idea behind this processing was taken from a test session under PARI/GP like:
- x=[6,0,1,2,3,4,5,7,8,9,10,11];
- z=sum(y=1,12,x[y]*12^(12-y));
- print(z);
- This program is not expensive in lines of code and extra details such as tech checkings...
- It is assumed here that you know what you are doing when messing with it, for this
- subtle reason previously mentioned, this code goes without any warranty whatsoever.
- *)
- const
- base=12;
- faked_base=10;
- type
- ptr_int64= ^int64;
- ptr_pizza= ^pizza;
- pizza= array [1..base] of int64;
- const
- either_napole_or_sicilian: ptr_pizza = nil; (* PLEASE, always remember to initialize this properly!!! *)
- swissknife: ptr_int64 = nil; (* The same principle applies here *)
- (*
- Dear user,
- Sorry: You need to change properly the following two arrays when modifying base.
- My apologizes for this.
- *)
- power: pizza=
- (base*base*base*base*base*base*base*base*base*base*base,
- base*base*base*base*base*base*base*base*base*base,
- base*base*base*base*base*base*base*base*base,
- base*base*base*base*base*base*base*base,
- base*base*base*base*base*base*base,
- base*base*base*base*base*base,
- base*base*base*base*base,
- base*base*base*base,
- base*base*base,
- base*base,
- base,
- 1);
- faked_power: pizza=
- (faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base*faked_base,
- faked_base*faked_base*faked_base,
- faked_base*faked_base,
- faked_base,
- 1);
- var
- vbase,
- vfaked_base: int64;
- input_f:text;
- input_s:string;
- delta_A_operand,
- delta_B_operand,
- current,
- last: int64;
- register: array [1..10000] of int64;
- function f(x:char):byte;
- var
- ans:byte;
- begin
- if (x in ['a'..'z']) then begin
- ans:=10+ord(x)-ord('a');
- end else if (x in ['0'..'9']) then begin
- ans:=ord(x)-ord('0');
- end else begin
- ans:= 255;
- end;
- f:=ans;
- end;
- function g(y:string):int64;
- var
- ans:int64;
- k:byte;
- begin
- ans:=0;
- if (length(y) = base) then for k:= 1 to base do begin
- ans:= ans + f(y[k])*either_napole_or_sicilian^[k];
- end;
- g:=ans;
- end;
- function p(q:longint):int64;
- var
- ans:int64;
- u:longint;
- begin
- ans:=1;
- if (q >= 1) then begin
- for u:= 1 to q do begin
- ans:= ans*faked_base;
- end;
- end;
- p:=ans;
- end;
- function h(b:longint; z:int64):int64;
- var
- ans,
- cz:int64;
- k,
- w:longint;
- begin
- ans:=z;
- if (b <> faked_base) then begin
- ans:=0;
- cz:=z;
- k:=1;
- while (cz >= b) do begin
- register[k]:= cz mod b;
- cz:= cz div b;
- k:=k+1;
- end;
- register[k]:=cz;
- for w:= k downto 1 do begin
- ans:= ans+register[w]*p(w-1);
- end;
- end;
- h:=ans;
- end;
- (*
- The filename of the data intended to be processed here should be
- passed as the first and unique parameter in the command line
- invocation to this program. The output is made directly to the
- console, so normally you should redirect it to a file in order
- to save the answer (Just a term of A217626 in each line, like
- in a b-file but without including the offsets at left)
- *)
- begin
- vbase:= base; (* Don't touch this!*)
- vfaked_base:= faked_base; (* Don't touch this!*)
- (* Do you want to see sparks?... disable the following enclosed block. ... It was a joke, dont do it.*)
- (* * )
- ( * *)
- if (vbase <= 10) then begin
- either_napole_or_sicilian:= @faked_power;
- swissknife:= @vfaked_base;
- end else begin
- either_napole_or_sicilian:= @power;
- swissknife:= @vbase;
- end;
- (* * )
- ( * *)
- if (paramcount() = 1) then begin
- assign(input_f, paramstr(1));
- (*$i-*)reset(input_f);(*$i+*)
- if (IOResult = 0) then begin
- readln(input_f, input_s);
- delta_A_operand:= g(input_s);
- last:=0;
- while (not eof(input_f)) do begin
- readln(input_f,input_s);
- delta_B_operand:= g(input_s);
- current:= h(swissknife^, (delta_B_operand-delta_A_operand) div (swissknife^-1) );
- writeln(current-last);
- last:= current;
- end;
- end else begin
- writeln('Unexpected error when processing: ',paramstr(1),'; **ABORTING**');
- goto The_end;
- end;
- close(input_f);
- end else begin
- writeln('You must specify one and only one filename as invocation parameter. Please try again.');
- end;
- The_end:
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement