Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Digital-root/NetRexx/digital-root.netrexx
Normal file
34
Task/Digital-root/NetRexx/digital-root.netrexx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* NetRexx ************************************************************
|
||||
* Test digroot
|
||||
**********************************************************************/
|
||||
Say 'number -> digital_root persistence'
|
||||
test_digroot(7 ,7, 0)
|
||||
test_digroot(627615 ,9, 2)
|
||||
test_digroot(39390 ,6, 2)
|
||||
test_digroot(588225 ,3, 2)
|
||||
test_digroot(393900588225,9, 2)
|
||||
test_digroot(393900588225,9, 3) /* test error case */
|
||||
|
||||
method test_digroot(n,dx,px) static
|
||||
res=digroot(n)
|
||||
Parse res d p
|
||||
If d=dx & p=px Then tag='ok'
|
||||
Else tag='expected:' dx px
|
||||
Say n '->' d p tag
|
||||
|
||||
method digroot(n) static
|
||||
/**********************************************************************
|
||||
* Compute the digital root and persistence of the given decimal number
|
||||
* 19.08.2012 Walter Pachl derived from Rexx
|
||||
**************************** Bottom of Data **************************/
|
||||
p=0 /* persistence */
|
||||
Loop While n.length()>1 /* more than one digit in n */
|
||||
s=0 /* initialize sum */
|
||||
p=p+1 /* increment persistence */
|
||||
Loop while n<>'' /* as long as there are digits */
|
||||
Parse n c +1 n /* pick the first one */
|
||||
s=s+c /* add to the new sum */
|
||||
End
|
||||
n=s /* the 'new' number */
|
||||
End
|
||||
return n p /* return root and persistence */
|
||||
Loading…
Add table
Add a link
Reference in a new issue