Skip to content

Instantly share code, notes, and snippets.

# Initialization
data modify storage _ trie set value [[[{v: "0"}, {v: "1"}], [{v: "2"}, {v: "3"}]], [[{v: "4"}, {v: "5"}], [{v: "6"}, {v: "7"}]]]
# If NBTs *were* immutable, indexing will be performed in O(logN) as follows:
# (Unfortunately, in 21w40a, the following code will run in O(N²))
data modify storage _ {} set value {index2: 0b, index1: 1b, index0: 1b}
execute if data storage _ {index2: 0b} run data modify storage _ node2 set from storage _ trie[0]
execute if data storage _ {index2: 1b} run data modify storage _ node2 set from storage _ trie[1]
@intsuc
intsuc / _touch.mcfunction
Last active April 20, 2023 10:28
List-Mapped Trie
scoreboard players operation #_index lmt = #index lmt
execute store result score #size lmt if data storage lmt: ""[]
execute if score #size lmt matches 0 run data modify storage lmt: "" append from storage lmt: branch[]
execute if score #size lmt matches 3 if score #index lmt matches 0.. run data remove storage lmt: ""[2]
execute if score #size lmt matches 2 if score #index lmt matches ..-1 run data modify storage lmt: "" append value []
scoreboard players operation #index lmt += #index lmt
execute store result score #size lmt if data storage lmt: ""[-2][]
execute if score #size lmt matches 0 run data modify storage lmt: ""[-2] append from storage lmt: branch[]
execute if score #size lmt matches 3 if score #index lmt matches 0.. run data remove storage lmt: ""[-2][2]
@intsuc
intsuc / decr.mcfunction
Last active November 27, 2022 11:13
Counter with 1073741761 states
# (Integer.MAX_VALUE >>> 1) - 63 == 1073741760
# execute if data storage _ {counter: 1073741760} run say lower limit exceeded
# Math.nextDown(1.0) == 0.9999999999999999
execute store result storage _ counter int 0.9999999999999999 run data get storage _ counter 1.0
// -------------------------------------------------------------------------------------------------
// scope-sensitive block structured
def foldr0[A, B](f: (A, B) => B, b: B, as: List[A]): B =
def walk0(as: List[A]): B = as match
case Nil => b
case a :: as => f(a, walk0(as))
walk0(as)
def val_of_pol0(cs: List[Int], x: Int): Int =
def walk0(c: Int, a: Int): Int =
@intsuc
intsuc / conlang.md
Last active April 30, 2021 03:57
My ideal constructed language

Goals

  • A language for humans and computers.
    • Unifying a constructed language and a programming language.
  • Consistent.
  • Minimal primitives.
  • Nameless.
    • Names collapse information.
    • Just connect the primitives as-is.
  • Non-phonetic.
say init
@intsuc
intsuc / main.else.mcfunction
Last active January 3, 2021 07:38
if-statement
# e₂
@intsuc
intsuc / is_nanf.mcfunction
Created December 9, 2020 15:14
`is_nanf` implementation independent of NaN equivalence
data modify storage _ zero set value 0.0f
execute store success storage _ non_zero byte 1.0 run data modify storage _ zero set from storage _ value
execute store result storage _ positive_floor int 1.0 run data get storage _ value
execute store result storage _ negative_floor int 1.0 run data get storage _ value -1.0
execute store success storage _ result byte 1.0 if data storage _ {non_zero: true, positive_floor: 0, negative_floor: 0}
@intsuc
intsuc / nan.json
Last active March 9, 2022 07:59
Create NaNd using ScoreboardValue
{
"function": "minecraft:set_attributes",
"modifiers": [
{
"name": "",
"attribute": "minecraft:generic.max_health",
"operation": "addition",
"slot": "mainhand",
"amount": {
"type": "minecraft:score",