From 9ba24680c5e5063816c5f1046e297a342aee32e1 Mon Sep 17 00:00:00 2001 From: SBtree-bit <54784723+SBtree-bit@users.noreply.github.com> Date: Sat, 15 Jun 2024 04:12:27 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Enhance=20speed=20of=20fac?= =?UTF-8?q?torial=20function=20(#218)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../function/factorial/factorial.mcfunction | 18 +++++++++++++++--- docs/CHANGELOG.md | 13 +++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/datapacks/Bookshelf/data/bs.math/function/factorial/factorial.mcfunction b/datapacks/Bookshelf/data/bs.math/function/factorial/factorial.mcfunction index 6a424b04d4..2ed84f5fd8 100644 --- a/datapacks/Bookshelf/data/bs.math/function/factorial/factorial.mcfunction +++ b/datapacks/Bookshelf/data/bs.math/function/factorial/factorial.mcfunction @@ -15,10 +15,22 @@ # Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/math.html#factorial # ------------------------------------------------------------------------------------------------------------ -# Note: Warning, this function does not work if the input is greater than 12 (because the result is greater than 2^31, the limit value of scoreboards) +# Note: Warning, this function does not work properly if the input is greater than 12 (because the result is greater than 2^31, the limit value of scoreboards) execute if score $math.factorial.n bs.in matches 0 run return run scoreboard players set $math.factorial bs.out 1 -execute if score $math.factorial.n bs.in matches 1.. store result score #math.factorial.i bs.data run scoreboard players operation $math.factorial bs.out = $math.factorial.n bs.in -execute if score $math.factorial.n bs.in matches 3.. run function bs.math:factorial/loop +execute if score $math.factorial.n bs.in matches 1 run return run scoreboard players set $math.factorial bs.out 1 +execute if score $math.factorial.n bs.in matches 2 run return run scoreboard players set $math.factorial bs.out 2 +execute if score $math.factorial.n bs.in matches 3 run return run scoreboard players set $math.factorial bs.out 6 +execute if score $math.factorial.n bs.in matches 4 run return run scoreboard players set $math.factorial bs.out 24 +execute if score $math.factorial.n bs.in matches 5 run return run scoreboard players set $math.factorial bs.out 120 +execute if score $math.factorial.n bs.in matches 6 run return run scoreboard players set $math.factorial bs.out 720 +execute if score $math.factorial.n bs.in matches 7 run return run scoreboard players set $math.factorial bs.out 5040 +execute if score $math.factorial.n bs.in matches 8 run return run scoreboard players set $math.factorial bs.out 40320 +execute if score $math.factorial.n bs.in matches 9 run return run scoreboard players set $math.factorial bs.out 362880 +execute if score $math.factorial.n bs.in matches 10 run return run scoreboard players set $math.factorial bs.out 3628800 +execute if score $math.factorial.n bs.in matches 11 run return run scoreboard players set $math.factorial bs.out 39916800 +execute if score $math.factorial.n bs.in matches 12 run return run scoreboard players set $math.factorial bs.out 479001600 +execute store result score #math.factorial.i bs.data run scoreboard players operation $math.factorial bs.out = $math.factorial.n bs.in +function bs.math:factorial/loop return run scoreboard players get $math.factorial bs.out diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 341844f2b2..783c166609 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,15 @@ # 🛠️ Changelog +--- + +## 📦 Bookshelf - 2.2.0 + +### ⚡️ Improvements + +- ([218](https://github.com/Gunivers/Bookshelf/pull/218)) Enhanced speed of factorial function in `bs.math`. + +--- + ## 📦 Bookshelf - 2.1.0 Bookshelf is now based on **Minecraft 1.21**. @@ -27,6 +37,8 @@ Bookshelf is now based on **Minecraft 1.21**. - Added templates for issues. - ([#199](https://github.com/Gunivers/Bookshelf/pull/199)) The different metadata (the manually specified one and the generated one) are now automatically verified at each commit inside a pull request. This prevents them from being forgotten. More information [here](project:contribute/contribution-validation.md). +--- + ## 📦 Bookshelf - 2.0.0 ```{admonition} Breaking changes @@ -59,6 +71,7 @@ This new version is filled with breaking changes. Since maintaining a list of th ### 🐛 Bug fixes - Who knows at this point 🤷‍♂️, almost no legacy code remains... +--- ## 📦 Gunivers Lib - 1.0.0