Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,28 +0,0 @@
|
|||
with Ada.Integer_Text_IO;
|
||||
|
||||
procedure Sum_Digits is
|
||||
-- sums the digits of an integer (in whatever base)
|
||||
-- outputs the sum (in base 10)
|
||||
|
||||
function Sum_Of_Digits(N: Natural; Base: Natural := 10) return Natural is
|
||||
Sum: Natural := 0;
|
||||
Val: Natural := N;
|
||||
begin
|
||||
while Val > 0 loop
|
||||
Sum := Sum + (Val mod Base);
|
||||
Val := Val / Base;
|
||||
end loop;
|
||||
return Sum;
|
||||
end Sum_Of_Digits;
|
||||
|
||||
use Ada.Integer_Text_IO;
|
||||
|
||||
begin -- main procedure Sum_Digits
|
||||
Put(Sum_OF_Digits(1)); -- 1
|
||||
Put(Sum_OF_Digits(12345)); -- 15
|
||||
Put(Sum_OF_Digits(123045)); -- 15
|
||||
Put(Sum_OF_Digits(123045, 50)); -- 104
|
||||
Put(Sum_OF_Digits(16#fe#, 10)); -- 11
|
||||
Put(Sum_OF_Digits(16#fe#, 16)); -- 29
|
||||
Put(Sum_OF_Digits(16#f0e#, 16)); -- 29
|
||||
end Sum_Digits;
|
||||
|
|
@ -10,5 +10,5 @@ sumDigits: function [n base][
|
|||
print sumDigits 1 10
|
||||
print sumDigits 12345 10
|
||||
print sumDigits 123045 10
|
||||
print sumDigits from.hex "0xfe" 16
|
||||
print sumDigits from.hex "0xf0e" 16
|
||||
print sumDigits 0xfe 16
|
||||
print sumDigits 0xf0e 16
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
(defun digit-sum (n)
|
||||
(apply #'+ (mapcar (lambda (c) (- c ?0)) (string-to-list "123"))))
|
||||
|
||||
(digit-sum 1234) ;=> 10
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
function Get-DigitalSum ([string] $number, $base = 10)
|
||||
{
|
||||
if ($number.ToCharArray().Length -le 1) { [Convert]::ToInt32($number, $base) }
|
||||
else
|
||||
{
|
||||
$result = 0
|
||||
foreach ($character in $number.ToCharArray())
|
||||
{
|
||||
$digit = [Convert]::ToInt32(([string]$character), $base)
|
||||
$result += $digit
|
||||
}
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,38 @@
|
|||
/*REXX program sums the decimal digits of natural numbers in any base up to base 36.*/
|
||||
parse arg z /*obtain optional argument from the CL.*/
|
||||
if z='' | z="," then z= '1 1234 fe f0e +F0E -666.00 11111112222222333333344444449'
|
||||
do j=1 for words(z); _=word(z, j) /*obtain a number from the list. */
|
||||
say right(sumDigs(_), 9) ' is the sum of the digits for the number ' _
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
sumDigs: procedure; arg x; @=123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ; $=0
|
||||
do k=1 to length(x); $=$ + pos( substr(x, k, 1), @); end /*k*/
|
||||
return $
|
||||
-- 24 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'SUM DIGITS OF AN INTEGER'
|
||||
say version
|
||||
say
|
||||
call Task 1
|
||||
call Task 1234
|
||||
call Task 'fe'
|
||||
call Task 'f0e'
|
||||
call Task '1E9'
|
||||
call Task 100101001
|
||||
call Task 885145624
|
||||
call Task 'AF771ED0A'
|
||||
call Task 'ashlh2837'
|
||||
call Task '123,456,789'
|
||||
call Task 12345.6789
|
||||
call Task 'AF12 BE34'
|
||||
call Task 'Rosetta Code 2007'
|
||||
call Task '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
exit
|
||||
|
||||
Task:
|
||||
procedure
|
||||
arg xx
|
||||
say 'Digital sum of' xx 'is' DigitSum(xx)
|
||||
return
|
||||
|
||||
DigitSum:
|
||||
procedure
|
||||
arg xx
|
||||
rr=0
|
||||
do i = 1 to Length(xx)
|
||||
rr=rr+Pos(SubStr(xx,i,1),'123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
||||
end
|
||||
return rr
|
||||
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
/*REXX program sums the decimal digits of integers expressed in base ten. */
|
||||
parse arg z /*obtain optional argument from the CL.*/
|
||||
if z='' | z="," then z=copies(7, 108) /*let's generate a pretty huge integer.*/
|
||||
numeric digits 1 + max( length(z) ) /*enable use of gigantic numbers. */
|
||||
|
||||
do j=1 for words(z); _=abs(word(z, j)) /*ignore any leading sign, if present.*/
|
||||
say sumDigs(_) ' is the sum of the digits for the number ' _
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
sumDigs: procedure; parse arg N 1 $ 2 ? /*use first decimal digit for the sum. */
|
||||
do while ?\==''; parse var ? _ 2 ?; $=$+_; end /*while*/
|
||||
return $
|
||||
Loading…
Add table
Add a link
Reference in a new issue