@function a:a
summon bat ~ ~ ~ {Attributes:[{Name:generic.armor}]}
data merge storage {a:[[9.,-0.9,-0.69,-0.45,-0.26,-0.14,-0.073,-0.038,-0.02,-0.011,-0.0056,-0.0029,-0.0015,-7.6e-4,-3.9e-4,-2.e-4,-1.1e-4,-5.6e-5,-2.9e-5,-1.5e-5,-7.6e-6,-3.9e-6,-2.e-6,-1.1e-6,-5.6e-7],[-1073741824,1073741824,546146222,278783439,140411372,70331752,35347866,18065629,9420929,5157943,2618732,1354293,700005,354538,181900,93273,51298,26115,13523,6995,3544,1819,933,513,261]],Operation:2,UUID:[I;0,0,0,1]}
execute as @e[type=bat] run function a:b
@function a:b
data modify entity @s Attributes[].Base set from storage i
data modify storage Amount set from storage a[0][0]
data modify entity @s Attributes[].Modifiers append from storage :
execute store result score a run attribute @s generic.armor get
execute if score a matches 1..29 store result entity @s Attributes[].Modifiers[-1].UUID[] int 1 store result score v a run data get storage a[1][0]
attribute @s generic.armor modifier remove 0-0-0-0-1
execute if score a matches 1..29 run scoreboard players operation o a += v a
data remove storage a[][0]
execute if data storage a[][] run function a:b
The function is a:a
.
Takes input in data storage : i
, as a double.
Outputs via a scoreboard o a
, scaled up by 466320149.
If we cannot assume a clean world with no bats, it's +8 to start with a kill @e
command. If we mustn't kill the player it's another +10 for [type=bat]
. If we cannot assume the objective a
already exists it's +34 for scoreboard objectives add a dummy
. If we can't assume the value o
doesn't exist yet it's +29 for scoreboard players set o a 0
.
Using a variant of binary search, we go over the values in a
, multiply our value by 1+x
using attributes, and if it's 1 or more we keep the multiplication and add the log of 1/(1+x)
to our answer. Because the log decreases by less than half in each step we get the correct answer.
We start with a multiplication by 10 to deal with the case of \$0.1\leq x<1\$. We only perform the multiplication if the result is less than 30, to prevent the value going over 100. We need to use 30 because generic.armor
is clamped to it.
Uses the fact that the storage name in Minecraft can be empty, as can the score holder. The scoreboard objective could've been as well, but then scoreboard players operation o a += v a
wouldn't work because spaces are trimmed at the end of each line.
*⍣¯1
or a BQN answer of⋆⁼
count as a non-builtin solution? Both say "the inverse of the function e^x", which is the natural logarithm \$\endgroup\$ln(x)
so yes \$\endgroup\$