September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
1
Task/Digital-root/00META.yaml
Normal file
1
Task/Digital-root/00META.yaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
--- {}
|
||||
22
Task/Digital-root/AppleScript/digital-root.applescript
Normal file
22
Task/Digital-root/AppleScript/digital-root.applescript
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
on digitalroot(N as integer)
|
||||
script math
|
||||
to sum(L)
|
||||
if L = {} then return 0
|
||||
(item 1 of L) + sum(rest of L)
|
||||
end sum
|
||||
end script
|
||||
|
||||
set i to 0
|
||||
set M to N
|
||||
|
||||
repeat until M < 10
|
||||
set digits to the characters of (M as text)
|
||||
set M to math's sum(digits)
|
||||
set i to i + 1
|
||||
end repeat
|
||||
|
||||
{N:N, persistences:i, root:M}
|
||||
end digitalroot
|
||||
|
||||
|
||||
digitalroot(627615)
|
||||
|
|
@ -1,30 +1,31 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
import extensions;
|
||||
import system'routines;
|
||||
import system'collections;
|
||||
|
||||
extension $op
|
||||
extension op
|
||||
{
|
||||
digitalRoot
|
||||
[
|
||||
int additivepersistence := 0.
|
||||
long num := self.
|
||||
get DigitalRoot()
|
||||
{
|
||||
int additivepersistence := 0;
|
||||
long num := self;
|
||||
|
||||
while (num > 9)
|
||||
[
|
||||
num := num literal; toArray; selectBy(:ch)(ch toInt - 48); summarize(LongInteger new).
|
||||
{
|
||||
num := num.Printable.toArray().selectBy:(ch => ch.toInt() - 48).summarize(new LongInteger());
|
||||
|
||||
additivepersistence += 1.
|
||||
].
|
||||
additivepersistence += 1
|
||||
};
|
||||
|
||||
^ { item1 = additivepersistence. item2 = num toInt. }.
|
||||
]
|
||||
^ new Tuple<int,int>(additivepersistence, num.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
(627615l, 39390l, 588225l, 393900588225l) forEach(:num)
|
||||
[
|
||||
var t := num digitalRoot.
|
||||
public program()
|
||||
{
|
||||
new long[]{627615l, 39390l, 588225l, 393900588225l}.forEach:(num)
|
||||
{
|
||||
var t := num.DigitalRoot;
|
||||
|
||||
console printLineFormatted("{0} has additive persistence {1} and digital root {2}", num, t item1, t item2).
|
||||
]
|
||||
].
|
||||
console.printLineFormatted("{0} has additive persistence {1} and digital root {2}", num, t.Item1, t.Item2)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
64
Task/Digital-root/Python/digital-root-2.py
Normal file
64
Task/Digital-root/Python/digital-root-2.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
from functools import (reduce)
|
||||
|
||||
|
||||
# main :: IO ()
|
||||
def main():
|
||||
print (
|
||||
tabulated(digitalRoot)(
|
||||
'Integer -> (additive persistence, digital root):'
|
||||
)([627615, 39390, 588225, 393900588225, 55])
|
||||
)
|
||||
|
||||
|
||||
# digitalRoot :: Int -> (Int, Int)
|
||||
def digitalRoot(n):
|
||||
'''Integer -> (additive persistence, digital root)'''
|
||||
|
||||
# f :: (Int, Int) -> (Int, Int)
|
||||
def f(pn):
|
||||
p, n = pn
|
||||
return (
|
||||
1 + p,
|
||||
reduce(lambda a, x: a + int(x), str(n), 0)
|
||||
)
|
||||
|
||||
# p :: (Int , Int) -> Bool
|
||||
def p(pn):
|
||||
return 10 > pn[1]
|
||||
|
||||
return until(p)(f)(
|
||||
(0, abs(int(n)))
|
||||
)
|
||||
|
||||
|
||||
# GENERIC -------------------------------------------------
|
||||
|
||||
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
|
||||
def compose(g):
|
||||
return lambda f: lambda x: g(f(x))
|
||||
|
||||
|
||||
# tabulated :: (a -> b) -> String -> String
|
||||
def tabulated(f):
|
||||
'''function -> heading -> input List -> tabulated output string'''
|
||||
def go(s, xs):
|
||||
fw = compose(len)(str)
|
||||
w = fw(max(xs, key=fw))
|
||||
return s + '\n' + '\n'.join(list(map(
|
||||
lambda x: str(x).rjust(w, ' ') + ' -> ' + str(f(x)), xs
|
||||
)))
|
||||
return lambda s: lambda xs: go(s, xs)
|
||||
|
||||
|
||||
# until :: (a -> Bool) -> (a -> a) -> a -> a
|
||||
def until(p):
|
||||
def go(f, x):
|
||||
v = x
|
||||
while not p(v):
|
||||
v = f(v)
|
||||
return v
|
||||
return lambda f: lambda x: go(f, x)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
13
Task/Digital-root/SmileBASIC/digital-root.smilebasic
Normal file
13
Task/Digital-root/SmileBASIC/digital-root.smilebasic
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
DEF DIGITAL_ROOT N OUT DR,AP
|
||||
AP=0
|
||||
DR=N
|
||||
WHILE DR>9
|
||||
INC AP
|
||||
STRDR$=STR$(DR)
|
||||
NEWDR=0
|
||||
FOR I=0 TO LEN(STRDR$)-1
|
||||
INC NEWDR,VAL(MID$(STRDR$,I,1))
|
||||
NEXT
|
||||
DR=NEWDR
|
||||
WEND
|
||||
END
|
||||
21
Task/Digital-root/TI-83-BASIC/digital-root.ti-83
Normal file
21
Task/Digital-root/TI-83-BASIC/digital-root.ti-83
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
:ClrHome
|
||||
:1→X
|
||||
:Input ">",Str1
|
||||
:Str1→Str2
|
||||
:Repeat L≤1
|
||||
:Disp Str1
|
||||
:length(Str1→L
|
||||
:L→dim(L₁
|
||||
:seq(expr(sub(Str1,A,1)),A,1,L)→L₁
|
||||
:sum(L₁→N
|
||||
:{0,.5,1→L₂
|
||||
:NL₂→L₃
|
||||
:Med-Med L₂,L₃,Y₁
|
||||
:Equ►String(Y₁,Str1
|
||||
:sub(Str1,1,length(Str1)-3→Str1
|
||||
:X+1→X
|
||||
:End
|
||||
:Pause
|
||||
:ClrHome
|
||||
:Disp Str2,"DIGITAL ROOT",expr(Str1),"ADDITIVE","PERSISTENCE",X
|
||||
:Pause
|
||||
25
Task/Digital-root/VBA/digital-root.vba
Normal file
25
Task/Digital-root/VBA/digital-root.vba
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Option Base 1
|
||||
Private Sub digital_root(n As Variant)
|
||||
Dim s As String, t() As Integer
|
||||
s = CStr(n)
|
||||
ReDim t(Len(s))
|
||||
For i = 1 To Len(s)
|
||||
t(i) = Mid(s, i, 1)
|
||||
Next i
|
||||
Do
|
||||
dr = WorksheetFunction.Sum(t)
|
||||
s = CStr(dr)
|
||||
ReDim t(Len(s))
|
||||
For i = 1 To Len(s)
|
||||
t(i) = Mid(s, i, 1)
|
||||
Next i
|
||||
persistence = persistence + 1
|
||||
Loop Until Len(s) = 1
|
||||
Debug.Print n; "has additive persistence"; persistence; "and digital root of "; dr & ";"
|
||||
End Sub
|
||||
Public Sub main()
|
||||
digital_root 627615
|
||||
digital_root 39390
|
||||
digital_root 588225
|
||||
digital_root 393900588225#
|
||||
End Sub
|
||||
20
Task/Digital-root/Visual-Basic-.NET/digital-root.visual
Normal file
20
Task/Digital-root/Visual-Basic-.NET/digital-root.visual
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
Module Module1
|
||||
|
||||
Function DigitalRoot(num As Long) As Tuple(Of Integer, Integer)
|
||||
Dim additivepersistence = 0
|
||||
While num > 9
|
||||
num = num.ToString().ToCharArray().Sum(Function(x) Integer.Parse(x))
|
||||
additivepersistence = additivepersistence + 1
|
||||
End While
|
||||
Return Tuple.Create(additivepersistence, CType(num, Integer))
|
||||
End Function
|
||||
|
||||
Sub Main()
|
||||
Dim nums = {627615, 39390, 588225, 393900588225}
|
||||
For Each num In nums
|
||||
Dim t = DigitalRoot(num)
|
||||
Console.WriteLine("{0} has additive persistence {1} and digital root {2}", num, t.Item1, t.Item2)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue