A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
44
Task/Forward-difference/REXX/forward-difference-1.rexx
Normal file
44
Task/Forward-difference/REXX/forward-difference-1.rexx
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*REXX program to compute the forward difference of a list of numbers.*/
|
||||
/* ┌───────────────────────────────────────────────────────────────────┐
|
||||
│ /\ n n n-k │
|
||||
│ {delta} / \ n [ƒ] (x) ≡ Σ Ç ∙ (-1) ∙ ƒ(x+k) │
|
||||
│ /____\ k=0 k │
|
||||
│ │
|
||||
│ {n=order} {Ç=comb or binomial coeff.} │
|
||||
└───────────────────────────────────────────────────────────────────┘*/
|
||||
numeric digits 100 /*ensure enough accuracy. */
|
||||
arg numbers ',' ord /*input: x1 x2 x3 x4 ... ,ORD */
|
||||
if numbers=='' then numbers='90 47 58 29 22 32 55 5 55 73' /*default?*/
|
||||
w=words(numbers) /*set W to # of numbers in list.*/
|
||||
|
||||
do i=1 for w /*validate input (valid numbers?)*/
|
||||
@.i=word(numbers,i) /*assign the next # in the list. */
|
||||
if \datatype(@.i,'N') then call ser @.i "isn't a valid number"
|
||||
@.i=@.i/1 /*normalize the #, prettify the #*/
|
||||
end /*i*/
|
||||
/*═════════════════════════════════════════process the (optional) input.*/
|
||||
if w==0 then call ser 'no numbers were specified'
|
||||
if ord\=='' & ord<0 then call ser ord "(ner) can't be negative"
|
||||
if ord\=='' & ord>w then call ser ord "(ner) can't be greater than" w
|
||||
say right(w 'numbers: ' numbers,64) /*sloppy way to do a header, ... */
|
||||
say right(copies('─',length(numbers)),64) /* and the header fence.*/
|
||||
if ord=='' then do; bot=0; top=w; end /*define default ners.*/
|
||||
else do; bot=n; top=n; end /*just a specific ner?*/
|
||||
/*═════════════════════════════════════════where da rubber meets da road*/
|
||||
do order=bot to top; do r=1 for w; !.r=@.r; end; $=
|
||||
do j=1 for order; d=!.j; do k=j+1 to w /*order diff.*/
|
||||
parse value !.k !.k-d with d !.k
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
do i=order+1 to w /*build list.*/
|
||||
$=$ !.i/1 /*append it. */
|
||||
end /*i*/
|
||||
if $=='' then $='[null]' /*pretty null*/
|
||||
what=right(order,length(w))th(order)'-order' /*nice format*/
|
||||
say what 'forward difference vector = ' strip($) /*display it.*/
|
||||
end /*o*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────SER subroutine──────────────────────*/
|
||||
ser: say; say '*** error! ***'; say arg(1); say; exit 13
|
||||
/*──────────────────────────────────TH subroutine───────────────────────*/
|
||||
th: parse arg ?; return word('th st nd rd',1+?//10*(?//100%10\==1)*(?//10<4))
|
||||
35
Task/Forward-difference/REXX/forward-difference-2.rexx
Normal file
35
Task/Forward-difference/REXX/forward-difference-2.rexx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* REXX ***************************************************************
|
||||
* Forward differences
|
||||
* 18.08.2012 Walter Pachl derived from PL/I
|
||||
**********************************************************************/
|
||||
Do n=-1 To 11
|
||||
Call differences '90 47 58 29 22 32 55 5 55 73',n
|
||||
End
|
||||
Exit
|
||||
|
||||
differences: Procedure
|
||||
Parse Arg a,n
|
||||
m=words(a)
|
||||
Select
|
||||
When n<0 Then Say 'n is negative:' n '<' 0
|
||||
When n>m Then Say 'n is too large:' n '>' m
|
||||
Otherwise Do
|
||||
Do i=1 By 1 while a<>''
|
||||
Parse Var a a.i a
|
||||
End
|
||||
Do i = 1 to n;
|
||||
t = a.i;
|
||||
Do j = i+1 to m;
|
||||
u = a.j
|
||||
a.j = a.j-t;
|
||||
t = u;
|
||||
end;
|
||||
end;
|
||||
ol=''
|
||||
Do k=n+1 to m
|
||||
ol=ol a.k
|
||||
End
|
||||
Say n ol
|
||||
End
|
||||
End
|
||||
Return
|
||||
Loading…
Add table
Add a link
Reference in a new issue