Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
27
Task/Digital-root/FreeBASIC/digital-root.freebasic
Normal file
27
Task/Digital-root/FreeBASIC/digital-root.freebasic
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function digitalRoot(n As UInteger, ByRef ap As Integer, base_ As Integer = 10) As Integer
|
||||
Dim dr As Integer
|
||||
ap = 0
|
||||
Do
|
||||
dr = 0
|
||||
While n > 0
|
||||
dr += n Mod base_
|
||||
n = n \ base_
|
||||
Wend
|
||||
ap += 1
|
||||
n = dr
|
||||
Loop until dr < base_
|
||||
Return dr
|
||||
End Function
|
||||
|
||||
Dim As Integer dr, ap
|
||||
Dim a(3) As UInteger = {627615, 39390, 588225, 393900588225}
|
||||
For i As Integer = 0 To 3
|
||||
ap = 0
|
||||
dr = digitalRoot(a(i), ap)
|
||||
Print a(i), "Additive Persistence ="; ap, "Digital root ="; dr
|
||||
Print
|
||||
Next
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
14
Task/Digital-root/Nim/digital-root.nim
Normal file
14
Task/Digital-root/Nim/digital-root.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import strutils
|
||||
|
||||
proc droot(n: int64): auto =
|
||||
var x = @[n]
|
||||
while x[x.high] > 10:
|
||||
var s = 0'i64
|
||||
for dig in $x[x.high]:
|
||||
s += parseInt("" & dig)
|
||||
x.add s
|
||||
return (x.len - 1, x[x.high])
|
||||
|
||||
for n in [627615'i64, 39390'i64, 588225'i64, 393900588225'i64]:
|
||||
let (a, d) = droot(n)
|
||||
echo align($n, 12)," has additive persistance ",a," and digital root of ",d
|
||||
4
Task/Digital-root/Oforth/digital-root.oforth
Normal file
4
Task/Digital-root/Oforth/digital-root.oforth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
: sumDigits(n, base) 0 while(n) [ n base /mod ->n + ] ;
|
||||
|
||||
: digitalRoot(n, base)
|
||||
0 while(n 9 >) [ 1 + sumDigits(n, base) ->n ] n swap Pair new ;
|
||||
17
Task/Digital-root/Potion/digital-root.potion
Normal file
17
Task/Digital-root/Potion/digital-root.potion
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
digital = (x) :
|
||||
dr = x string # Digital Root.
|
||||
ap = 0 # Additive Persistence.
|
||||
while (dr length > 1) :
|
||||
sum = 0
|
||||
dr length times (i): sum = sum + dr(i) number integer.
|
||||
dr = sum string
|
||||
ap++
|
||||
.
|
||||
(x, " has additive persistence ", ap,
|
||||
" and digital root ", dr, ";\n") join print
|
||||
.
|
||||
|
||||
digital(627615)
|
||||
digital(39390)
|
||||
digital(588225)
|
||||
digital(393900588225)
|
||||
22
Task/Digital-root/Ring/digital-root.ring
Normal file
22
Task/Digital-root/Ring/digital-root.ring
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
c = 0
|
||||
see "Digital root of 627615 is " + digitRoot(627615, 10) + " persistance is " + c + nl
|
||||
see "Digital root of 39390 is " + digitRoot(39390, 10) + " persistance is " + c + nl
|
||||
see "Digital root of 588225 is " + digitRoot(588225, 10) + " persistance is " + c + nl
|
||||
see "Digital root of 9992 is " + digitRoot(9992, 10) + " persistance is " + c + nl
|
||||
|
||||
func digitRoot n,b
|
||||
c = 0
|
||||
while n >= b
|
||||
c = c + 1
|
||||
n = digSum(n, b)
|
||||
end
|
||||
return n
|
||||
|
||||
func digSum n, b
|
||||
s = 0
|
||||
while n != 0
|
||||
q = floor(n / b)
|
||||
s = s + n - q * b
|
||||
n = q
|
||||
end
|
||||
return s
|
||||
25
Task/Digital-root/Sidef/digital-root.sidef
Normal file
25
Task/Digital-root/Sidef/digital-root.sidef
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
func digroot (r, base = 10) {
|
||||
var root = r.base(base)
|
||||
var persistence = 0
|
||||
while (root.len > 1) {
|
||||
root = root.chars.map{|n| Number(n, 36) }.sum(0).base(base)
|
||||
++persistence
|
||||
}
|
||||
return(persistence, root)
|
||||
}
|
||||
|
||||
var nums = [5, 627615, 39390, 588225, 393900588225]
|
||||
var bases = [2, 3, 8, 10, 16, 36]
|
||||
var fmt = "%25s(%2s): persistance = %s, root = %2s\n"
|
||||
|
||||
nums << (550777011503 *
|
||||
105564897893993412813307040538786690718089963180462913406682192479)
|
||||
|
||||
bases.each { |b|
|
||||
nums.each { |n|
|
||||
var x = n.base(b)
|
||||
x = 'BIG' if (x.len > 25)
|
||||
fmt.printf(x, b, digroot(n, b))
|
||||
}
|
||||
print "\n"
|
||||
}
|
||||
13
Task/Digital-root/Wortel/digital-root.wortel
Normal file
13
Task/Digital-root/Wortel/digital-root.wortel
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
@let {
|
||||
sumDigits ^(@sum @arr)
|
||||
drootl &\@rangef [. sumDigits ^(\~>1 #@arr)]
|
||||
|
||||
droot ^(@last drootl)
|
||||
apers ^(#-drootl)
|
||||
|
||||
[
|
||||
!console.log "[number]: [digital root] [additive persistence] [intermediate sums]"
|
||||
~@each [627615 39390 588225 393900588225]
|
||||
&n !console.log "{n}: {!droot n} {!apers n} {@str !drootl n}"
|
||||
]
|
||||
}
|
||||
20
Task/Digital-root/jq/digital-root-1.jq
Normal file
20
Task/Digital-root/jq/digital-root-1.jq
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def do_until(condition; next):
|
||||
def u: if condition then . else (next|u) end;
|
||||
u;
|
||||
|
||||
# n may be a decimal number or a string representing a decimal number
|
||||
def digital_root(n):
|
||||
# string-only version
|
||||
def dr:
|
||||
# state: [mdr, persist]
|
||||
do_until( .[0] | length == 1;
|
||||
[ (.[0] | explode | map(.-48) | add | tostring), .[1] + 1 ]
|
||||
);
|
||||
[n|tostring, 0] | dr | .[0] |= tonumber;
|
||||
|
||||
def neatly:
|
||||
. as $in
|
||||
| range(0;length)
|
||||
| "\(.): \($in[.])";
|
||||
|
||||
def rjust(n): tostring | (n-length)*" " + .;
|
||||
8
Task/Digital-root/jq/digital-root-2.jq
Normal file
8
Task/Digital-root/jq/digital-root-2.jq
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(
|
||||
" i : [DR, P]",
|
||||
(961038, 923594037444, 670033, 448944221089
|
||||
) as $i
|
||||
| "\($i|rjust(12)): \(digital_root($i))"
|
||||
),
|
||||
"",
|
||||
"digital_root(\"1\" * 100000) => \(digital_root( "1" * 100000))"
|
||||
9
Task/Digital-root/jq/digital-root-3.jq
Normal file
9
Task/Digital-root/jq/digital-root-3.jq
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$ jq -M -n -r -c -f Digital_root.jq
|
||||
|
||||
i : [DR, P]
|
||||
961038: [9,2]
|
||||
923594037444: [9,2]
|
||||
670033: [1,3]
|
||||
448944221089: [1,3]
|
||||
|
||||
digital_root("1" * 100000) => [1,2]
|
||||
Loading…
Add table
Add a link
Reference in a new issue