From 84d15817ad7b0789c61f61d4b05574a38c6594b1 Mon Sep 17 00:00:00 2001 From: AlephAlpha Date: Thu, 27 Jun 2024 14:19:02 +0800 Subject: [PATCH] :seal: --- analysis/corpus.txt | 2 ++ analysis/freq_1gram.txt | 32 ++++++++++++------------ analysis/freq_2gram.txt | 22 +++++++++++------ analysis/freq_3gram.txt | 15 ++++++++++-- analysis/freq_4gram.txt | 11 +++++++++ analysis/freq_5gram.txt | 9 +++++++ analysis/particles.txt | 6 ++--- doc/Builtins.md | 54 +++++++++++++++++++++++++++++++++++++++++ src/Nekomata/Builtin.hs | 45 +++++++++++++++++++++++++++------- test/Eval.hs | 19 +++++++++++++++ 10 files changed, 178 insertions(+), 37 deletions(-) diff --git a/analysis/corpus.txt b/analysis/corpus.txt index 0e9525b..7d72f33 100644 --- a/analysis/corpus.txt +++ b/analysis/corpus.txt @@ -114,6 +114,7 @@ R:∙ ĭᵐ↔Ĭ 258Ɗ+12%→ 12Rᶠ{-Z3¦ +xSᵖ{@∑= RË3÷ ᵗ{±1Ĩ$þÐaOđᵒ{≈∑Ƶ xq§LaĦ* @@ -214,6 +215,7 @@ x:→&xï@Ŝ Ňᵖ{:ÄXÞ½= ˡ{ᵗ≡ĭ?}Å Ɗĭ∑ +ĉᵐ{ᵉĜ#Mĝ}j ᵏ{*+$/1%≡ @ᵃ{x-¬∑}ä- ƒo↔ diff --git a/analysis/freq_1gram.txt b/analysis/freq_1gram.txt index 7c05fec..a67ec5f 100644 --- a/analysis/freq_1gram.txt +++ b/analysis/freq_1gram.txt @@ -1,42 +1,42 @@ -{ : 76 +{ : 78 $ : 55 -= : 51 += : 52 : : 50 -ᵐ : 43 +ᵐ : 44 + : 42 -∑ : 39 +∑ : 40 → : 33 R : 32 ← : 30 * : 30 -} : 28 -j : 26 -x : 26 +} : 29 +j : 27 +x : 27 1 : 25 - : 25 o : 23 ç : 23 +ᵉ : 22 , : 22 +# : 22 ↕ : 22 2 : 22 -ᵉ : 21 -# : 21 Ť : 21 a : 20 ᵒ : 19 ↔ : 19 u : 18 đ : 18 +ᵖ : 18 ~ : 18 -ᵖ : 17 3 : 16 +S : 16 ĭ : 16 l : 16 p : 16 -S : 15 +ĉ : 16 t : 15 Ṁ : 15 -ĉ : 15 Ð : 15 " : 14 J : 14 @@ -83,6 +83,7 @@ z : 10 ∙ : 9 i : 9 C : 9 +@ : 9 ᵈ : 9 P : 8 f : 8 @@ -96,7 +97,6 @@ f : 8 ‼ : 8 ƒ : 8 4 : 8 -@ : 8 Ƶ : 7 H : 7 Ä : 7 @@ -142,6 +142,7 @@ G : 5 Å : 5 s : 5 µ : 5 +M : 5 8 : 5 √ : 5 5 : 5 @@ -150,13 +151,13 @@ s : 5 b : 5 A : 5 v : 5 +ĝ : 4 Ł : 4 Ḟ : 4 k : 4 F : 4 ƥ : 4 D : 4 -M : 4 7 : 4 ÷ : 4 & : 4 @@ -165,7 +166,6 @@ M : 4 ň : 4 Ṗ : 4 õ : 4 -ĝ : 3 Ṃ : 3 Y : 3 T : 3 @@ -179,6 +179,7 @@ U : 3 m : 3 Š : 3 ' : 3 +Ĝ : 2 Ƥ : 2 g : 2 ɱ : 2 @@ -187,7 +188,6 @@ g : 2 ē : 2 K : 2 ¥ : 2 -Ĝ : 1 e : 1 : 1 W : 1 diff --git a/analysis/freq_2gram.txt b/analysis/freq_2gram.txt index 78b5c00..b6d33f0 100644 --- a/analysis/freq_2gram.txt +++ b/analysis/freq_2gram.txt @@ -1,13 +1,14 @@ ᶦ{ : 12 -ᵖ{ : 10 +ᵖ{ : 11 ʷ{ : 9 ˡ{ : 8 ᵑ{ : 7 ᶠ{ : 7 {$ : 6 +ᵐ{ : 6 Jᵐ : 5 {: : 5 -ᵐ{ : 5 +ĉᵐ : 5 Ťđ : 5 ↕= : 4 *→ : 4 @@ -17,7 +18,6 @@ Jᵐ : 5 1Ĩ : 4 ᵏ{ : 4 ᵒ{ : 4 -ĉᵐ : 4 :ᵒ : 4 xŘ : 4 ↕ũ : 4 @@ -35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1 +{@∑ : 1 +@∑= : 1 RË3 : 1 Ë3÷ : 1 ᵗ{± : 1 @@ -663,6 +668,14 @@ XÞ½ : 1 ĭ?} : 1 ?}Å : 1 Ɗĭ∑ : 1 +ĉᵐ{ : 1 +ᵐ{ᵉ : 1 +{ᵉĜ : 1 +ᵉĜ# : 1 +Ĝ#M : 1 +#Mĝ : 1 +Mĝ} : 1 +ĝ}j : 1 ᵏ{* : 1 {*+ : 1 *+$ : 1 @@ -766,7 +779,6 @@ Qao : 1 ŇPᵖ : 1 Pᵖf : 1 RSᵖ : 1 -Sᵖ{ : 1 {:* : 1 :*Ɔ : 1 *Ɔ$ : 1 @@ -893,7 +905,6 @@ U$ᵑ : 1 xqN : 1 qNᵖ : 1 Nᵖ{ : 1 -ᵖ{@ : 1 {@Ť : 1 @Ťů : 1 Ťů} : 1 diff --git a/analysis/freq_4gram.txt b/analysis/freq_4gram.txt index eb690a8..75e106d 100644 --- a/analysis/freq_4gram.txt +++ b/analysis/freq_4gram.txt @@ -210,6 +210,10 @@ Rᶠ{- : 1 ᶠ{-Z : 1 {-Z3 : 1 -Z3¦ : 1 +xSᵖ{ : 1 +Sᵖ{@ : 1 +ᵖ{@∑ : 1 +{@∑= : 1 RË3÷ : 1 ᵗ{±1 : 1 {±1Ĩ : 1 @@ -480,6 +484,13 @@ XÞ½= : 1 ᵗ≡ĭ? : 1 ≡ĭ?} : 1 ĭ?}Å : 1 +ĉᵐ{ᵉ : 1 +ᵐ{ᵉĜ : 1 +{ᵉĜ# : 1 +ᵉĜ#M : 1 +Ĝ#Mĝ : 1 +#Mĝ} : 1 +Mĝ}j : 1 ᵏ{*+ : 1 {*+$ : 1 *+$/ : 1 diff --git a/analysis/freq_5gram.txt b/analysis/freq_5gram.txt index 6fc1ecf..33e3244 100644 --- a/analysis/freq_5gram.txt +++ b/analysis/freq_5gram.txt @@ -137,6 +137,9 @@ Oᵐ{x= : 1 Rᶠ{-Z : 1 ᶠ{-Z3 : 1 {-Z3¦ : 1 +xSᵖ{@ : 1 +Sᵖ{@∑ : 1 +ᵖ{@∑= : 1 ᵗ{±1Ĩ : 1 {±1Ĩ$ : 1 ±1Ĩ$þ : 1 @@ -343,6 +346,12 @@ x:→&x : 1 {ᵗ≡ĭ? : 1 ᵗ≡ĭ?} : 1 ≡ĭ?}Å : 1 +ĉᵐ{ᵉĜ : 1 +ᵐ{ᵉĜ# : 1 +{ᵉĜ#M : 1 +ᵉĜ#Mĝ : 1 +Ĝ#Mĝ} : 1 +#Mĝ}j : 1 ᵏ{*+$ : 1 {*+$/ : 1 *+$/1 : 1 diff --git a/analysis/particles.txt b/analysis/particles.txt index 6edc6b4..b5928f0 100644 --- a/analysis/particles.txt +++ b/analysis/particles.txt @@ -3,17 +3,17 @@ particle : with "{" / total ʳ : 0 / 5 ˣ : 0 / 4 ᶾ : 0 / 1 -ᵉ : 1 / 21 +ᵉ : 1 / 22 ᶻ : 1 / 12 ᶜ : 1 / 9 -ᵐ : 5 / 43 +ᵐ : 6 / 44 ᵃ : 2 / 12 ᵋ : 1 / 5 ᵒ : 4 / 19 ᵚ : 2 / 8 ᵗ : 2 / 7 ᵑ : 7 / 12 -ᵖ : 10 / 17 +ᵖ : 11 / 18 ᵏ : 4 / 6 ᶠ : 7 / 10 ˡ : 8 / 10 diff --git a/doc/Builtins.md b/doc/Builtins.md index dfd0930..48a986a 100644 --- a/doc/Builtins.md +++ b/doc/Builtins.md @@ -1952,10 +1952,25 @@ This means that the list is not equal to the element, and recursively, every ite If it is, push the list itself, otherwise fail. +__Examples__: + +- `[1,2,3] 2f` → Fail +- `[1,3,1] 2f` → `[1,3,1]` +- `[1,[2,3]] 2f` → Fail +- `2 2f` → Fail +- `3 2f` → `3` +- `[1,2,3] [2,3]f` → `[1,2,3]` +- `[1,[2,3]] [2,3]f` → Fail + ### `enumerate` (`x`, `1 -> 2`) Push a list of integers from 0 to the length of the argument minus 1 without popping the original argument. +__Examples__: + +- `[1,2,3]xÐ` → `[[1,2,3],[0,1,2]]` +- `[4,3,2,1]xÐ` → `[[4,3,2,1],[0,1,2,3]]` + ### `rotate` (`Ř`, `2 -> 1`) Rotate a list by a given number of positions. @@ -1964,12 +1979,24 @@ If the first argument is a number, it is converted to a range from 0 to that num This function is automatically vectorized on the second argument. +__Examples__: + +- `[1,2,3] 1Ř` → `[2,3,1]` +- `[1,2,3] 1_Ř` → `[3,1,2]` +- `[1,2,3] [4,5]Ř` → `[[2,3,1],[3,1,2]]` +- `3 1Ř` → `[1,2,0]` + ### `transpose` (`Ť`, `1 -> 1`) Transpose a list of lists. Fail if the sublists are not all of the same length. +__Examples__: + +- `[[1,2],[3,4],[5,6]]Ť` → `[[1,3,5],[2,4,6]]` +- `[[1,2],[3,4,5]]Ť` → Fail + ### `setPartition` (`O`, `1 -> 1`) Partition a list into a list of lists such that their concatenation is a permutation of the original list. @@ -1978,10 +2005,21 @@ If the argument is a number, it is converted to a range from 0 to that number mi This function is non-deterministic. +__Examples__: + +- `[1,2,3]O` → `[[1,2,3]] [[2,3],[1]] [[1,3],[2]] [[3],[1,2]] [[3],[2],[1]]` +- `3O` → `[[0,1,2]] [[1,2],[0]] [[0,2],[1]] [[2],[0,1]] [[2],[1],[0]]` + ### `setMinus` (`∕`, `2 -> 1`) For each element in the second list, remove the first occurrence of that element in the first list. +__Examples__: + +- `[1,2,3,2,1] [2,1]∕` → `[3,2,1]` +- `[1,2,3,2,1] [2,1,1]∕` → `[3,2]` +- `[1,2,3,2,1] [2,4]∕` → `[1,3,2,1]` + ### `index` (`Ĩ`, `2 -> 1`) Get the index of any occurrence of an element in a list. @@ -1992,16 +2030,32 @@ Fail if the element does not occur in the list. This function is non-deterministic. +__Examples__: + +- `[1,2,3,2,1] 2Ĩ` → `1 3` +- `[1,2,3,2,1] 4Ĩ` → Fail + ### `count` (`Ĉ`, `2 -> 1`) Count the number of occurrences of an element in a list. +__Examples__: + +- `[1,2,3,2,1] 2Ĉ` → `2` +- `[1,2,3,2,1] 4Ĉ` → `0` + ### `tally` (`Ţ`, `1 -> 2`) Count the number of occurrences of each element in a list. Return a list of elements and a list of counts in the same order. +__Examples__: + +- `[1,2,3,2,1]ŢÐ` → `[[1,2,3],[2,2,1]]` +- `[3,1,3,2,1]ŢÐ` → `[[3,1,2],[2,2,1]]` +- `[]ŢÐ` → `[[],[]]` + ### `intersect` (`∩`, `2 -> 1`) Get the intersection of two lists. diff --git a/src/Nekomata/Builtin.hs b/src/Nekomata/Builtin.hs index aa4f908..7a133f3 100644 --- a/src/Nekomata/Builtin.hs +++ b/src/Nekomata/Builtin.hs @@ -1776,14 +1776,23 @@ builtins = \This means that the list is not equal to the element, \ \and recursively, every item of the list if free of that element.\n\ \If it is, push the list itself, otherwise fail." - [] + [ ("[1,2,3] 2f", all_ []) + , ("[1,3,1] 2f", all_ ["[1,3,1]"]) + , ("[1,[2,3]] 2f", all_ []) + , ("2 2f", all_ []) + , ("3 2f", all_ ["3"]) + , ("[1,2,3] [2,3]f", all_ ["[1,2,3]"]) + , ("[1,[2,3]] [2,3]f", all_ []) + ] , Builtin "enumerate" 'x' enumerate "Push a list of integers from 0 to the length of the argument minus 1 \ \without popping the original argument." - [] + [ ("[1,2,3]xÐ", all_ ["[[1,2,3],[0,1,2]]"]) + , ("[4,3,2,1]xÐ", all_ ["[[4,3,2,1],[0,1,2,3]]"]) + ] , Builtin "rotate" 'Ř' @@ -1792,14 +1801,20 @@ builtins = \If the first argument is a number, \ \it is converted to a range from 0 to that number minus 1.\n\ \This function is automatically vectorized on the second argument." - [] + [ ("[1,2,3] 1Ř", all_ ["[2,3,1]"]) + , ("[1,2,3] 1_Ř", all_ ["[3,1,2]"]) + , ("[1,2,3] [4,5]Ř", all_ ["[[2,3,1],[3,1,2]]"]) + , ("3 1Ř", all_ ["[1,2,0]"]) + ] , Builtin "transpose" 'Ť' transpose "Transpose a list of lists.\n\ \Fail if the sublists are not all of the same length." - [] + [ ("[[1,2],[3,4],[5,6]]Ť", all_ ["[[1,3,5],[2,4,6]]"]) + , ("[[1,2],[3,4,5]]Ť", all_ []) + ] , Builtin "setPartition" 'O' @@ -1809,14 +1824,19 @@ builtins = \If the argument is a number, \ \it is converted to a range from 0 to that number minus 1.\n\ \This function is non-deterministic." - [] + [ ("[1,2,3]O", all_ ["[[1,2,3]]", "[[2,3],[1]]", "[[1,3],[2]]", "[[3],[1,2]]", "[[3],[2],[1]]"]) + , ("3O", all_ ["[[0,1,2]]", "[[1,2],[0]]", "[[0,2],[1]]", "[[2],[0,1]]", "[[2],[1],[0]]"]) + ] , Builtin "setMinus" '∕' setMinus "For each element in the second list, \ \remove the first occurrence of that element in the first list." - [] + [ ("[1,2,3,2,1] [2,1]∕", all_ ["[3,2,1]"]) + , ("[1,2,3,2,1] [2,1,1]∕", all_ ["[3,2]"]) + , ("[1,2,3,2,1] [2,4]∕", all_ ["[1,3,2,1]"]) + ] , Builtin "index" 'Ĩ' @@ -1825,20 +1845,27 @@ builtins = \The index is 0-based.\n\ \Fail if the element does not occur in the list.\n\ \This function is non-deterministic." - [] + [ ("[1,2,3,2,1] 2Ĩ", all_ ["1", "3"]) + , ("[1,2,3,2,1] 4Ĩ", all_ []) + ] , Builtin "count" 'Ĉ' count "Count the number of occurrences of an element in a list." - [] + [ ("[1,2,3,2,1] 2Ĉ", all_ ["2"]) + , ("[1,2,3,2,1] 4Ĉ", all_ ["0"]) + ] , Builtin "tally" 'Ţ' tally "Count the number of occurrences of each element in a list.\n\ \Return a list of elements and a list of counts in the same order." - [] + [ ("[1,2,3,2,1]ŢÐ", all_ ["[[1,2,3],[2,2,1]]"]) + , ("[3,1,3,2,1]ŢÐ", all_ ["[[3,1,2],[2,2,1]]"]) + , ("[]ŢÐ", all_ ["[[],[]]"]) + ] , Builtin "intersect" '∩' diff --git a/test/Eval.hs b/test/Eval.hs index 9425e38..b5e81c8 100644 --- a/test/Eval.hs +++ b/test/Eval.hs @@ -1279,6 +1279,14 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do , ("11", all_ ["[2,5,8]"]) , ("12", all_ ["[3,6,9]"]) ] + describe "q153221: Generate combinations that add up to a target value" $ do + specEval + "xSᵖ{@∑=" + [ ("[1,2,1,5] 8", all_ ["[0,1,3]", "[1,2,3]"]) + , ("[48/10,95/10,27/10,11/12,10] 148/10", all_ ["[0,4]"]) + , ("[7,8,9,-10,20,27] 17", all_ ["[1,2]", "[0,3,4]", "[3,5]"]) + , ("[1,2,3] 7", all_ []) + ] describe "q153783: The first n numbers without consecutive equal binary digits" $ do specEval "RË3÷" @@ -2335,6 +2343,17 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do , ("2147483647", all_ ["29"]) , ("999999999", all_ ["36"]) ] + describe "q255822: Replace 0s In a String With Their Consecutive Counts" $ do + specEval + "ĉᵐ{ᵉĜ#Mĝ}j" + [ ("\"1234500362000440\"", all_ ["1234523623441"]) + , ("\"123450036200044\"", all_ ["123452362344"]) + , ("\"000000000000\"", all_ ["12"]) + , ("\"0123456789\"", all_ ["1123456789"]) + , ("\"1234567890\"", all_ ["1234567891"]) + , ("\"123456789\"", all_ ["123456789"]) + , ("\"010203004050\"", all_ ["11121324151"]) + ] describe "q256017: CGAC2022 Day 25: When The Planets Align" $ do specEval "ᵏ{*+$/1%≡"