Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program first_half_twelve_factorial_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;
- denominator=base-1; (*Unconditionally should be the quantity (base-1) in decimal*)
- power12: array [1..base] of int64=
- (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);
- var
- input_f:text;
- input_s:string;
- delta_A_operand,
- delta_B_operand,
- delta_quotient,
- prev_quotient: int64;
- register: array [1..100] 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])*power12[k];
- end;
- g:=ans;
- end;
- function p(q:longint):longint;
- var
- ans,
- u:longint;
- begin
- ans:=1;
- if (q >= 1) then begin
- for u:= 1 to q do begin
- ans:= ans*10;
- end;
- end;
- p:=ans;
- end;
- function h(b:longint; z:int64):int64;
- var
- ans,
- cz:int64;
- k,
- w:longint;
- 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;
- 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
- 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);
- (*
- writeln('0');
- *)
- prev_quotient:= 0;
- while (not eof(input_f)) do begin
- readln(input_f,input_s);
- delta_B_operand:= g(input_s);
- delta_quotient:=h(base,(delta_B_operand - delta_A_operand) div denominator);
- writeln(delta_quotient-prev_quotient);
- (* Toggle the following comment switch in order to obtain either A215940 (OFF) or A217626 (ON). Default is OFF; *)
- (**)
- prev_quotient:= delta_quotient;
- (**)
- 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