Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Knuths-power-tree/Sidef/knuths-power-tree.sidef
Normal file
38
Task/Knuths-power-tree/Sidef/knuths-power-tree.sidef
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
var lvl = [[1]]
|
||||
var p = Hash(1 => 0)
|
||||
|
||||
func path(n) is cached {
|
||||
n || return []
|
||||
while (n !~ p) {
|
||||
var q = []
|
||||
for x in lvl[0] {
|
||||
for y in path(x) {
|
||||
break if (x+y ~~ p)
|
||||
y = x+y
|
||||
p{y} = x
|
||||
q << y
|
||||
}
|
||||
}
|
||||
lvl[0] = q
|
||||
}
|
||||
path(p{n}) + [n]
|
||||
}
|
||||
|
||||
func tree_pow(x, n) {
|
||||
var r = Hash(0 => 1, 1 => x)
|
||||
var p = 0
|
||||
for i in path(n) {
|
||||
r{i} = (r{i-p} * r{p})
|
||||
p = i
|
||||
}
|
||||
r{n}
|
||||
}
|
||||
|
||||
func show_pow(x, n) {
|
||||
var fmt = ("%d: %s\n" + ["%g^%s = %f", "%s^%s = %s"][x.is_int] + "\n")
|
||||
print(fmt % (n, path(n), x, n, tree_pow(x, n)))
|
||||
}
|
||||
|
||||
for x in ^18 { show_pow(2, x) }
|
||||
show_pow(1.1, 81)
|
||||
show_pow(3, 191)
|
||||
Loading…
Add table
Add a link
Reference in a new issue