From 31045ccfb2c60d86bd86d6ccf5b54b97973e72bc Mon Sep 17 00:00:00 2001 From: AlephAlpha Date: Thu, 26 Sep 2024 14:09:51 +0800 Subject: [PATCH] :oil_drum: --- Nekomata.cabal | 9 +++++---- analysis/corpus.txt | 3 +++ analysis/freq_1gram.txt | 34 +++++++++++++++++----------------- analysis/freq_2gram.txt | 19 ++++++++++++++++--- analysis/freq_3gram.txt | 13 +++++++++++++ analysis/freq_4gram.txt | 10 ++++++++++ analysis/freq_5gram.txt | 7 +++++++ analysis/particles.txt | 2 +- doc/Tutorial.md | 2 ++ src/Nekomata/CodePage.hs | 35 +++++++++++++++++++---------------- test/Eval.hs | 25 +++++++++++++++++++++++++ test/Main.hs | 9 +++++++++ 12 files changed, 127 insertions(+), 41 deletions(-) diff --git a/Nekomata.cabal b/Nekomata.cabal index 2b10b43..1e4105d 100644 --- a/Nekomata.cabal +++ b/Nekomata.cabal @@ -88,7 +88,7 @@ library -- Other library packages from which modules are imported. build-depends: , arithmoi ^>=0.13 - , base >=4.15 && <5 + , base >=4.15 && <5 , containers ^>=0.7 , integer-roots ^>=1.0 , parsec ^>=3.1 @@ -117,7 +117,7 @@ executable Nekomata -- Other library packages from which modules are imported. build-depends: - , base >=4.15 && <5 + , base >=4.15 && <5 , bytestring ^>=0.12 , containers ^>=0.7 , haskeline ^>=0.8 @@ -154,6 +154,7 @@ test-suite Nekomata-test -- Test dependencies. build-depends: - , base >=4.15 && <5 - , hspec ^>=2.11 + , base >=4.15 && <5 + , hspec ^>=2.11 , Nekomata + , unicode-data ^>=0.6 diff --git a/analysis/corpus.txt b/analysis/corpus.txt index 74b8e57..c61d16c 100644 --- a/analysis/corpus.txt +++ b/analysis/corpus.txt @@ -355,3 +355,6 @@ o$2ᵑ{Jĭᵃjᵈ↔,}= ĕ∏Hᵗf R~3DᵉlhÖ*ž 3D3UXᶜi3bᵖ≥ +Ť?~q5Ƃ= +Ṗ@ᵐ~oũ +↔SĦaõ@ diff --git a/analysis/freq_1gram.txt b/analysis/freq_1gram.txt index 62c4feb..792631c 100644 --- a/analysis/freq_1gram.txt +++ b/analysis/freq_1gram.txt @@ -1,10 +1,10 @@ { : 83 $ : 56 -= : 55 += : 56 : : 50 + : 46 ∑ : 39 -ᵐ : 35 +ᵐ : 36 → : 33 R : 33 * : 32 @@ -13,28 +13,29 @@ x : 30 } : 28 - : 26 1 : 25 +o : 25 j : 25 ᵉ : 24 -o : 24 ç : 23 2 : 23 , : 22 ↕ : 22 +Ť : 22 3 : 21 -Ť : 21 +↔ : 21 # : 20 ᵒ : 20 -↔ : 20 +~ : 20 đ : 19 +S : 18 ĭ : 18 u : 18 ᵖ : 18 -~ : 18 -S : 17 +a : 18 p : 17 -a : 17 l : 16 ĉ : 16 +Ƃ : 15 Ɔ : 15 Z : 15 t : 15 @@ -42,39 +43,38 @@ t : 15 Ṁ : 15 Ð : 15 " : 14 -Ƃ : 14 Ň : 14 ∙ : 14 L : 14 ᶦ : 13 < : 13 +q : 13 ᵃ : 13 ≡ : 13 ∫ : 13 ž : 13 ; : 13 -q : 12 ½ : 12 ᶻ : 12 +? : 12 Ë : 12 +@ : 12 ± : 12 ∆ : 12 _ : 12 ʷ : 11 +ũ : 11 ˡ : 11 Ţ : 11 Q : 11 r : 11 ᵑ : 11 -? : 11 ∏ : 11 J : 11 -ũ : 10 E : 10 ≥ : 10 ŋ : 10 c : 10 -@ : 10 % : 10 ᶠ : 10 N : 10 @@ -100,6 +100,7 @@ H : 8 £ : 8 Ø : 8 ɗ : 8 +Ħ : 8 ¦ : 8 ƒ : 8 4 : 8 @@ -108,8 +109,8 @@ H : 8 ᴶ : 7 Ä : 7 / : 7 -Ħ : 7 Ĭ : 7 +õ : 7 Ĉ : 7 ä : 7 Ř : 7 @@ -121,7 +122,6 @@ v : 7 Ď : 6 ≤ : 6 ŧ : 6 -õ : 6 ş : 6 µ : 6 Ŝ : 6 @@ -130,6 +130,7 @@ v : 7 D : 6 ĕ : 6 ṁ : 6 +5 : 6 > : 6 Þ : 6 ∩ : 6 @@ -151,7 +152,7 @@ s : 5 M : 5 8 : 5 √ : 5 -5 : 5 +Ṗ : 5 U : 5 ᵋ : 5 A : 5 @@ -170,7 +171,6 @@ X : 4 6 : 4 ˣ : 4 ň : 4 -Ṗ : 4 ʸ : 4 Ṃ : 3 ḟ : 3 diff --git a/analysis/freq_2gram.txt b/analysis/freq_2gram.txt index b4ecce2..94fca6e 100644 --- a/analysis/freq_2gram.txt +++ b/analysis/freq_2gram.txt @@ -111,6 +111,7 @@ cɗ : 2 ʳ× : 2 Y$ : 2 $Ĭ : 2 +õ@ : 2 {1 : 2 %ŗ : 2 ŗ} : 2 @@ -140,6 +141,7 @@ E∑ : 2 o; : 2 ;↔ : 2 ᵐh : 2 +ᵐ~ : 2 *4 : 2 +→ : 2 Qƥ : 2 @@ -198,6 +200,7 @@ $y : 2 {i : 2 {Ť : 2 ç+ : 2 +5Ƃ : 2 4* : 2 $2 : 2 2÷ : 2 @@ -353,7 +356,6 @@ cʳ : 1 ƊY : 1 Ĭɗ : 1 ¬õ : 1 -õ@ : 1 ˡ∑ : 1 ˡ½ : 1 $Z : 1 @@ -475,7 +477,6 @@ R∫ : 1 ä7 : 1 7+ : 1 +≥ : 1 -ᵐ~ : 1 *5 : 1 5* : 1 4ŋ : 1 @@ -708,7 +709,6 @@ Uˡ : 1 Ťj : 1 ĭ: : 1 çç : 1 -5Ƃ : 1 đ> : 1 :4 : 1 *Ð : 1 @@ -1453,3 +1453,16 @@ Xᶜ : 1 i3 : 1 bᵖ : 1 ᵖ≥ : 1 +Ť? : 1 +?~ : 1 +~q : 1 +q5 : 1 +Ƃ= : 1 +Ṗ@ : 1 +@ᵐ : 1 +~o : 1 +oũ : 1 +↔S : 1 +SĦ : 1 +Ħa : 1 +aõ : 1 diff --git a/analysis/freq_3gram.txt b/analysis/freq_3gram.txt index 7097f1e..6683e0a 100644 --- a/analysis/freq_3gram.txt +++ b/analysis/freq_3gram.txt @@ -1460,3 +1460,16 @@ Xᶜi : 1 i3b : 1 3bᵖ : 1 bᵖ≥ : 1 +Ť?~ : 1 +?~q : 1 +~q5 : 1 +q5Ƃ : 1 +5Ƃ= : 1 +Ṗ@ᵐ : 1 +@ᵐ~ : 1 +ᵐ~o : 1 +~oũ : 1 +↔SĦ : 1 +SĦa : 1 +Ħaõ : 1 +aõ@ : 1 diff --git a/analysis/freq_4gram.txt b/analysis/freq_4gram.txt index bb00f97..299b117 100644 --- a/analysis/freq_4gram.txt +++ b/analysis/freq_4gram.txt @@ -1181,3 +1181,13 @@ Xᶜi3 : 1 ᶜi3b : 1 i3bᵖ : 1 3bᵖ≥ : 1 +Ť?~q : 1 +?~q5 : 1 +~q5Ƃ : 1 +q5Ƃ= : 1 +Ṗ@ᵐ~ : 1 +@ᵐ~o : 1 +ᵐ~oũ : 1 +↔SĦa : 1 +SĦaõ : 1 +Ħaõ@ : 1 diff --git a/analysis/freq_5gram.txt b/analysis/freq_5gram.txt index c887bc7..c6c59c8 100644 --- a/analysis/freq_5gram.txt +++ b/analysis/freq_5gram.txt @@ -925,3 +925,10 @@ UXᶜi3 : 1 Xᶜi3b : 1 ᶜi3bᵖ : 1 i3bᵖ≥ : 1 +Ť?~q5 : 1 +?~q5Ƃ : 1 +~q5Ƃ= : 1 +Ṗ@ᵐ~o : 1 +@ᵐ~oũ : 1 +↔SĦaõ : 1 +SĦaõ@ : 1 diff --git a/analysis/particles.txt b/analysis/particles.txt index f4bf909..cc80387 100644 --- a/analysis/particles.txt +++ b/analysis/particles.txt @@ -4,8 +4,8 @@ particle : with "{" / total ʳ : 0 / 5 ˣ : 0 / 4 ᶾ : 0 / 1 +ᵐ : 3 / 36 ᶻ : 1 / 12 -ᵐ : 3 / 35 ᶜ : 1 / 9 ᵃ : 2 / 13 ᵋ : 1 / 5 diff --git a/doc/Tutorial.md b/doc/Tutorial.md index 3488f62..cd5454c 100644 --- a/doc/Tutorial.md +++ b/doc/Tutorial.md @@ -4,6 +4,8 @@ Nekomata is still in an early stage of development. The syntax and semantics of For installing and using the interpreter, please see [Getting Started](GettingStarted.md). +For documentation of built-in functions and particles, please see [Builtins.md](Builtins.md). + ## The Stack Nekomata is a concatenative language. "Concatenative" is just a fancy word for "stack-based". In a concatenative language, the program is a sequence of instructions that operate on a stack. diff --git a/src/Nekomata/CodePage.hs b/src/Nekomata/CodePage.hs index 210df32..3be900f 100644 --- a/src/Nekomata/CodePage.hs +++ b/src/Nekomata/CodePage.hs @@ -16,25 +16,28 @@ import Data.Word (Word8) {- | Nekomata's custom code page: 256 characters, each representing a single byte. +Unassigned characters are represented by '�'. -} codePage :: String codePage = - "¡¢£¤¥¦§¬±×÷‼←→↔↕" - ++ "¿∆∏∑∕∙√½∩∫≈≠≡µ≤≥" - ++ " !\"#$%&'()*+,-./" - ++ "0123456789:;<=>?" - ++ "@ABCDEFGHIJKLMNO" - ++ "PQRSTUVWXYZ[\\]^_" - ++ "`abcdefghijklmno" - ++ "pqrstuvwxyz{|}~\n" - ++ "ᵃᶜᵈᵉᵋᶠʰᶦʲᴶᵏˡᵐᵚᵑᵒ" - ++ "ᵖʳᵗʷˣʸᶻᶾ��������" - ++ "ÄÅƂÇĈĎÐƊËḞĜĢĦĨĬĻ" - ++ "ŁṀṂŇÖØƆƤṖŘŜŠŞŢŤŬ" - ++ "ŽƵÞ�������������" - ++ "äåƃƀçĉđḍɗēĕƒḟĝïĭ" - ++ "įṁṃɱňŋṇõɔƥŗřşŧũů" - ++ "žƶþ�������������" + concat + [ "¡¢£¤¥¦§¬±×÷‼←→↔↕" + , "¿∆∏∑∕∙√½∩∫≈≠≡µ≤≥" + , " !\"#$%&'()*+,-./" + , "0123456789:;<=>?" + , "@ABCDEFGHIJKLMNO" + , "PQRSTUVWXYZ[\\]^_" + , "`abcdefghijklmno" + , "pqrstuvwxyz{|}~\n" + , "ᵃᶜᵈᵉᵋᶠʰᶦʲᴶᵏˡᵐᵚᵑᵒ" + , "ᵖʳᵗʷˣʸᶻᶾ��������" + , "ÄÅƂÇĈĎÐƊËḞĜĢĦĨĬĻ" + , "ŁṀṂŇÖØƆƤṖŘŜŠŞŢŤŬ" + , "ŽƵÞ�������������" + , "äåƃƀçĉđḍɗēĕƒḟĝïĭ" + , "įṁṃɱňŋṇõɔƥŗřşŧũů" + , "žƶþ�������������" + ] -- | Convert a character to a number. charToInt :: (Num a) => Char -> Maybe a diff --git a/test/Eval.hs b/test/Eval.hs index 23c4750..8d685ff 100644 --- a/test/Eval.hs +++ b/test/Eval.hs @@ -3845,3 +3845,28 @@ testEval = describe "Solutions to Code Golf Stack Exchange challenges" $ do , ("54", first_ "27") , ("1337", first_ "688") ] + describe "q275212: Stuck on Sokoban" $ do + specEval + "Ť?~q5Ƃ=" + [ ("[[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,0],[1,1,1,1,0],[1,1,1,1,1]]", Check False) + , ("[[1,1,1],[0,1,1],[1,1,1]]", Check True) + , ("[[0,1,1],[1,1,1],[1,1,0]]", Check False) + , ("[[0,0,0,0],[0,1,0,1],[0,0,0,0]]", Check True) + , ("[[0,0,0,0],[0,1,0,0],[0,0,0,0]]", Check False) + , ("[[0,1]]", Check False) + , ("[[1,0,1,0]]", Check True) + , ("[[1,0,0,1]]", Check False) + ] + describe "q275291: How many ways can you make change?" $ do + specEval + "Ṗ@ᵐ~oũ" + [ ("1 [\"\",\"cs\",\"2\",\"\",\"\",\"BJ\"]", all_ ["c", "s"]) + , ("2 [\"\",\"cs\",\"2\",\"\",\"\",\"BJ\"]", all_ ["cc", "cs", "ss", "2"]) + , ("3 [\"\",\"cs\",\"2\",\"\",\"\",\"BJ\"]", all_ ["ccc", "ccs", "css", "sss", "2c", "2s"]) + , ("4 [\"\",\"cs\",\"2\",\"\",\"\",\"BJ\"]", all_ ["cccc", "cccs", "ccss", "csss", "ssss", "2cc", "2cs", "2ss", "22"]) + , ("5 [\"\",\"cs\",\"2\",\"\",\"\",\"BJ\"]", all_ ["ccccc", "cccs", "ccss", "csss", "ssss", "2ccc", "2ccs", "2css", "2sss", "22c", "22s", "B", "J"]) + ] + describe "q275700: Reorder a string of length 2^n by permuting the n binary digits of every index" $ do + specEval + "↔SĦaõ@" + [("[1,2,0] [1,1,0,1,0,0,1,0]", all_ ["[1,0,0,1,1,1,0,0]"])] diff --git a/test/Main.hs b/test/Main.hs index 7069c94..e41d726 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -7,6 +7,7 @@ import Nekomata.CodePage import Nekomata.Particle hiding (name, short) import qualified Nekomata.Particle as Particle import Test.Hspec +import Unicode.Char testNames :: Spec testNames = do @@ -36,6 +37,10 @@ testNames = do let codePage' = filter (`notElem` " \\\"\n[]{}0123456789�") codePage all (`elem` codePage') shortNames `shouldBe` True + it "should have short names that are not Unicode modifier letters" $ do + let shortNames = map short builtins + all ((/= ModifierLetter) . generalCategory) shortNames `shouldBe` True + describe "Particle" $ do it "should have unique names" $ do let names = map Particle.name builtinParticles @@ -50,6 +55,10 @@ testNames = do let codePage' = filter (`notElem` " \\\"\n[]{}0123456789�") codePage all (`elem` codePage') shortNames `shouldBe` True + it "should have short names that are Unicode modifier letters" $ do + let shortNames = map Particle.short builtinParticles + all ((== ModifierLetter) . generalCategory) shortNames `shouldBe` True + it "should have different names than builtin functions" $ do let names = map Particle.name builtinParticles let builtins' = map name builtins