Delannoy Number

 投稿者:しばっち  投稿日:2015年10月28日(水)22時22分18秒
 
!'Delannoy Number
FOR J=0 TO 7
   FOR I=0 TO 7
      PRINT USING "######":D(I,J);
   NEXT I
   PRINT
NEXT J
END

EXTERNAL  FUNCTION D(A,B)
IF A=0 AND B=0 THEN
   LET D=1
ELSEIF A<0 OR B<0 THEN
   LET D=0
ELSE
   LET D=D(A-1,B)+D(A,B-1)+D(A-1,B-1)
END IF
END FUNCTION

-------------------------------------------------------------------------------------
OPTION ARITHMETIC DECIMAL_HIGH
OPTION BASE 0
LET N=100
DIM M(N,N)
LET K=3
FOR X=0 TO N/2
   FOR Y=0 TO N/2
      LET M(X,Y)=MOD(D(X,Y),K)
   NEXT Y
NEXT X
FOR X=N/2 TO 0 STEP -1
   FOR Y=0 TO N/2
      LET M(N-X,Y)=MOD(D(X,Y),K)
   NEXT Y
NEXT X
FOR X=0 TO N
   FOR Y=N/2 TO 0 STEP -1
      LET M(X,N-Y)=MOD(D(X,Y),K)
   NEXT Y
NEXT X
FOR X=N/2 TO 0 STEP -1
   FOR Y=N/2 TO 0 STEP -1
      LET M(N-X,N-Y)=MOD(D(X,Y),K)
   NEXT Y
NEXT X
SET WINDOW 0,1,1,0
MAT PLOT CELLS, IN 0 , 0 ; 1 , 1 : M
END

EXTERNAL  FUNCTION D(N,K) !'Delannoy Number
OPTION ARITHMETIC DECIMAL_HIGH
FOR I=0 TO N
   LET S=S+COMB(K,I)*COMB(N+K-I,K)
NEXT I
LET D=S
END FUNCTION
 

戻る