diff --git a/Lang/8080-Assembly/Idiomatically-determine-all-the-lowercase-and-uppercase-letters b/Lang/8080-Assembly/Idiomatically-determine-all-the-lowercase-and-uppercase-letters new file mode 120000 index 0000000000..9a4e5be197 --- /dev/null +++ b/Lang/8080-Assembly/Idiomatically-determine-all-the-lowercase-and-uppercase-letters @@ -0,0 +1 @@ +../../Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/8080-Assembly \ No newline at end of file diff --git a/Lang/AArch64-Assembly/Miller-Rabin-primality-test b/Lang/AArch64-Assembly/Miller-Rabin-primality-test new file mode 120000 index 0000000000..f452839a71 --- /dev/null +++ b/Lang/AArch64-Assembly/Miller-Rabin-primality-test @@ -0,0 +1 @@ +../../Task/Miller-Rabin-primality-test/AArch64-Assembly \ No newline at end of file diff --git a/Lang/ALGOL-68/Abelian-sandpile-model b/Lang/ALGOL-68/Abelian-sandpile-model new file mode 120000 index 0000000000..01bbfb3c77 --- /dev/null +++ b/Lang/ALGOL-68/Abelian-sandpile-model @@ -0,0 +1 @@ +../../Task/Abelian-sandpile-model/ALGOL-68 \ No newline at end of file diff --git a/Lang/ALGOL-68/Square-form-factorization b/Lang/ALGOL-68/Square-form-factorization new file mode 120000 index 0000000000..2759455513 --- /dev/null +++ b/Lang/ALGOL-68/Square-form-factorization @@ -0,0 +1 @@ +../../Task/Square-form-factorization/ALGOL-68 \ No newline at end of file diff --git a/Lang/ALGOL-W/Arithmetic-derivative b/Lang/ALGOL-W/Arithmetic-derivative new file mode 120000 index 0000000000..a3db59a4a9 --- /dev/null +++ b/Lang/ALGOL-W/Arithmetic-derivative @@ -0,0 +1 @@ +../../Task/Arithmetic-derivative/ALGOL-W \ No newline at end of file diff --git a/Lang/ALGOL-W/Deceptive-numbers b/Lang/ALGOL-W/Deceptive-numbers new file mode 120000 index 0000000000..a1723c19f5 --- /dev/null +++ b/Lang/ALGOL-W/Deceptive-numbers @@ -0,0 +1 @@ +../../Task/Deceptive-numbers/ALGOL-W \ No newline at end of file diff --git a/Lang/Acornsoft-Lisp/00-LANG.txt b/Lang/Acornsoft-Lisp/00-LANG.txt index 320ec9f6cf..6f33c84882 100644 --- a/Lang/Acornsoft-Lisp/00-LANG.txt +++ b/Lang/Acornsoft-Lisp/00-LANG.txt @@ -12,6 +12,8 @@ In the original, 1980s version, all built-in defined names were in upper case; however, versions that use lower case instead have become available. +It is a very small Lisp. The only data types are lists, symbols, 16-bit integers, and the types that represent built-in functions and special forms. Even basic list-processing functions such as length, append, reverse, and equal are not built in. It can nonetheless be used to write interesting programs. + ==References== * Arthur Norman and Gillian Cattell, ''LISP on the BBC Microcomputer'' * [[wp:Acornsoft_LISP|Wikipedia:Acornsoft Lisp]] \ No newline at end of file diff --git a/Lang/Acornsoft-Lisp/Combinations-with-repetitions b/Lang/Acornsoft-Lisp/Combinations-with-repetitions new file mode 120000 index 0000000000..70f131d0f0 --- /dev/null +++ b/Lang/Acornsoft-Lisp/Combinations-with-repetitions @@ -0,0 +1 @@ +../../Task/Combinations-with-repetitions/Acornsoft-Lisp \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Deceptive-numbers b/Lang/Amazing-Hopper/Deceptive-numbers new file mode 120000 index 0000000000..8f0aa19f7f --- /dev/null +++ b/Lang/Amazing-Hopper/Deceptive-numbers @@ -0,0 +1 @@ +../../Task/Deceptive-numbers/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Exceptions-Catch-an-exception-thrown-in-a-nested-call b/Lang/Amazing-Hopper/Exceptions-Catch-an-exception-thrown-in-a-nested-call new file mode 120000 index 0000000000..0103e6f8e7 --- /dev/null +++ b/Lang/Amazing-Hopper/Exceptions-Catch-an-exception-thrown-in-a-nested-call @@ -0,0 +1 @@ +../../Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Function-definition b/Lang/Amazing-Hopper/Function-definition new file mode 120000 index 0000000000..9bc2eac985 --- /dev/null +++ b/Lang/Amazing-Hopper/Function-definition @@ -0,0 +1 @@ +../../Task/Function-definition/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Identity-matrix b/Lang/Amazing-Hopper/Identity-matrix new file mode 120000 index 0000000000..4a7e2fd4cf --- /dev/null +++ b/Lang/Amazing-Hopper/Identity-matrix @@ -0,0 +1 @@ +../../Task/Identity-matrix/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-Break b/Lang/Amazing-Hopper/Loops-Break new file mode 120000 index 0000000000..d893889883 --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-Break @@ -0,0 +1 @@ +../../Task/Loops-Break/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-Foreach b/Lang/Amazing-Hopper/Loops-Foreach new file mode 120000 index 0000000000..a96479cd1b --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-Foreach @@ -0,0 +1 @@ +../../Task/Loops-Foreach/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-Increment-loop-index-within-loop-body b/Lang/Amazing-Hopper/Loops-Increment-loop-index-within-loop-body new file mode 120000 index 0000000000..97bc03e8ea --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-Increment-loop-index-within-loop-body @@ -0,0 +1 @@ +../../Task/Loops-Increment-loop-index-within-loop-body/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-N-plus-one-half b/Lang/Amazing-Hopper/Loops-N-plus-one-half new file mode 120000 index 0000000000..34fd3f5304 --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-N-plus-one-half @@ -0,0 +1 @@ +../../Task/Loops-N-plus-one-half/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-Nested b/Lang/Amazing-Hopper/Loops-Nested new file mode 120000 index 0000000000..b565608ed5 --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-Nested @@ -0,0 +1 @@ +../../Task/Loops-Nested/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-While b/Lang/Amazing-Hopper/Loops-While new file mode 120000 index 0000000000..be6130bb45 --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-While @@ -0,0 +1 @@ +../../Task/Loops-While/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Loops-With-multiple-ranges b/Lang/Amazing-Hopper/Loops-With-multiple-ranges new file mode 120000 index 0000000000..3c9f0de0dc --- /dev/null +++ b/Lang/Amazing-Hopper/Loops-With-multiple-ranges @@ -0,0 +1 @@ +../../Task/Loops-With-multiple-ranges/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/String-append b/Lang/Amazing-Hopper/String-append new file mode 120000 index 0000000000..6d208e62ad --- /dev/null +++ b/Lang/Amazing-Hopper/String-append @@ -0,0 +1 @@ +../../Task/String-append/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Strip-a-set-of-characters-from-a-string b/Lang/Amazing-Hopper/Strip-a-set-of-characters-from-a-string new file mode 120000 index 0000000000..d713785f03 --- /dev/null +++ b/Lang/Amazing-Hopper/Strip-a-set-of-characters-from-a-string @@ -0,0 +1 @@ +../../Task/Strip-a-set-of-characters-from-a-string/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Amazing-Hopper/Strip-whitespace-from-a-string-Top-and-tail b/Lang/Amazing-Hopper/Strip-whitespace-from-a-string-Top-and-tail new file mode 120000 index 0000000000..a5452c52ea --- /dev/null +++ b/Lang/Amazing-Hopper/Strip-whitespace-from-a-string-Top-and-tail @@ -0,0 +1 @@ +../../Task/Strip-whitespace-from-a-string-Top-and-tail/Amazing-Hopper \ No newline at end of file diff --git a/Lang/Bc/Deceptive-numbers b/Lang/Bc/Deceptive-numbers new file mode 120000 index 0000000000..244bb00858 --- /dev/null +++ b/Lang/Bc/Deceptive-numbers @@ -0,0 +1 @@ +../../Task/Deceptive-numbers/Bc \ No newline at end of file diff --git a/Lang/C++/Square-form-factorization b/Lang/C++/Square-form-factorization new file mode 120000 index 0000000000..02b9bbca28 --- /dev/null +++ b/Lang/C++/Square-form-factorization @@ -0,0 +1 @@ +../../Task/Square-form-factorization/C++ \ No newline at end of file diff --git a/Lang/C++/Terminal-control-Coloured-text b/Lang/C++/Terminal-control-Coloured-text new file mode 120000 index 0000000000..d28321a098 --- /dev/null +++ b/Lang/C++/Terminal-control-Coloured-text @@ -0,0 +1 @@ +../../Task/Terminal-control-Coloured-text/C++ \ No newline at end of file diff --git a/Lang/C++/The-sieve-of-Sundaram b/Lang/C++/The-sieve-of-Sundaram new file mode 120000 index 0000000000..e0a2a39b88 --- /dev/null +++ b/Lang/C++/The-sieve-of-Sundaram @@ -0,0 +1 @@ +../../Task/The-sieve-of-Sundaram/C++ \ No newline at end of file diff --git a/Lang/C++/Tonelli-Shanks-algorithm b/Lang/C++/Tonelli-Shanks-algorithm new file mode 120000 index 0000000000..c3fb6b9d19 --- /dev/null +++ b/Lang/C++/Tonelli-Shanks-algorithm @@ -0,0 +1 @@ +../../Task/Tonelli-Shanks-algorithm/C++ \ No newline at end of file diff --git a/Lang/Dc/Terminal-control-Ringing-the-terminal-bell b/Lang/Dc/Terminal-control-Ringing-the-terminal-bell new file mode 120000 index 0000000000..0790097004 --- /dev/null +++ b/Lang/Dc/Terminal-control-Ringing-the-terminal-bell @@ -0,0 +1 @@ +../../Task/Terminal-control-Ringing-the-terminal-bell/Dc \ No newline at end of file diff --git a/Lang/Draco/Arithmetic-numbers b/Lang/Draco/Arithmetic-numbers new file mode 120000 index 0000000000..f4a20d710c --- /dev/null +++ b/Lang/Draco/Arithmetic-numbers @@ -0,0 +1 @@ +../../Task/Arithmetic-numbers/Draco \ No newline at end of file diff --git a/Lang/EasyLang/4-rings-or-4-squares-puzzle b/Lang/EasyLang/4-rings-or-4-squares-puzzle new file mode 120000 index 0000000000..f8f08276c2 --- /dev/null +++ b/Lang/EasyLang/4-rings-or-4-squares-puzzle @@ -0,0 +1 @@ +../../Task/4-rings-or-4-squares-puzzle/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/ABC-problem b/Lang/EasyLang/ABC-problem new file mode 120000 index 0000000000..18a0732918 --- /dev/null +++ b/Lang/EasyLang/ABC-problem @@ -0,0 +1 @@ +../../Task/ABC-problem/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Abundant-deficient-and-perfect-number-classifications b/Lang/EasyLang/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..3d14411268 --- /dev/null +++ b/Lang/EasyLang/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Abundant-odd-numbers b/Lang/EasyLang/Abundant-odd-numbers new file mode 120000 index 0000000000..78400648db --- /dev/null +++ b/Lang/EasyLang/Abundant-odd-numbers @@ -0,0 +1 @@ +../../Task/Abundant-odd-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Align-columns b/Lang/EasyLang/Align-columns new file mode 120000 index 0000000000..09ddaaad2b --- /dev/null +++ b/Lang/EasyLang/Align-columns @@ -0,0 +1 @@ +../../Task/Align-columns/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Aliquot-sequence-classifications b/Lang/EasyLang/Aliquot-sequence-classifications new file mode 120000 index 0000000000..3085d38bff --- /dev/null +++ b/Lang/EasyLang/Aliquot-sequence-classifications @@ -0,0 +1 @@ +../../Task/Aliquot-sequence-classifications/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Almost-prime b/Lang/EasyLang/Almost-prime new file mode 120000 index 0000000000..f2e37e388e --- /dev/null +++ b/Lang/EasyLang/Almost-prime @@ -0,0 +1 @@ +../../Task/Almost-prime/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Angle-difference-between-two-bearings b/Lang/EasyLang/Angle-difference-between-two-bearings new file mode 120000 index 0000000000..a2eba57e69 --- /dev/null +++ b/Lang/EasyLang/Angle-difference-between-two-bearings @@ -0,0 +1 @@ +../../Task/Angle-difference-between-two-bearings/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Angles-geometric-normalization-and-conversion b/Lang/EasyLang/Angles-geometric-normalization-and-conversion new file mode 120000 index 0000000000..afa5d2ad31 --- /dev/null +++ b/Lang/EasyLang/Angles-geometric-normalization-and-conversion @@ -0,0 +1 @@ +../../Task/Angles-geometric-normalization-and-conversion/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Anti-primes b/Lang/EasyLang/Anti-primes new file mode 120000 index 0000000000..9f890a169f --- /dev/null +++ b/Lang/EasyLang/Anti-primes @@ -0,0 +1 @@ +../../Task/Anti-primes/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Arithmetic-geometric-mean b/Lang/EasyLang/Arithmetic-geometric-mean new file mode 120000 index 0000000000..49e1f0e922 --- /dev/null +++ b/Lang/EasyLang/Arithmetic-geometric-mean @@ -0,0 +1 @@ +../../Task/Arithmetic-geometric-mean/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Arithmetic-geometric-mean-Calculate-Pi b/Lang/EasyLang/Arithmetic-geometric-mean-Calculate-Pi new file mode 120000 index 0000000000..3be49c9de9 --- /dev/null +++ b/Lang/EasyLang/Arithmetic-geometric-mean-Calculate-Pi @@ -0,0 +1 @@ +../../Task/Arithmetic-geometric-mean-Calculate-Pi/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Ascending-primes b/Lang/EasyLang/Ascending-primes new file mode 120000 index 0000000000..f20d5f06bb --- /dev/null +++ b/Lang/EasyLang/Ascending-primes @@ -0,0 +1 @@ +../../Task/Ascending-primes/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Attractive-numbers b/Lang/EasyLang/Attractive-numbers new file mode 120000 index 0000000000..cec03b0311 --- /dev/null +++ b/Lang/EasyLang/Attractive-numbers @@ -0,0 +1 @@ +../../Task/Attractive-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Averages-Mean-angle b/Lang/EasyLang/Averages-Mean-angle new file mode 120000 index 0000000000..24f9f1474b --- /dev/null +++ b/Lang/EasyLang/Averages-Mean-angle @@ -0,0 +1 @@ +../../Task/Averages-Mean-angle/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Averages-Mean-time-of-day b/Lang/EasyLang/Averages-Mean-time-of-day new file mode 120000 index 0000000000..860451fa65 --- /dev/null +++ b/Lang/EasyLang/Averages-Mean-time-of-day @@ -0,0 +1 @@ +../../Task/Averages-Mean-time-of-day/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Averages-Root-mean-square b/Lang/EasyLang/Averages-Root-mean-square new file mode 120000 index 0000000000..c6747681ce --- /dev/null +++ b/Lang/EasyLang/Averages-Root-mean-square @@ -0,0 +1 @@ +../../Task/Averages-Root-mean-square/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Bell-numbers b/Lang/EasyLang/Bell-numbers new file mode 120000 index 0000000000..127123a7d4 --- /dev/null +++ b/Lang/EasyLang/Bell-numbers @@ -0,0 +1 @@ +../../Task/Bell-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Bioinformatics-base-count b/Lang/EasyLang/Bioinformatics-base-count new file mode 120000 index 0000000000..3bc65db849 --- /dev/null +++ b/Lang/EasyLang/Bioinformatics-base-count @@ -0,0 +1 @@ +../../Task/Bioinformatics-base-count/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Blum-integer b/Lang/EasyLang/Blum-integer new file mode 120000 index 0000000000..bc9517af8d --- /dev/null +++ b/Lang/EasyLang/Blum-integer @@ -0,0 +1 @@ +../../Task/Blum-integer/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Compare-a-list-of-strings b/Lang/EasyLang/Compare-a-list-of-strings new file mode 120000 index 0000000000..c992d49d46 --- /dev/null +++ b/Lang/EasyLang/Compare-a-list-of-strings @@ -0,0 +1 @@ +../../Task/Compare-a-list-of-strings/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Count-occurrences-of-a-substring b/Lang/EasyLang/Count-occurrences-of-a-substring new file mode 120000 index 0000000000..4597b1fb7c --- /dev/null +++ b/Lang/EasyLang/Count-occurrences-of-a-substring @@ -0,0 +1 @@ +../../Task/Count-occurrences-of-a-substring/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Curzon-numbers b/Lang/EasyLang/Curzon-numbers new file mode 120000 index 0000000000..570e1186b0 --- /dev/null +++ b/Lang/EasyLang/Curzon-numbers @@ -0,0 +1 @@ +../../Task/Curzon-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Determine-if-a-string-has-all-the-same-characters b/Lang/EasyLang/Determine-if-a-string-has-all-the-same-characters new file mode 120000 index 0000000000..164270fc83 --- /dev/null +++ b/Lang/EasyLang/Determine-if-a-string-has-all-the-same-characters @@ -0,0 +1 @@ +../../Task/Determine-if-a-string-has-all-the-same-characters/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Determine-if-a-string-has-all-unique-characters b/Lang/EasyLang/Determine-if-a-string-has-all-unique-characters new file mode 120000 index 0000000000..cec3ed07b3 --- /dev/null +++ b/Lang/EasyLang/Determine-if-a-string-has-all-unique-characters @@ -0,0 +1 @@ +../../Task/Determine-if-a-string-has-all-unique-characters/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Eban-numbers b/Lang/EasyLang/Eban-numbers new file mode 120000 index 0000000000..37afec99ff --- /dev/null +++ b/Lang/EasyLang/Eban-numbers @@ -0,0 +1 @@ +../../Task/Eban-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Entropy b/Lang/EasyLang/Entropy new file mode 120000 index 0000000000..e06e8d9283 --- /dev/null +++ b/Lang/EasyLang/Entropy @@ -0,0 +1 @@ +../../Task/Entropy/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Even-or-odd b/Lang/EasyLang/Even-or-odd new file mode 120000 index 0000000000..b33718ea9f --- /dev/null +++ b/Lang/EasyLang/Even-or-odd @@ -0,0 +1 @@ +../../Task/Even-or-odd/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Exponentiation-operator b/Lang/EasyLang/Exponentiation-operator new file mode 120000 index 0000000000..5f8b2cb64c --- /dev/null +++ b/Lang/EasyLang/Exponentiation-operator @@ -0,0 +1 @@ +../../Task/Exponentiation-operator/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Find-common-directory-path b/Lang/EasyLang/Find-common-directory-path new file mode 120000 index 0000000000..2f1337d020 --- /dev/null +++ b/Lang/EasyLang/Find-common-directory-path @@ -0,0 +1 @@ +../../Task/Find-common-directory-path/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Find-the-intersection-of-a-line-with-a-plane b/Lang/EasyLang/Find-the-intersection-of-a-line-with-a-plane new file mode 120000 index 0000000000..ec7aff0f03 --- /dev/null +++ b/Lang/EasyLang/Find-the-intersection-of-a-line-with-a-plane @@ -0,0 +1 @@ +../../Task/Find-the-intersection-of-a-line-with-a-plane/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Hilbert-curve b/Lang/EasyLang/Hilbert-curve new file mode 120000 index 0000000000..ff5cdcedf4 --- /dev/null +++ b/Lang/EasyLang/Hilbert-curve @@ -0,0 +1 @@ +../../Task/Hilbert-curve/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Identity-matrix b/Lang/EasyLang/Identity-matrix new file mode 120000 index 0000000000..301b6d2c90 --- /dev/null +++ b/Lang/EasyLang/Identity-matrix @@ -0,0 +1 @@ +../../Task/Identity-matrix/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Idiomatically-determine-all-the-lowercase-and-uppercase-letters b/Lang/EasyLang/Idiomatically-determine-all-the-lowercase-and-uppercase-letters new file mode 120000 index 0000000000..116f99247d --- /dev/null +++ b/Lang/EasyLang/Idiomatically-determine-all-the-lowercase-and-uppercase-letters @@ -0,0 +1 @@ +../../Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Jewels-and-stones b/Lang/EasyLang/Jewels-and-stones new file mode 120000 index 0000000000..79405be237 --- /dev/null +++ b/Lang/EasyLang/Jewels-and-stones @@ -0,0 +1 @@ +../../Task/Jewels-and-stones/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Jordan-P-lya-numbers b/Lang/EasyLang/Jordan-P-lya-numbers new file mode 120000 index 0000000000..dda236d7e7 --- /dev/null +++ b/Lang/EasyLang/Jordan-P-lya-numbers @@ -0,0 +1 @@ +../../Task/Jordan-P-lya-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Lah-numbers b/Lang/EasyLang/Lah-numbers new file mode 120000 index 0000000000..911d26c4d0 --- /dev/null +++ b/Lang/EasyLang/Lah-numbers @@ -0,0 +1 @@ +../../Task/Lah-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Letter-frequency b/Lang/EasyLang/Letter-frequency new file mode 120000 index 0000000000..a5bfe27f68 --- /dev/null +++ b/Lang/EasyLang/Letter-frequency @@ -0,0 +1 @@ +../../Task/Letter-frequency/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Levenshtein-distance b/Lang/EasyLang/Levenshtein-distance new file mode 120000 index 0000000000..85d30bfcbc --- /dev/null +++ b/Lang/EasyLang/Levenshtein-distance @@ -0,0 +1 @@ +../../Task/Levenshtein-distance/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Longest-common-substring b/Lang/EasyLang/Longest-common-substring new file mode 120000 index 0000000000..dae80ce24b --- /dev/null +++ b/Lang/EasyLang/Longest-common-substring @@ -0,0 +1 @@ +../../Task/Longest-common-substring/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Loops-Increment-loop-index-within-loop-body b/Lang/EasyLang/Loops-Increment-loop-index-within-loop-body new file mode 120000 index 0000000000..f96a49aa6f --- /dev/null +++ b/Lang/EasyLang/Loops-Increment-loop-index-within-loop-body @@ -0,0 +1 @@ +../../Task/Loops-Increment-loop-index-within-loop-body/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Matrix-transposition b/Lang/EasyLang/Matrix-transposition new file mode 120000 index 0000000000..8c003a6e84 --- /dev/null +++ b/Lang/EasyLang/Matrix-transposition @@ -0,0 +1 @@ +../../Task/Matrix-transposition/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Monty-Hall-problem b/Lang/EasyLang/Monty-Hall-problem new file mode 120000 index 0000000000..e126dc0d13 --- /dev/null +++ b/Lang/EasyLang/Monty-Hall-problem @@ -0,0 +1 @@ +../../Task/Monty-Hall-problem/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors b/Lang/EasyLang/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors new file mode 120000 index 0000000000..9d8dc2f2d3 --- /dev/null +++ b/Lang/EasyLang/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors @@ -0,0 +1 @@ +../../Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Own-digits-power-sum b/Lang/EasyLang/Own-digits-power-sum new file mode 120000 index 0000000000..2d5efd33b1 --- /dev/null +++ b/Lang/EasyLang/Own-digits-power-sum @@ -0,0 +1 @@ +../../Task/Own-digits-power-sum/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Pangram-checker b/Lang/EasyLang/Pangram-checker new file mode 120000 index 0000000000..f7779ae2cf --- /dev/null +++ b/Lang/EasyLang/Pangram-checker @@ -0,0 +1 @@ +../../Task/Pangram-checker/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Perfect-numbers b/Lang/EasyLang/Perfect-numbers new file mode 120000 index 0000000000..7b9c303b67 --- /dev/null +++ b/Lang/EasyLang/Perfect-numbers @@ -0,0 +1 @@ +../../Task/Perfect-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Permutations-Derangements b/Lang/EasyLang/Permutations-Derangements new file mode 120000 index 0000000000..1993da537c --- /dev/null +++ b/Lang/EasyLang/Permutations-Derangements @@ -0,0 +1 @@ +../../Task/Permutations-Derangements/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Price-fraction b/Lang/EasyLang/Price-fraction new file mode 120000 index 0000000000..425841fb81 --- /dev/null +++ b/Lang/EasyLang/Price-fraction @@ -0,0 +1 @@ +../../Task/Price-fraction/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Rare-numbers b/Lang/EasyLang/Rare-numbers new file mode 120000 index 0000000000..015d554002 --- /dev/null +++ b/Lang/EasyLang/Rare-numbers @@ -0,0 +1 @@ +../../Task/Rare-numbers/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Semiprime b/Lang/EasyLang/Semiprime new file mode 120000 index 0000000000..ed622fe02f --- /dev/null +++ b/Lang/EasyLang/Semiprime @@ -0,0 +1 @@ +../../Task/Semiprime/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Sequence:-smallest-number-with-exactly-n-divisors b/Lang/EasyLang/Sequence:-smallest-number-with-exactly-n-divisors new file mode 120000 index 0000000000..cbc83c21b2 --- /dev/null +++ b/Lang/EasyLang/Sequence:-smallest-number-with-exactly-n-divisors @@ -0,0 +1 @@ +../../Task/Sequence:-smallest-number-with-exactly-n-divisors/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Short-circuit-evaluation b/Lang/EasyLang/Short-circuit-evaluation new file mode 120000 index 0000000000..13fc1386b3 --- /dev/null +++ b/Lang/EasyLang/Short-circuit-evaluation @@ -0,0 +1 @@ +../../Task/Short-circuit-evaluation/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Sisyphus-sequence b/Lang/EasyLang/Sisyphus-sequence new file mode 120000 index 0000000000..e2e1045744 --- /dev/null +++ b/Lang/EasyLang/Sisyphus-sequence @@ -0,0 +1 @@ +../../Task/Sisyphus-sequence/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Sleep b/Lang/EasyLang/Sleep new file mode 120000 index 0000000000..35689819c7 --- /dev/null +++ b/Lang/EasyLang/Sleep @@ -0,0 +1 @@ +../../Task/Sleep/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Square-form-factorization b/Lang/EasyLang/Square-form-factorization new file mode 120000 index 0000000000..02496c127b --- /dev/null +++ b/Lang/EasyLang/Square-form-factorization @@ -0,0 +1 @@ +../../Task/Square-form-factorization/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Stirling-numbers-of-the-first-kind b/Lang/EasyLang/Stirling-numbers-of-the-first-kind new file mode 120000 index 0000000000..3bef923a99 --- /dev/null +++ b/Lang/EasyLang/Stirling-numbers-of-the-first-kind @@ -0,0 +1 @@ +../../Task/Stirling-numbers-of-the-first-kind/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Stirling-numbers-of-the-second-kind b/Lang/EasyLang/Stirling-numbers-of-the-second-kind new file mode 120000 index 0000000000..c6b742cdc9 --- /dev/null +++ b/Lang/EasyLang/Stirling-numbers-of-the-second-kind @@ -0,0 +1 @@ +../../Task/Stirling-numbers-of-the-second-kind/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/String-matching b/Lang/EasyLang/String-matching new file mode 120000 index 0000000000..8b66f9754a --- /dev/null +++ b/Lang/EasyLang/String-matching @@ -0,0 +1 @@ +../../Task/String-matching/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Strip-a-set-of-characters-from-a-string b/Lang/EasyLang/Strip-a-set-of-characters-from-a-string new file mode 120000 index 0000000000..343f54ba3e --- /dev/null +++ b/Lang/EasyLang/Strip-a-set-of-characters-from-a-string @@ -0,0 +1 @@ +../../Task/Strip-a-set-of-characters-from-a-string/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Strip-block-comments b/Lang/EasyLang/Strip-block-comments new file mode 120000 index 0000000000..afef7eb48f --- /dev/null +++ b/Lang/EasyLang/Strip-block-comments @@ -0,0 +1 @@ +../../Task/Strip-block-comments/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Strip-comments-from-a-string b/Lang/EasyLang/Strip-comments-from-a-string new file mode 120000 index 0000000000..8ec4466745 --- /dev/null +++ b/Lang/EasyLang/Strip-comments-from-a-string @@ -0,0 +1 @@ +../../Task/Strip-comments-from-a-string/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Strip-control-codes-and-extended-characters-from-a-string b/Lang/EasyLang/Strip-control-codes-and-extended-characters-from-a-string new file mode 120000 index 0000000000..7c122382c3 --- /dev/null +++ b/Lang/EasyLang/Strip-control-codes-and-extended-characters-from-a-string @@ -0,0 +1 @@ +../../Task/Strip-control-codes-and-extended-characters-from-a-string/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Strip-whitespace-from-a-string-Top-and-tail b/Lang/EasyLang/Strip-whitespace-from-a-string-Top-and-tail new file mode 120000 index 0000000000..af79da1705 --- /dev/null +++ b/Lang/EasyLang/Strip-whitespace-from-a-string-Top-and-tail @@ -0,0 +1 @@ +../../Task/Strip-whitespace-from-a-string-Top-and-tail/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Sylvesters-sequence b/Lang/EasyLang/Sylvesters-sequence new file mode 120000 index 0000000000..14370fd966 --- /dev/null +++ b/Lang/EasyLang/Sylvesters-sequence @@ -0,0 +1 @@ +../../Task/Sylvesters-sequence/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Time-a-function b/Lang/EasyLang/Time-a-function new file mode 120000 index 0000000000..3bc0053e39 --- /dev/null +++ b/Lang/EasyLang/Time-a-function @@ -0,0 +1 @@ +../../Task/Time-a-function/EasyLang \ No newline at end of file diff --git a/Lang/EasyLang/Tokenize-a-string b/Lang/EasyLang/Tokenize-a-string new file mode 120000 index 0000000000..bd4e1f9903 --- /dev/null +++ b/Lang/EasyLang/Tokenize-a-string @@ -0,0 +1 @@ +../../Task/Tokenize-a-string/EasyLang \ No newline at end of file diff --git a/Lang/F-Sharp/Hilbert-curve b/Lang/F-Sharp/Hilbert-curve new file mode 120000 index 0000000000..556d6ba0f5 --- /dev/null +++ b/Lang/F-Sharp/Hilbert-curve @@ -0,0 +1 @@ +../../Task/Hilbert-curve/F-Sharp \ No newline at end of file diff --git a/Lang/FutureBasic/Bulls-and-cows b/Lang/FutureBasic/Bulls-and-cows new file mode 120000 index 0000000000..cd60c68b03 --- /dev/null +++ b/Lang/FutureBasic/Bulls-and-cows @@ -0,0 +1 @@ +../../Task/Bulls-and-cows/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Maze-generation b/Lang/FutureBasic/Maze-generation new file mode 120000 index 0000000000..096f10ac2d --- /dev/null +++ b/Lang/FutureBasic/Maze-generation @@ -0,0 +1 @@ +../../Task/Maze-generation/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Pick-random-element b/Lang/FutureBasic/Pick-random-element new file mode 120000 index 0000000000..cc4f33408b --- /dev/null +++ b/Lang/FutureBasic/Pick-random-element @@ -0,0 +1 @@ +../../Task/Pick-random-element/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/String-append b/Lang/FutureBasic/String-append new file mode 120000 index 0000000000..223107d369 --- /dev/null +++ b/Lang/FutureBasic/String-append @@ -0,0 +1 @@ +../../Task/String-append/FutureBasic \ No newline at end of file diff --git a/Lang/Grain/Anti-primes b/Lang/Grain/Anti-primes new file mode 120000 index 0000000000..342f59f5d1 --- /dev/null +++ b/Lang/Grain/Anti-primes @@ -0,0 +1 @@ +../../Task/Anti-primes/Grain \ No newline at end of file diff --git a/Lang/Grain/Fibonacci-sequence b/Lang/Grain/Fibonacci-sequence new file mode 120000 index 0000000000..11301aac08 --- /dev/null +++ b/Lang/Grain/Fibonacci-sequence @@ -0,0 +1 @@ +../../Task/Fibonacci-sequence/Grain \ No newline at end of file diff --git a/Lang/Hoon/Greatest-common-divisor b/Lang/Hoon/Greatest-common-divisor new file mode 120000 index 0000000000..7821bac912 --- /dev/null +++ b/Lang/Hoon/Greatest-common-divisor @@ -0,0 +1 @@ +../../Task/Greatest-common-divisor/Hoon \ No newline at end of file diff --git a/Lang/Insitux/List-comprehensions b/Lang/Insitux/List-comprehensions new file mode 120000 index 0000000000..9b60b04ac9 --- /dev/null +++ b/Lang/Insitux/List-comprehensions @@ -0,0 +1 @@ +../../Task/List-comprehensions/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Phrase-reversals b/Lang/Insitux/Phrase-reversals new file mode 120000 index 0000000000..7698e83cc1 --- /dev/null +++ b/Lang/Insitux/Phrase-reversals @@ -0,0 +1 @@ +../../Task/Phrase-reversals/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Short-circuit-evaluation b/Lang/Insitux/Short-circuit-evaluation new file mode 120000 index 0000000000..183c70370b --- /dev/null +++ b/Lang/Insitux/Short-circuit-evaluation @@ -0,0 +1 @@ +../../Task/Short-circuit-evaluation/Insitux \ No newline at end of file diff --git a/Lang/Java/SHA-1 b/Lang/Java/SHA-1 new file mode 120000 index 0000000000..440d54c6ce --- /dev/null +++ b/Lang/Java/SHA-1 @@ -0,0 +1 @@ +../../Task/SHA-1/Java \ No newline at end of file diff --git a/Lang/Java/SHA-256 b/Lang/Java/SHA-256 new file mode 120000 index 0000000000..b00a629111 --- /dev/null +++ b/Lang/Java/SHA-256 @@ -0,0 +1 @@ +../../Task/SHA-256/Java \ No newline at end of file diff --git a/Lang/Java/Sisyphus-sequence b/Lang/Java/Sisyphus-sequence new file mode 120000 index 0000000000..49fc399860 --- /dev/null +++ b/Lang/Java/Sisyphus-sequence @@ -0,0 +1 @@ +../../Task/Sisyphus-sequence/Java \ No newline at end of file diff --git a/Lang/Java/Smarandache-Wellin-primes b/Lang/Java/Smarandache-Wellin-primes new file mode 120000 index 0000000000..659326206e --- /dev/null +++ b/Lang/Java/Smarandache-Wellin-primes @@ -0,0 +1 @@ +../../Task/Smarandache-Wellin-primes/Java \ No newline at end of file diff --git a/Lang/Java/Square-form-factorization b/Lang/Java/Square-form-factorization new file mode 120000 index 0000000000..408d94598d --- /dev/null +++ b/Lang/Java/Square-form-factorization @@ -0,0 +1 @@ +../../Task/Square-form-factorization/Java \ No newline at end of file diff --git a/Lang/Java/Terminal-control-Coloured-text b/Lang/Java/Terminal-control-Coloured-text new file mode 120000 index 0000000000..9fa9b33c2b --- /dev/null +++ b/Lang/Java/Terminal-control-Coloured-text @@ -0,0 +1 @@ +../../Task/Terminal-control-Coloured-text/Java \ No newline at end of file diff --git a/Lang/Java/The-sieve-of-Sundaram b/Lang/Java/The-sieve-of-Sundaram new file mode 120000 index 0000000000..b01906820f --- /dev/null +++ b/Lang/Java/The-sieve-of-Sundaram @@ -0,0 +1 @@ +../../Task/The-sieve-of-Sundaram/Java \ No newline at end of file diff --git a/Lang/Joy/Nth b/Lang/Joy/Nth new file mode 120000 index 0000000000..a54053725b --- /dev/null +++ b/Lang/Joy/Nth @@ -0,0 +1 @@ +../../Task/Nth/Joy \ No newline at end of file diff --git a/Lang/Joy/Pick-random-element b/Lang/Joy/Pick-random-element new file mode 120000 index 0000000000..9d96f6a8fb --- /dev/null +++ b/Lang/Joy/Pick-random-element @@ -0,0 +1 @@ +../../Task/Pick-random-element/Joy \ No newline at end of file diff --git a/Lang/Joy/Terminal-control-Ringing-the-terminal-bell b/Lang/Joy/Terminal-control-Ringing-the-terminal-bell new file mode 120000 index 0000000000..80b22226ee --- /dev/null +++ b/Lang/Joy/Terminal-control-Ringing-the-terminal-bell @@ -0,0 +1 @@ +../../Task/Terminal-control-Ringing-the-terminal-bell/Joy \ No newline at end of file diff --git a/Lang/Julia/Steffensens-method b/Lang/Julia/Steffensens-method new file mode 120000 index 0000000000..d8ed6f03dc --- /dev/null +++ b/Lang/Julia/Steffensens-method @@ -0,0 +1 @@ +../../Task/Steffensens-method/Julia \ No newline at end of file diff --git a/Lang/Lua/Arithmetic-derivative b/Lang/Lua/Arithmetic-derivative new file mode 120000 index 0000000000..0eab9f5cd3 --- /dev/null +++ b/Lang/Lua/Arithmetic-derivative @@ -0,0 +1 @@ +../../Task/Arithmetic-derivative/Lua \ No newline at end of file diff --git a/Lang/Lua/Deceptive-numbers b/Lang/Lua/Deceptive-numbers new file mode 120000 index 0000000000..58f4a997e9 --- /dev/null +++ b/Lang/Lua/Deceptive-numbers @@ -0,0 +1 @@ +../../Task/Deceptive-numbers/Lua \ No newline at end of file diff --git a/Lang/Lua/Rare-numbers b/Lang/Lua/Rare-numbers new file mode 120000 index 0000000000..4fe9510e25 --- /dev/null +++ b/Lang/Lua/Rare-numbers @@ -0,0 +1 @@ +../../Task/Rare-numbers/Lua \ No newline at end of file diff --git a/Lang/Maxima/Euclid-Mullin-sequence b/Lang/Maxima/Euclid-Mullin-sequence new file mode 120000 index 0000000000..47c5b80fa4 --- /dev/null +++ b/Lang/Maxima/Euclid-Mullin-sequence @@ -0,0 +1 @@ +../../Task/Euclid-Mullin-sequence/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Eulers-constant-0.5772... b/Lang/Maxima/Eulers-constant-0.5772... new file mode 120000 index 0000000000..30dc5ef80b --- /dev/null +++ b/Lang/Maxima/Eulers-constant-0.5772... @@ -0,0 +1 @@ +../../Task/Eulers-constant-0.5772.../Maxima \ No newline at end of file diff --git a/Lang/Maxima/Eulers-identity b/Lang/Maxima/Eulers-identity new file mode 120000 index 0000000000..ee6f8d0b85 --- /dev/null +++ b/Lang/Maxima/Eulers-identity @@ -0,0 +1 @@ +../../Task/Eulers-identity/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Factorial-primes b/Lang/Maxima/Factorial-primes new file mode 120000 index 0000000000..1ea7000aac --- /dev/null +++ b/Lang/Maxima/Factorial-primes @@ -0,0 +1 @@ +../../Task/Factorial-primes/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Floyds-triangle b/Lang/Maxima/Floyds-triangle new file mode 120000 index 0000000000..e1ca8acce8 --- /dev/null +++ b/Lang/Maxima/Floyds-triangle @@ -0,0 +1 @@ +../../Task/Floyds-triangle/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Formatted-numeric-output b/Lang/Maxima/Formatted-numeric-output new file mode 120000 index 0000000000..04ee081f74 --- /dev/null +++ b/Lang/Maxima/Formatted-numeric-output @@ -0,0 +1 @@ +../../Task/Formatted-numeric-output/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Harmonic-series b/Lang/Maxima/Harmonic-series new file mode 120000 index 0000000000..36c83bb1f7 --- /dev/null +++ b/Lang/Maxima/Harmonic-series @@ -0,0 +1 @@ +../../Task/Harmonic-series/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Harshad-or-Niven-series b/Lang/Maxima/Harshad-or-Niven-series new file mode 120000 index 0000000000..6d05a03e1c --- /dev/null +++ b/Lang/Maxima/Harshad-or-Niven-series @@ -0,0 +1 @@ +../../Task/Harshad-or-Niven-series/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Idiomatically-determine-all-the-lowercase-and-uppercase-letters b/Lang/Maxima/Idiomatically-determine-all-the-lowercase-and-uppercase-letters new file mode 120000 index 0000000000..99b91297a5 --- /dev/null +++ b/Lang/Maxima/Idiomatically-determine-all-the-lowercase-and-uppercase-letters @@ -0,0 +1 @@ +../../Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Jacobsthal-numbers b/Lang/Maxima/Jacobsthal-numbers new file mode 120000 index 0000000000..030995d38b --- /dev/null +++ b/Lang/Maxima/Jacobsthal-numbers @@ -0,0 +1 @@ +../../Task/Jacobsthal-numbers/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Lah-numbers b/Lang/Maxima/Lah-numbers new file mode 120000 index 0000000000..fb3435cadf --- /dev/null +++ b/Lang/Maxima/Lah-numbers @@ -0,0 +1 @@ +../../Task/Lah-numbers/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Largest-proper-divisor-of-n b/Lang/Maxima/Largest-proper-divisor-of-n new file mode 120000 index 0000000000..b571f8ac17 --- /dev/null +++ b/Lang/Maxima/Largest-proper-divisor-of-n @@ -0,0 +1 @@ +../../Task/Largest-proper-divisor-of-n/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Left-factorials b/Lang/Maxima/Left-factorials new file mode 120000 index 0000000000..479727b8f6 --- /dev/null +++ b/Lang/Maxima/Left-factorials @@ -0,0 +1 @@ +../../Task/Left-factorials/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Long-primes b/Lang/Maxima/Long-primes new file mode 120000 index 0000000000..f0ba3d8a24 --- /dev/null +++ b/Lang/Maxima/Long-primes @@ -0,0 +1 @@ +../../Task/Long-primes/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Magic-8-ball b/Lang/Maxima/Magic-8-ball new file mode 120000 index 0000000000..834c78f4fb --- /dev/null +++ b/Lang/Maxima/Magic-8-ball @@ -0,0 +1 @@ +../../Task/Magic-8-ball/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Meissel-Mertens-constant b/Lang/Maxima/Meissel-Mertens-constant new file mode 120000 index 0000000000..ea7cea2fda --- /dev/null +++ b/Lang/Maxima/Meissel-Mertens-constant @@ -0,0 +1 @@ +../../Task/Meissel-Mertens-constant/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Modular-inverse b/Lang/Maxima/Modular-inverse new file mode 120000 index 0000000000..90ae513cd9 --- /dev/null +++ b/Lang/Maxima/Modular-inverse @@ -0,0 +1 @@ +../../Task/Modular-inverse/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors b/Lang/Maxima/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors new file mode 120000 index 0000000000..658f75cafb --- /dev/null +++ b/Lang/Maxima/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors @@ -0,0 +1 @@ +../../Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors b/Lang/Maxima/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors new file mode 120000 index 0000000000..3fd28ddd85 --- /dev/null +++ b/Lang/Maxima/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors @@ -0,0 +1 @@ +../../Task/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors/Maxima \ No newline at end of file diff --git a/Lang/Maxima/Sylvesters-sequence b/Lang/Maxima/Sylvesters-sequence new file mode 120000 index 0000000000..8249630434 --- /dev/null +++ b/Lang/Maxima/Sylvesters-sequence @@ -0,0 +1 @@ +../../Task/Sylvesters-sequence/Maxima \ No newline at end of file diff --git a/Lang/MiniScript/Arithmetic-derivative b/Lang/MiniScript/Arithmetic-derivative new file mode 120000 index 0000000000..d8a1ddf66f --- /dev/null +++ b/Lang/MiniScript/Arithmetic-derivative @@ -0,0 +1 @@ +../../Task/Arithmetic-derivative/MiniScript \ No newline at end of file diff --git a/Lang/OCaml/Terminal-control-Ringing-the-terminal-bell b/Lang/OCaml/Terminal-control-Ringing-the-terminal-bell new file mode 120000 index 0000000000..27e4959ff7 --- /dev/null +++ b/Lang/OCaml/Terminal-control-Ringing-the-terminal-bell @@ -0,0 +1 @@ +../../Task/Terminal-control-Ringing-the-terminal-bell/OCaml \ No newline at end of file diff --git a/Lang/Odin/Curzon-numbers b/Lang/Odin/Curzon-numbers new file mode 120000 index 0000000000..d3b5bcedb0 --- /dev/null +++ b/Lang/Odin/Curzon-numbers @@ -0,0 +1 @@ +../../Task/Curzon-numbers/Odin \ No newline at end of file diff --git a/Lang/Odin/Eban-numbers b/Lang/Odin/Eban-numbers new file mode 120000 index 0000000000..d9dbd4f58a --- /dev/null +++ b/Lang/Odin/Eban-numbers @@ -0,0 +1 @@ +../../Task/Eban-numbers/Odin \ No newline at end of file diff --git a/Lang/Odin/Perfect-numbers b/Lang/Odin/Perfect-numbers new file mode 120000 index 0000000000..b4da5392c4 --- /dev/null +++ b/Lang/Odin/Perfect-numbers @@ -0,0 +1 @@ +../../Task/Perfect-numbers/Odin \ No newline at end of file diff --git a/Lang/PostScript/00-LANG.txt b/Lang/PostScript/00-LANG.txt index 14f4460eb4..32cddabaf0 100644 --- a/Lang/PostScript/00-LANG.txt +++ b/Lang/PostScript/00-LANG.txt @@ -3,9 +3,9 @@ '''PostScript''' originated as a printer definition language invented by the founders of '''Adobe'''. The language was necessitated by the increasing demands of printing and rendering jobs on the computers of the 1970s. These tasks were therefore pushed to the printers themselves, with the result that printers now had chips and built in interpreters for PostScript. With the growth of printing complexity, some printers ended up having even more powerful processors than the master systems themselves. -Although now almost displaced by the '''Portable Document Format''' (PDF), also developed by Adobe, PostScript's USP lies in it's being a '''Turing complete''' language with support for the basic data types and fundamental structures and concepts of Computer Science. Many interpreters and viewers of PostScript are available, some even for free. Although primarily a language suited for 2D graphics, PostScript is complete as a language and able to handle normal computation tasks. +Although now almost displaced by the '''Portable Document Format''' (PDF), also developed by Adobe, PostScript's unique selling proposition lies in it's being a '''Turing complete''' language with support for the basic data types and fundamental structures and concepts of Computer Science. Many interpreters and viewers of PostScript are available, some even for free. Although primarily a language suited for 2D graphics, PostScript is complete as a language and able to handle normal computation tasks. -''(does "USP" mean "unique selling proposition"?)'' + ==See Also== *[http://logand.com/sw/wps/index.html WPS - PostScript interpreter written in JavaScript.] diff --git a/Lang/Quackery/00-LANG.txt b/Lang/Quackery/00-LANG.txt index ca017e1b3c..498188387d 100644 --- a/Lang/Quackery/00-LANG.txt +++ b/Lang/Quackery/00-LANG.txt @@ -31,5 +31,4 @@ Quackery is not intended to be a super-fast enterprise-level language; it is int If your language supports bignums, first-class functions and dynamic arrays of bignums, functions and dynamic arrays, and has automatic garbage collection, and if you can code depth-first traversal of a tree you can implement Quackery in your preferred language with reasonable ease, and modify it as you please. -Or try your hand at one of the [https://rosettacode.org/wiki/Tasks_not_implemented_in_Quackery Tasks not implemented in Quackery] -. \ No newline at end of file +Or try your hand at one of the [[Tasks not implemented in Quackery]]. \ No newline at end of file diff --git a/Lang/Quackery/AKS-test-for-primes b/Lang/Quackery/AKS-test-for-primes new file mode 120000 index 0000000000..10ff400134 --- /dev/null +++ b/Lang/Quackery/AKS-test-for-primes @@ -0,0 +1 @@ +../../Task/AKS-test-for-primes/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Blum-integer b/Lang/Quackery/Blum-integer new file mode 120000 index 0000000000..83910cd0bd --- /dev/null +++ b/Lang/Quackery/Blum-integer @@ -0,0 +1 @@ +../../Task/Blum-integer/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Brazilian-numbers b/Lang/Quackery/Brazilian-numbers new file mode 120000 index 0000000000..56937f6f88 --- /dev/null +++ b/Lang/Quackery/Brazilian-numbers @@ -0,0 +1 @@ +../../Task/Brazilian-numbers/Quackery \ No newline at end of file diff --git a/Lang/Quackery/First-class-functions b/Lang/Quackery/First-class-functions new file mode 120000 index 0000000000..ab6788c0dd --- /dev/null +++ b/Lang/Quackery/First-class-functions @@ -0,0 +1 @@ +../../Task/First-class-functions/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Formatted-numeric-output b/Lang/Quackery/Formatted-numeric-output new file mode 120000 index 0000000000..c28b31f883 --- /dev/null +++ b/Lang/Quackery/Formatted-numeric-output @@ -0,0 +1 @@ +../../Task/Formatted-numeric-output/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Literals-Floating-point b/Lang/Quackery/Literals-Floating-point new file mode 120000 index 0000000000..3155035075 --- /dev/null +++ b/Lang/Quackery/Literals-Floating-point @@ -0,0 +1 @@ +../../Task/Literals-Floating-point/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Loops-Increment-loop-index-within-loop-body b/Lang/Quackery/Loops-Increment-loop-index-within-loop-body new file mode 120000 index 0000000000..8c7ede6356 --- /dev/null +++ b/Lang/Quackery/Loops-Increment-loop-index-within-loop-body @@ -0,0 +1 @@ +../../Task/Loops-Increment-loop-index-within-loop-body/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Miller-Rabin-primality-test b/Lang/Quackery/Miller-Rabin-primality-test new file mode 120000 index 0000000000..d8e4ec56b5 --- /dev/null +++ b/Lang/Quackery/Miller-Rabin-primality-test @@ -0,0 +1 @@ +../../Task/Miller-Rabin-primality-test/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Multi-dimensional-array b/Lang/Quackery/Multi-dimensional-array new file mode 120000 index 0000000000..f931c88196 --- /dev/null +++ b/Lang/Quackery/Multi-dimensional-array @@ -0,0 +1 @@ +../../Task/Multi-dimensional-array/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Own-digits-power-sum b/Lang/Quackery/Own-digits-power-sum new file mode 120000 index 0000000000..7adeb6319c --- /dev/null +++ b/Lang/Quackery/Own-digits-power-sum @@ -0,0 +1 @@ +../../Task/Own-digits-power-sum/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Repunit-primes b/Lang/Quackery/Repunit-primes new file mode 120000 index 0000000000..cade03efff --- /dev/null +++ b/Lang/Quackery/Repunit-primes @@ -0,0 +1 @@ +../../Task/Repunit-primes/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Summarize-primes b/Lang/Quackery/Summarize-primes new file mode 120000 index 0000000000..4db7909d7e --- /dev/null +++ b/Lang/Quackery/Summarize-primes @@ -0,0 +1 @@ +../../Task/Summarize-primes/Quackery \ No newline at end of file diff --git a/Lang/Quackery/Time-a-function b/Lang/Quackery/Time-a-function new file mode 120000 index 0000000000..1e18e5e5d0 --- /dev/null +++ b/Lang/Quackery/Time-a-function @@ -0,0 +1 @@ +../../Task/Time-a-function/Quackery \ No newline at end of file diff --git a/Lang/Raku/Steffensens-method b/Lang/Raku/Steffensens-method new file mode 120000 index 0000000000..22b61824b8 --- /dev/null +++ b/Lang/Raku/Steffensens-method @@ -0,0 +1 @@ +../../Task/Steffensens-method/Raku \ No newline at end of file diff --git a/Lang/Ruby/Home-primes b/Lang/Ruby/Home-primes new file mode 120000 index 0000000000..385bbc4d71 --- /dev/null +++ b/Lang/Ruby/Home-primes @@ -0,0 +1 @@ +../../Task/Home-primes/Ruby \ No newline at end of file diff --git a/Lang/Standard-ML/Monty-Hall-problem b/Lang/Standard-ML/Monty-Hall-problem new file mode 120000 index 0000000000..1ee10bd6fe --- /dev/null +++ b/Lang/Standard-ML/Monty-Hall-problem @@ -0,0 +1 @@ +../../Task/Monty-Hall-problem/Standard-ML \ No newline at end of file diff --git a/Lang/UNIX-Shell/Deceptive-numbers b/Lang/UNIX-Shell/Deceptive-numbers new file mode 120000 index 0000000000..a319427794 --- /dev/null +++ b/Lang/UNIX-Shell/Deceptive-numbers @@ -0,0 +1 @@ +../../Task/Deceptive-numbers/UNIX-Shell \ No newline at end of file diff --git a/Lang/Zig/Combinations-and-permutations b/Lang/Zig/Combinations-and-permutations new file mode 120000 index 0000000000..7f82e63dd0 --- /dev/null +++ b/Lang/Zig/Combinations-and-permutations @@ -0,0 +1 @@ +../../Task/Combinations-and-permutations/Zig \ No newline at end of file diff --git a/Lang/Zig/Function-definition b/Lang/Zig/Function-definition new file mode 120000 index 0000000000..99ae877f50 --- /dev/null +++ b/Lang/Zig/Function-definition @@ -0,0 +1 @@ +../../Task/Function-definition/Zig \ No newline at end of file diff --git a/Lang/Zig/Loops-Increment-loop-index-within-loop-body b/Lang/Zig/Loops-Increment-loop-index-within-loop-body new file mode 120000 index 0000000000..2c26d90cda --- /dev/null +++ b/Lang/Zig/Loops-Increment-loop-index-within-loop-body @@ -0,0 +1 @@ +../../Task/Loops-Increment-loop-index-within-loop-body/Zig \ No newline at end of file diff --git a/Lang/Zig/Sorting-algorithms-Quicksort b/Lang/Zig/Sorting-algorithms-Quicksort new file mode 120000 index 0000000000..c50423b087 --- /dev/null +++ b/Lang/Zig/Sorting-algorithms-Quicksort @@ -0,0 +1 @@ +../../Task/Sorting-algorithms-Quicksort/Zig \ No newline at end of file diff --git a/Task/100-doors/Informix-4GL/100-doors.4gl b/Task/100-doors/Informix-4GL/100-doors-1.4gl similarity index 100% rename from Task/100-doors/Informix-4GL/100-doors.4gl rename to Task/100-doors/Informix-4GL/100-doors-1.4gl diff --git a/Task/100-doors/Informix-4GL/100-doors-2.4gl b/Task/100-doors/Informix-4GL/100-doors-2.4gl new file mode 100644 index 0000000000..77483d70d0 --- /dev/null +++ b/Task/100-doors/Informix-4GL/100-doors-2.4gl @@ -0,0 +1,12 @@ +(var doors (times 100 false)) + +(for i (range 1 101) + i2 (range (dec i) 100 i) + (var! doors (set-at [i2] (! (i2 doors)))) + (continue)) + +(-> (xmap vec doors) + (filter 1) + (map (comp 0 inc)) + (join ", ") + @(str "open doors: ")) diff --git a/Task/4-rings-or-4-squares-puzzle/EasyLang/4-rings-or-4-squares-puzzle.easy b/Task/4-rings-or-4-squares-puzzle/EasyLang/4-rings-or-4-squares-puzzle.easy new file mode 100644 index 0000000000..f2e05dc87f --- /dev/null +++ b/Task/4-rings-or-4-squares-puzzle/EasyLang/4-rings-or-4-squares-puzzle.easy @@ -0,0 +1,56 @@ +func ok v t[] . + for h in t[] + if v = h + return 0 + . + . + return 1 +. +proc four lo hi uni show . . + # + subr bf + for f = lo to hi + if uni = 0 or ok f [ a c d g e ] = 1 + b = e + f - c + if b >= lo and b <= hi and (uni = 0 or ok b [ a c d g e f ] = 1) + solutions += 1 + if show = 1 + for h in [ a b c d e f g ] + write h & " " + . + print "" + . + . + . + . + . + subr ge + for e = lo to hi + if uni = 0 or ok e [ a c d ] = 1 + g = d + e + if g >= lo and g <= hi and (uni = 0 or ok g [ a c d e ] = 1) + bf + . + . + . + . + subr acd + for c = lo to hi + for d = lo to hi + if uni = 0 or c <> d + a = c + d + if a >= lo and a <= hi and (uni = 0 or c <> 0 and d <> 0) + ge + . + . + . + . + . + print "low:" & lo & " hi:" & hi & " unique:" & uni + acd + print solutions & " solutions" + print "" +. +four 1 7 1 1 +four 3 9 1 1 +four 0 9 0 0 diff --git a/Task/ABC-problem/EasyLang/abc-problem.easy b/Task/ABC-problem/EasyLang/abc-problem.easy new file mode 100644 index 0000000000..4f51ed99d3 --- /dev/null +++ b/Task/ABC-problem/EasyLang/abc-problem.easy @@ -0,0 +1,23 @@ +b$[][] = [ [ "B" "O" ] [ "X" "K" ] [ "D" "Q" ] [ "C" "P" ] [ "N" "A" ] [ "G" "T" ] [ "R" "E" ] [ "T" "G" ] [ "Q" "D" ] [ "F" "S" ] [ "J" "W" ] [ "H" "U" ] [ "V" "I" ] [ "A" "N" ] [ "O" "B" ] [ "E" "R" ] [ "F" "S" ] [ "L" "Y" ] [ "P" "C" ] [ "Z" "M" ] ] +len b[] len b$[][] +global w$[] cnt . +# +proc backtr wi . . + if wi > len w$[] + cnt += 1 + return + . + for i = 1 to len b$[][] + if b[i] = 0 and (b$[i][1] = w$[wi] or b$[i][2] = w$[wi]) + b[i] = 1 + backtr wi + 1 + b[i] = 0 + . + . +. +for s$ in [ "A" "BARK" "BOOK" "TREAT" "COMMON" "SQUAD" "CONFUSE" ] + w$[] = strchars s$ + cnt = 0 + backtr 1 + print s$ & " can be spelled in " & cnt & " ways" +. diff --git a/Task/ABC-problem/Insitux/abc-problem.insitux b/Task/ABC-problem/Insitux/abc-problem.insitux index d0c393dfba..aba0f2cc01 100644 --- a/Task/ABC-problem/Insitux/abc-problem.insitux +++ b/Task/ABC-problem/Insitux/abc-problem.insitux @@ -1,8 +1,11 @@ -(var find-idx #(when (let found (find % %1)) (idx %1 found))) -(function in-block? c (when (let block-idx (find-idx (substr? (upper-case c)) rem-blocks)) (var! rem-blocks drop block-idx))) +(function in-block? c + (when (let block-idx (find-idx (substr? (upper-case c)) rem-blocks)) + (var! rem-blocks drop block-idx))) (function can-make-word word (var rem-blocks ["BO" "XK" "DQ" "CP" "NA" "GT" "RE" "TG" "QD" "FS" "JW" "HU" "VI" "AN" "OB" "ER" "FS" "LY" "PC" "ZM"]) (.. and (map in-block? word))) -(join ", " (map #(str % " => " (can-make-word %)) ["A" "bark" "Book" "TREAT" "Common" "squaD" "CoNFuSe"])) ; Notice case insensitivity +(-> ["A" "bark" "Book" "TREAT" "Common" "squaD" "CoNFuSe"] ; Notice case insensitivity + (map #(str % " => " (can-make-word %))) + (join ", ")) diff --git a/Task/AKS-test-for-primes/Quackery/aks-test-for-primes.quackery b/Task/AKS-test-for-primes/Quackery/aks-test-for-primes.quackery new file mode 100644 index 0000000000..4e57c399b7 --- /dev/null +++ b/Task/AKS-test-for-primes/Quackery/aks-test-for-primes.quackery @@ -0,0 +1,66 @@ + [ dup 0 peek swap + [] 0 rot 0 join + witheach + [ abs tuck + + rot join swap ] + drop + [] swap witheach + [ rot negate + dup dip unrot + * join ] + nip ] is nextcoeffs ( [ --> [ ) + + [ ' [ 1 ] swap + times nextcoeffs ] is coeffs ( n --> [ ) + + [ dup 2 < iff + [ drop false ] + done + true swap + dup coeffs + behead drop + -1 split drop + witheach + [ over mod + 0 != if + [ dip not + conclude ] ] + drop ] is prime ( n --> b ) + + [ behead + 0 < iff + [ say "-" ] + else sp + dup size + dup 0 = iff + [ 1 echo 2drop ] + done + say "x" + dup 1 = iff + [ 2drop + say " + 1" ] + done + say "^" + echo + witheach + [ dup 0 < iff + [ say " - " ] + else + [ say " + " ] + abs echo + i 0 = if done + say "x" + i 1 = if done + say "^" + i echo ] ] is echocoeffs ( [ --> ) + + 8 times + [ i^ echo + say ": " + i^ coeffs + echocoeffs + cr ] + cr + 50 times + [ i^ prime if + [ i^ echo sp ] ] diff --git a/Task/Abelian-sandpile-model/ALGOL-68/abelian-sandpile-model.alg b/Task/Abelian-sandpile-model/ALGOL-68/abelian-sandpile-model.alg new file mode 100644 index 0000000000..c04c801c1a --- /dev/null +++ b/Task/Abelian-sandpile-model/ALGOL-68/abelian-sandpile-model.alg @@ -0,0 +1,92 @@ +BEGIN # model Abelian sandpiles # + # returns TRUE if the sandpile s is stable, FALSE otherwise # + OP STABLE = ( [,]INT s )BOOL: + BEGIN + BOOL result := TRUE; + FOR i FROM 1 LWB s TO 1 UPB s WHILE result DO + FOR j FROM 2 LWB s TO 2 UPB s WHILE result := s[ i, j ] < 4 DO SKIP OD + OD; + result + END # STABLE # ; + # returns the sandpile s after avalanches # + OP AVALANCHE = ( [,]INT s )[,]INT: + BEGIN + [ 1 : 1 UPB s, 1 : 2 UPB s ]INT result := s[ AT 1, AT 1 ]; + WHILE BOOL had avalanche := FALSE; + FOR i TO 1 UPB s DO + FOR j TO 2 UPB s DO + IF result[ i, j ] >= 4 THEN + # unstable pile # + had avalanche := TRUE; + result[ i, j ] -:= 4; + IF i > 1 THEN result[ i - 1, j ] +:= 1 FI; + IF i < 1 UPB s THEN result[ i + 1, j ] +:= 1 FI; + IF j > 1 THEN result[ i, j - 1 ] +:= 1 FI; + IF j < 2 UPB s THEN result[ i, j + 1 ] +:= 1 FI + FI + OD + OD; + had avalanche + DO SKIP OD; + result + END # AVALANCHE # ; + # returns the maximum element of s # + OP MAX = ( [,]INT s )INT: + BEGIN + INT result := s[ 1 LWB s, 2 LWB s ]; + FOR i FROM 1 LWB s TO 2 UPB s DO + FOR j FROM 2 LWB s TO 2 UPB s DO + IF s[ i, j ] > result THEN result := s[ i, j ] FI + OD + OD; + result + END # MAX # ; + # prints the sandpile s # + PROC show sandpile = ( STRING title, [,]INT s )VOID: + BEGIN + print( ( title, newline ) ); + IF 1 UPB s >= 1 LWB s AND 2 UPB s >= 2 LWB s THEN + # non-empty sandpile # + INT width := 1; # find tthe width needed for each element # + INT v := MAX s; + WHILE v > 9 DO + v OVERAB 10; + width +:= 1 + OD; + FOR i TO 1 UPB s DO + FOR j TO 2 UPB s DO + print( ( " ", whole( s[ i, j ], - width ) ) ) + OD; + print( ( newline ) ) + OD + FI + END # show sandpile # ; + # printys a sandpile before and after the avalanches # + PROC show sandpile before and after = ( [,]INT s )VOID: + BEGIN + [ 1 LWB s : 1 UPB s, 2 LWB s : 2 UPB s ]INT t := s; + show sandpile( "before: ", t ); + WHILE NOT STABLE t DO + t := AVALANCHE t + OD; + show sandpile( "after: ", t ); + print( ( newline ) ) + END # show sandpile before and after # ; + # task test case # + [,]INT s1 = ( ( 0, 0, 0, 0, 0 ) + , ( 0, 0, 0, 0, 0 ) + , ( 0, 0, 16, 0, 0 ) + , ( 0, 0, 0, 0, 0 ) + , ( 0, 0, 0, 0, 0 ) + ); + show sandpile before and after( s1 ); + # test case from 11l, C, etc. # + [ 1 : 10, 1 : 10 ]INT s2; + FOR i FROM 1 LWB s2 TO 1 UPB s2 DO + FOR j FROM 2 LWB s2 TO 2 UPB s2 DO + s2[ i, j ] := 0 + OD + OD; + s2[ 6, 6 ] := 64; + show sandpile before and after( s2 ) +END diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/EasyLang/abundant-deficient-and-perfect-number-classifications.easy b/Task/Abundant-deficient-and-perfect-number-classifications/EasyLang/abundant-deficient-and-perfect-number-classifications.easy new file mode 100644 index 0000000000..bdb5bc710b --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/EasyLang/abundant-deficient-and-perfect-number-classifications.easy @@ -0,0 +1,31 @@ +func sumprop num . + if num < 2 + return 0 + . + i = 2 + sum = 1 + root = sqrt num + while i < root + if num mod i = 0 + sum += i + num / i + . + i += 1 + . + if num mod root = 0 + sum += root + . + return sum +. +for j = 1 to 20000 + sump = sumprop j + if sump < j + deficient += 1 + elif sump = j + perfect += 1 + else + abundant += 1 + . +. +print "Perfect: " & perfect +print "Abundant: " & abundant +print "Deficient: " & deficient diff --git a/Task/Abundant-odd-numbers/EasyLang/abundant-odd-numbers.easy b/Task/Abundant-odd-numbers/EasyLang/abundant-odd-numbers.easy new file mode 100644 index 0000000000..5cfb14b7e7 --- /dev/null +++ b/Task/Abundant-odd-numbers/EasyLang/abundant-odd-numbers.easy @@ -0,0 +1,35 @@ +fastfunc sumdivs n . + sum = 1 + i = 3 + while i <= sqrt n + if n mod i = 0 + sum += i + j = n / i + if i <> j + sum += j + . + . + i += 2 + . + return sum +. +n = 1 +numfmt 0 6 +while cnt < 1000 + sum = sumdivs n + if sum > n + cnt += 1 + if cnt <= 25 or cnt = 1000 + print cnt & " n: " & n & " sum: " & sum + . + . + n += 2 +. +print "" +n = 1000000001 +repeat + sum = sumdivs n + until sum > n + n += 2 +. +print "1st > 1B: " & n & " sum: " & sum diff --git a/Task/Accumulator-factory/Bracmat/accumulator-factory.bracmat b/Task/Accumulator-factory/Bracmat/accumulator-factory-1.bracmat similarity index 100% rename from Task/Accumulator-factory/Bracmat/accumulator-factory.bracmat rename to Task/Accumulator-factory/Bracmat/accumulator-factory-1.bracmat diff --git a/Task/Accumulator-factory/Bracmat/accumulator-factory-2.bracmat b/Task/Accumulator-factory/Bracmat/accumulator-factory-2.bracmat new file mode 100644 index 0000000000..73faf46bdb --- /dev/null +++ b/Task/Accumulator-factory/Bracmat/accumulator-factory-2.bracmat @@ -0,0 +1,36 @@ +( ( accumulator + = + . + ' ( add sum object addFunction + . ( addFunction + = A B + . !arg:(?A.?B) + & ( !A:# + & !B:# + & "If both values are recognized as integer or fractional values, just use '+'." + & !A+!B + | "Otherwise, create an object for adding two C doubles and let that run." + & ( new + $ (UFP,'(.$($A)+$($B))) + . go + ) + $ + ) + ) + & ( object + = add + = addFunction$($arg.!arg) + ) + & !(object.add):?sum + & 'addFunction$($($sum).!arg) + : (=?(object.add)) + & !sum + ) + ) +& accumulator$1:(=?x) +& x$5 +& accumulator$1:(=?y) +& y$"5.0" +& out$(x$23/10) +& out$(y$"2.3") +) diff --git a/Task/Align-columns/EasyLang/align-columns.easy b/Task/Align-columns/EasyLang/align-columns.easy new file mode 100644 index 0000000000..e3acfc12a5 --- /dev/null +++ b/Task/Align-columns/EasyLang/align-columns.easy @@ -0,0 +1,55 @@ +global width inp$[] . +proc read . . + repeat + inp$ = input + until inp$ = "" + inp$[] &= inp$ + ar$[] = strsplit inp$ "$" + for s$ in ar$[] + width = higher width len s$ + . + . +. +call read +# +proc out mode . . + for inp$ in inp$[] + ar$[] = strsplit inp$ "$" + for s$ in ar$[] + spc = width - len s$ + 1 + if mode = 1 + write s$ + for i to spc + write " " + . + elif mode = 2 + for i to spc + write " " + . + write s$ + elif mode = 3 + for i to spc div 2 + write " " + . + write s$ + for i to spc - spc div 2 + write " " + . + . + . + print "" + . +. +call out 1 +print "" +call out 2 +print "" +call out 3 +# +input_data +Given$a$text$file$of$many$lines,$where$fields$within$a$line$ +are$delineated$by$a$single$'dollar'$character,$write$a$program +that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$ +column$are$separated$by$at$least$one$space. +Further,$allow$for$each$word$in$a$column$to$be$either$left$ +justified,$right$justified,$or$center$justified$within$its$column. diff --git a/Task/Aliquot-sequence-classifications/EasyLang/aliquot-sequence-classifications.easy b/Task/Aliquot-sequence-classifications/EasyLang/aliquot-sequence-classifications.easy new file mode 100644 index 0000000000..e25f92c48c --- /dev/null +++ b/Task/Aliquot-sequence-classifications/EasyLang/aliquot-sequence-classifications.easy @@ -0,0 +1,75 @@ +fastfunc sumprop num . + if num = 1 + return 0 + . + sum = 1 + root = sqrt num + i = 2 + while i < root + if num mod i = 0 + sum += i + num / i + . + i += 1 + . + if num mod root = 0 + sum += root + . + return sum +. +func$ tostr ar[] . + for v in ar[] + s$ &= " " & v + . + return s$ +. +func$ class k . + oldk = k + newk = sumprop oldk + oldk = newk + seq[] &= newk + if newk = 0 + return "terminating " & tostr seq[] + . + if newk = k + return "perfect " & tostr seq[] + . + newk = sumprop oldk + oldk = newk + seq[] &= newk + if newk = 0 + return "terminating " & tostr seq[] + . + if newk = k + return "amicable " & tostr seq[] + . + for t = 4 to 16 + newk = sumprop oldk + seq[] &= newk + if newk = 0 + return "terminating " & tostr seq[] + . + if newk = k + return "sociable (period " & t - 1 & ") " & tostr seq[] + . + if newk = oldk + return "aspiring " & tostr seq[] + . + for i to len seq[] - 1 + if newk = seq[i] + return "cyclic (at " & newk & ") " & tostr seq[] + . + . + if newk > 140737488355328 + return "non-terminating (term > 140737488355328) " & tostr seq[] + . + oldk = newk + . + return "non-terminating (after 16 terms) " & tostr seq[] +. +print "Number classification sequence" +for j = 1 to 12 + print j & " " & class j +. +for j in [ 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080 ] + print j & " " & class j +. diff --git a/Task/Almost-prime/EasyLang/almost-prime.easy b/Task/Almost-prime/EasyLang/almost-prime.easy new file mode 100644 index 0000000000..67e268e1f0 --- /dev/null +++ b/Task/Almost-prime/EasyLang/almost-prime.easy @@ -0,0 +1,30 @@ +func kprime n k . + i = 2 + while i <= n + while n mod i = 0 + if f = k + return 0 + . + f += 1 + n /= i + . + i += 1 + . + if f = k + return 1 + . + return 0 +. +for k = 1 to 5 + write "k=" & k & " : " + i = 2 + c = 0 + while c < 10 + if kprime i k = 1 + write i & " " + c += 1 + . + i += 1 + . + print "" +. diff --git a/Task/Amicable-pairs/Elena/amicable-pairs-3.elena b/Task/Amicable-pairs/Elena/amicable-pairs-3.elena index 9fa2bbb5e9..d2de787c53 100644 --- a/Task/Amicable-pairs/Elena/amicable-pairs-3.elena +++ b/Task/Amicable-pairs/Elena/amicable-pairs-3.elena @@ -27,7 +27,7 @@ public sealed AmicablePairs { int sum := divsums[i]; if(i < sum && sum <= divsums.Length && divsums[sum] == i) { - yield:new Tuple(i, sum); + $yield new Tuple(i, sum); } }; diff --git a/Task/Angle-difference-between-two-bearings/EasyLang/angle-difference-between-two-bearings.easy b/Task/Angle-difference-between-two-bearings/EasyLang/angle-difference-between-two-bearings.easy new file mode 100644 index 0000000000..fbe96a9106 --- /dev/null +++ b/Task/Angle-difference-between-two-bearings/EasyLang/angle-difference-between-two-bearings.easy @@ -0,0 +1,24 @@ +func angdiff a b . + r = (b - a) mod 360 + if r < -180 + r += 360 + elif r >= 180 + r -= 360 + . + return r +. +proc pd a b . . + print b & " " & a & " -> " & angdiff a b +. +pd 20 45 +pd -45 45 +pd -85 90 +pd -95 90 +pd -45 125 +pd -45 145 +pd 29.4803 -88.6381 +pd -78.3251 -159.036 +pd -70099.74233810938 29840.67437876723 +pd -165313.6666297357 33693.9894517456 +pd 1174.8380510598456 -154146.66490124757 +pd 60175.77306795546 42213.07192354373 diff --git a/Task/Angles-geometric-normalization-and-conversion/EasyLang/angles-geometric-normalization-and-conversion.easy b/Task/Angles-geometric-normalization-and-conversion/EasyLang/angles-geometric-normalization-and-conversion.easy new file mode 100644 index 0000000000..546d276c89 --- /dev/null +++ b/Task/Angles-geometric-normalization-and-conversion/EasyLang/angles-geometric-normalization-and-conversion.easy @@ -0,0 +1,46 @@ +func angconv ang f$ t$ . + sgn = sign ang + ang = abs ang + if f$ = "degree" + turn = ang / 360 mod 1 + elif f$ = "gradian" + turn = ang / 400 mod 1 + elif f$ = "mil" + turn = ang / 6400 mod 1 + elif f$ = "radian" + turn = ang / (2 * pi) mod 1 + . + if t$ = "degree" + ang = turn * 360 + elif t$ = "gradian" + ang = turn * 400 + elif t$ = "mil" + ang = turn * 6400 + elif t$ = "radian" + ang = turn * 2 * pi + . + return ang * sgn +. +func$ fmt s$ . + return substr " " 1 (9 - len s$) & s$ & " " +. +# +scales$[] = [ "degree" "gradian" "mil" "radian" ] +values[] = [ -2 -1 0 1 2 6.2831853 16 57.2957795 359 399 6399 1000000 ] +numfmt 3 10 +for f$ in scales$[] + write fmt f$ + for t$ in scales$[] + write fmt t$ + . + print "" + print " ------------------------------------------------" + for v in values[] + write v + for t$ in scales$[] + write angconv v f$ t$ + . + print "" + . + print "" +. diff --git a/Task/Anti-primes/EasyLang/anti-primes.easy b/Task/Anti-primes/EasyLang/anti-primes.easy new file mode 100644 index 0000000000..d5099ac863 --- /dev/null +++ b/Task/Anti-primes/EasyLang/anti-primes.easy @@ -0,0 +1,27 @@ +func divcnt v . + n = v + tot = 1 + p = 2 + while p <= sqrt n + cnt = 1 + while n mod p = 0 + cnt += 1 + n = n div p + . + p += 1 + tot *= cnt + . + if n > 1 + tot *= 2 + . + return tot +. +while count < 20 + n += 1 + divs = divcnt n + if divs > max + print n + max = divs + count += 1 + . +. diff --git a/Task/Anti-primes/Grain/anti-primes.grain b/Task/Anti-primes/Grain/anti-primes.grain new file mode 100644 index 0000000000..e6664bbc5c --- /dev/null +++ b/Task/Anti-primes/Grain/anti-primes.grain @@ -0,0 +1,31 @@ +import File from "sys/file" +let mut maxDiv = 0 +let mut count = 0 +let numaprimes = 20 +let countDivisors = n => { + if (n < 1) { + 1 + } else { + let mut count = 2 + let mut target = n / 2 + for (let mut i = 1; i <= target; i += 1) { + if (n % i == 0) { + count += 1 + } else { + void + } + } + count + } +} +print("\nThe first 20 anti-primes are: ") +let mut d = 0 +for (let mut j = 1; count < numaprimes; j += 1) { + d = countDivisors(j) + if (d > maxDiv) { + File.fdWrite(File.stdout, Pervasives.toString(j)) + File.fdWrite(File.stdout, " ") + maxDiv = d + count += 1 + } +} diff --git a/Task/Archimedean-spiral/EasyLang/archimedean-spiral.easy b/Task/Archimedean-spiral/EasyLang/archimedean-spiral.easy index fb16cc5cc2..6f648c90fb 100644 --- a/Task/Archimedean-spiral/EasyLang/archimedean-spiral.easy +++ b/Task/Archimedean-spiral/EasyLang/archimedean-spiral.easy @@ -1,9 +1,8 @@ -linewidth 0.2 +linewidth 0.4 x = 50 y = 50 -move x y while r < 50 line r * cos t + x r * sin t + y - r += 0.1 - t += 6 + r += 0.05 + t += 3 . diff --git a/Task/Arithmetic-derivative/ALGOL-W/arithmetic-derivative.alg b/Task/Arithmetic-derivative/ALGOL-W/arithmetic-derivative.alg new file mode 100644 index 0000000000..5b41206fb6 --- /dev/null +++ b/Task/Arithmetic-derivative/ALGOL-W/arithmetic-derivative.alg @@ -0,0 +1,21 @@ +begin + integer procedure lagarias ( integer value n ) ; % Lagarias arithmetic derivative % + if n < 0 + then -lagarias (-n) + else if n = 0 or n = 1 + then 0 + else begin + integer f, q; + integer procedure smallPf ( integer value j, k ) ; % Smallest prime factor % + if j rem k = 0 then k else smallPf (j, k + 1); + f := smallPf (n, 2); q := n div f; + if q = 1 + then 1 + else q * lagarias (f) + f * lagarias (q) + end lagarias ; + + for n := -99 until 100 do begin + writeon( i_w := 6, s_w := 0, " ", lagarias (n) ); + if n rem 10 = 0 then write() + end for_n +end. diff --git a/Task/Arithmetic-derivative/Lua/arithmetic-derivative.lua b/Task/Arithmetic-derivative/Lua/arithmetic-derivative.lua new file mode 100644 index 0000000000..e5ac19fdd3 --- /dev/null +++ b/Task/Arithmetic-derivative/Lua/arithmetic-derivative.lua @@ -0,0 +1,25 @@ +do local function lagarias (n) -- Lagarias arithmetic derivative + if n < 0 + then return -lagarias (-n) + elseif n == 0 or n == 1 + then return 0 + else local function smallPf (j, k) -- Smallest prime factor + if j % k == 0 then return k else return smallPf (j, k + 1) end + end + local f = smallPf (n, 2) local q = math.floor (n / f) + if q == 1 + then return 1 + else return q * lagarias (f) + f * lagarias (q) + end + end + end + for n = -99,100 + do io.write (string.format("%6d", lagarias (n))) + if n % 10 == 0 then io.write ("\n") end + end + io.write ("\n") + for n = 1,17 -- 18, 19 and 20 would overflow + do local m = 10 ^ n + io.write ("D(", string.format ("%d", m), ") / 7 = ", math.floor (lagarias (m) / 7), "\n") + end +end diff --git a/Task/Arithmetic-derivative/MiniScript/arithmetic-derivative.mini b/Task/Arithmetic-derivative/MiniScript/arithmetic-derivative.mini new file mode 100644 index 0000000000..1c297bd18d --- /dev/null +++ b/Task/Arithmetic-derivative/MiniScript/arithmetic-derivative.mini @@ -0,0 +1,43 @@ +lagarias = function (n) // Lagarias arithmetic derivative + if n < 0 then + return -lagarias (-n) + else if n == 0 or n == 1 then + return 0 + else + smallPf = function (j, k) // Smallest prime factor + if j % k == 0 then + return k + else + return smallPf (j, k + 1) + end if + end function + f = smallPf (n, 2) + q = floor (n / f) + if q == 1 then + return 1 + else + return q * lagarias (f) + f * lagarias (q) + end if + end if +end function +fmt6 = function (n) // return a 6 character string representation of n + s = str( n ) + if s.len > 5 then + return s + else + return ( " " * ( 6 - s.len ) ) + s + end if +end function +ad = "" +for n in range( -99, 100 ) + ad = ad + " " + fmt6( lagarias (n) ) + if n % 10 == 0 then + print( ad ) + ad = "" + end if +end for +print() +for n in range( 1, 17 ) // 18, 19 and 20 would overflow ????? TODO: check + m = 10 ^ n + print( "D(" + str(m) + ") / 7 = " + str( floor (lagarias (m) / 7) ) ) +end for diff --git a/Task/Arithmetic-geometric-mean-Calculate-Pi/EasyLang/arithmetic-geometric-mean-calculate-pi.easy b/Task/Arithmetic-geometric-mean-Calculate-Pi/EasyLang/arithmetic-geometric-mean-calculate-pi.easy new file mode 100644 index 0000000000..0ebe1a31ba --- /dev/null +++ b/Task/Arithmetic-geometric-mean-Calculate-Pi/EasyLang/arithmetic-geometric-mean-calculate-pi.easy @@ -0,0 +1,15 @@ +an = 1 +bn = sqrt 0.5 +tn = 0.25 +pn = 1 +while pn <= 5 + prevAn = an + an = (bn + an) / 2 + bn = sqrt (bn * prevAn) + prevAn -= an + tn -= (pn * prevAn * prevAn) + pn *= 2 +. +mypi = (an + bn) * (an + bn) / (tn * 4) +numfmt 15 0 +print mypi diff --git a/Task/Arithmetic-geometric-mean/EasyLang/arithmetic-geometric-mean.easy b/Task/Arithmetic-geometric-mean/EasyLang/arithmetic-geometric-mean.easy new file mode 100644 index 0000000000..5f7ce66faf --- /dev/null +++ b/Task/Arithmetic-geometric-mean/EasyLang/arithmetic-geometric-mean.easy @@ -0,0 +1,11 @@ +func agm a g . + repeat + a0 = a + a = (a0 + g) / 2 + g = sqrt (a0 * g) + until abs (a0 - a) < abs (a) * 1e-15 + . + return a +. +numfmt 16 0 +print agm 1 sqrt 0.5 diff --git a/Task/Arithmetic-geometric-mean/Raku/arithmetic-geometric-mean-3.raku b/Task/Arithmetic-geometric-mean/Raku/arithmetic-geometric-mean-3.raku new file mode 100644 index 0000000000..ab680a4e4c --- /dev/null +++ b/Task/Arithmetic-geometric-mean/Raku/arithmetic-geometric-mean-3.raku @@ -0,0 +1,6 @@ +sub agm { + ($^z, {(.re+.im)/2 + (.re*.im).sqrt*1i} ... * ≅ *) + .tail.re +} + +say agm 1 + 1i/2.sqrt diff --git a/Task/Arithmetic-numbers/Draco/arithmetic-numbers.draco b/Task/Arithmetic-numbers/Draco/arithmetic-numbers.draco new file mode 100644 index 0000000000..8b296bf618 --- /dev/null +++ b/Task/Arithmetic-numbers/Draco/arithmetic-numbers.draco @@ -0,0 +1,48 @@ +word MAX = 13000; + +[MAX+1]word divisorSum; +[MAX+1]byte divisorCount; + +proc calculateDivisorSums() void: + word num, div; + for div from 1 by 1 upto MAX do + for num from div by div upto MAX do + divisorSum[num] := divisorSum[num] + div; + divisorCount[num] := divisorCount[num] + 1 + od + od +corp + +proc arithmetic(word n) bool: + divisorSum[n] % divisorCount[n] = 0 +corp + +proc composite(word n) bool: + n > 1 and divisorSum[n] /= n+1 +corp + +proc main() void: + word num, nthArithm, composites; + calculateDivisorSums(); + + writeln("First 100 arithmetic numbers:"); + + num := 0; + composites := 0; + for nthArithm from 1 upto 10000 do + while num := num+1; not arithmetic(num) do od; + if composite(num) then composites := composites + 1 fi; + + if nthArithm <= 100 then + write(num:5); + if nthArithm % 10 = 0 then writeln() fi + fi; + + if nthArithm = 1000 or nthArithm = 10000 then + writeln(); + writeln("The ",nthArithm,"th arithmetic number is ",num,"."); + writeln("Of the first ",nthArithm," arithmetic numbers, ", + composites," are composite.") + fi + od +corp diff --git a/Task/Ascending-primes/EasyLang/ascending-primes.easy b/Task/Ascending-primes/EasyLang/ascending-primes.easy new file mode 100644 index 0000000000..499d11769c --- /dev/null +++ b/Task/Ascending-primes/EasyLang/ascending-primes.easy @@ -0,0 +1,25 @@ +func isprim num . + if num < 2 + return 0 + . + i = 2 + while i <= sqrt num + if num mod i = 0 + return 0 + . + i += 1 + . + return 1 +. +proc nextasc n . . + if isprim n = 1 + write n & " " + . + if n > 123456789 + return + . + for d = n mod 10 + 1 to 9 + nextasc n * 10 + d + . +. +nextasc 0 diff --git a/Task/Attractive-numbers/EasyLang/attractive-numbers.easy b/Task/Attractive-numbers/EasyLang/attractive-numbers.easy new file mode 100644 index 0000000000..6128796beb --- /dev/null +++ b/Task/Attractive-numbers/EasyLang/attractive-numbers.easy @@ -0,0 +1,32 @@ +func isprim num . + if num < 2 + return 0 + . + i = 2 + while i <= sqrt num + if num mod i = 0 + return 0 + . + i += 1 + . + return 1 +. +func count n . + f = 2 + repeat + if n mod f = 0 + cnt += 1 + n /= f + else + f += 1 + . + until n = 1 + . + return cnt +. +for i = 2 to 120 + n = count i + if isprim n = 1 + write i & " " + . +. diff --git a/Task/Averages-Mean-angle/EasyLang/averages-mean-angle.easy b/Task/Averages-Mean-angle/EasyLang/averages-mean-angle.easy new file mode 100644 index 0000000000..9186db4ae0 --- /dev/null +++ b/Task/Averages-Mean-angle/EasyLang/averages-mean-angle.easy @@ -0,0 +1,10 @@ +func mean ang[] . + for ang in ang[] + x += cos ang + y += sin ang + . + return atan2 (y / len ang[]) (x / len ang[]) +. +print mean [ 350 10 ] +print mean [ 90 180 270 360 ] +print mean [ 10 20 30 ] diff --git a/Task/Averages-Mean-time-of-day/EasyLang/averages-mean-time-of-day.easy b/Task/Averages-Mean-time-of-day/EasyLang/averages-mean-time-of-day.easy new file mode 100644 index 0000000000..636e7daff7 --- /dev/null +++ b/Task/Averages-Mean-time-of-day/EasyLang/averages-mean-time-of-day.easy @@ -0,0 +1,32 @@ +func tm2deg t$ . + t[] = number strsplit t$ ":" + return 360 * t[1] / 24.0 + 360 * t[2] / (24 * 60.0) + 360 * t[3] / (24 * 3600.0) +. +func$ deg2tm deg . + len t[] 3 + h = floor (24 * 60 * 60 * deg / 360) + t[3] = h mod 60 + h = h div 60 + t[2] = h mod 60 + t[1] = h div 60 + for h in t[] + if h < 10 + s$ &= 0 + . + s$ &= h + s$ &= ":" + . + return substr s$ 1 8 +. +func mean ang[] . + for ang in ang[] + x += cos ang + y += sin ang + . + return atan2 (y / len ang[]) (x / len ang[]) +. +in$ = "23:00:17 23:40:20 00:12:45 00:17:19" +for s$ in strsplit in$ " " + ar[] &= tm2deg s$ +. +print deg2tm (360 + mean ar[]) diff --git a/Task/Averages-Median/Bracmat/averages-median.bracmat b/Task/Averages-Median/Bracmat/averages-median.bracmat index d8a19b0c04..6a49df5696 100644 --- a/Task/Averages-Median/Bracmat/averages-median.bracmat +++ b/Task/Averages-Median/Bracmat/averages-median.bracmat @@ -1,25 +1,47 @@ -(median= - begin decimals end int list med med1 med2 num number -. 0:?list - & whl - ' ( @( !arg - : ? - ((%@:~" ":~",") ?:?number) - ((" "|",") ?arg|:?arg) - ) - & @( !number - : ( #?int "." [?begin #?decimals [?end - & !int+!decimals*10^(!begin+-1*!end):?num - | ?num - ) - ) - & (!num.)+!list:?list +( ( median + = begin decimals end int list + , med med1 med2 num number + . ( convertToRational + = + . new$(UFP,'(.$arg:?V)) + : ?ufp + & (ufp..go)$ + & (ufp..export)$(Q.V) + ) + & 0:?list + & whl + ' ( !arg:%?number ?arg + & convertToRational$!number:?rationalnumber + & (!rationalnumber.)+!list:?list + ) + & !list:?+[?end + & ( !end*1/2:~/ + & !list + : ? + + [!(=1/2*!end+-1) + + (?med1.?) + + (?med2.?) + + ? + & !med1*1/2+!med2*1/2:?med + | !list:?+[(div$(1/2*!end,1))+(?med.)+? + ) + & (new$(UFP,'(.$med)).go)$ + ) +& out$(median$("4.1" 4 "1.2" "6.235" "7868.33")) +& out + $ ( median + $ ( "4.4" + "2.3" + "-1.7" + "7.5" + "6.6" + "0.0" + "1.9" + "8.2" + "9.3" + "4.5" ) - & !list:?+[?end - & ( !end*1/2:~/ - & !list:?+[!(=1/2*!end+-1)+(?med1.)+(?med2.)+? - & !med1*1/2+!med2*1/2:?med - | !list:?+[(div$(1/2*!end,1))+(?med.)+? ) - & !med +& out$(median$(1 5 3 2 4)) +& out$(median$(1 5 3 6 4 2)) ); diff --git a/Task/Averages-Root-mean-square/EasyLang/averages-root-mean-square.easy b/Task/Averages-Root-mean-square/EasyLang/averages-root-mean-square.easy new file mode 100644 index 0000000000..50fec25962 --- /dev/null +++ b/Task/Averages-Root-mean-square/EasyLang/averages-root-mean-square.easy @@ -0,0 +1,8 @@ +func rms v[] . + for v in v[] + sum += v * v + . + return sqrt (sum / len v[]) +. +v[] = [ 1 2 3 4 5 6 7 8 9 10 ] +print rms v[] diff --git a/Task/Bell-numbers/EasyLang/bell-numbers.easy b/Task/Bell-numbers/EasyLang/bell-numbers.easy new file mode 100644 index 0000000000..e554895111 --- /dev/null +++ b/Task/Bell-numbers/EasyLang/bell-numbers.easy @@ -0,0 +1,14 @@ +func bell n . + len list[] n + list[1] = 1 + for i = 2 to n + for j = 1 to i - 2 + list[i - j - 1] += list[i - j] + . + list[i] = list[1] + list[i - 1] + . + return list[n] +. +for i = 1 to 15 + print bell i +. diff --git a/Task/Bioinformatics-base-count/EasyLang/bioinformatics-base-count.easy b/Task/Bioinformatics-base-count/EasyLang/bioinformatics-base-count.easy new file mode 100644 index 0000000000..d7c2cc2230 --- /dev/null +++ b/Task/Bioinformatics-base-count/EasyLang/bioinformatics-base-count.easy @@ -0,0 +1,39 @@ +len d[] 26 +pos = 1 +numfmt 0 4 +repeat + s$ = input + until s$ = "" + for c$ in strchars s$ + if pos mod 40 = 1 + write pos & ":" + . + if pos mod 4 = 1 + write " " + . + write c$ + if pos mod 40 = 0 + print "" + . + pos += 1 + c = strcode c$ + d[c - 64] += 1 + . +. +print "" +for i in [ 1 3 7 20 ] + write strchar (64 + i) & ": " + print d[i] +. +print "Total: " & d[1] + d[3] + d[7] + d[20] +input_data +CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATG +CTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTG +AGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGAT +GGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT +CGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGG +TCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA +TTTAATTTTTCTATATAGCGATCTGTATTTAAGCAATTCATTTAGGTTAT +CGCCGCGATGCTCGGTTCGGACCGCCAAGCATCTGGCTCCACTGCTAGTG +TCCTAAATTTGAATGGCAAACACAAATAAGATTTAGCAATTCGTGTAGAC +GACCGGGGACTTGCATGATGGGAGCAGCTTTGTTAAACTACGAACGTAAT diff --git a/Task/Blum-integer/EasyLang/blum-integer.easy b/Task/Blum-integer/EasyLang/blum-integer.easy new file mode 100644 index 0000000000..7b73286f92 --- /dev/null +++ b/Task/Blum-integer/EasyLang/blum-integer.easy @@ -0,0 +1,38 @@ +fastfunc semiprim n . + d = 3 + while d * d <= n + while n mod d = 0 + if c = 2 + return 0 + . + n /= d + c += 1 + . + d += 2 + . + if c = 1 + return n + . +. +print "The first 50 Blum integers:" +n = 3 +numfmt 0 4 +repeat + prim1 = semiprim n + if prim1 <> 0 + if prim1 mod 4 = 3 + prim2 = n div prim1 + if prim2 <> prim1 and prim2 mod 4 = 3 + c += 1 + if c <= 50 + write n + if c mod 10 = 0 ; print "" ; . + . + . + . + . + until c >= 26828 + n += 2 +. +print "" +print "The 26828th Blum integer is: " & n diff --git a/Task/Blum-integer/Quackery/blum-integer.quackery b/Task/Blum-integer/Quackery/blum-integer.quackery new file mode 100644 index 0000000000..8ad0f6d807 --- /dev/null +++ b/Task/Blum-integer/Quackery/blum-integer.quackery @@ -0,0 +1,48 @@ + 600000 eratosthenes + + [ dup sqrt + tuck dup * = ] is exactsqrt ( n --> n b ) + + [ dup isprime iff + [ drop false ] done + dup 4 mod 1 != iff + [ drop false ] done + dup exactsqrt iff + [ 2drop false ] done + temp put + 3 from + [ 4 incr + index temp share > iff + [ drop false end ] + done + index isprime not if done + dup index /mod 0 != iff + drop done + isprime not if done + drop index end ] + temp release ] is blum ( n --> n ) + + [ dup blum + over echo + say " = " + dup echo + say " * " + / echo cr ] is echoblum ( n --> ) + + say "The First 50 Blum integers:" + cr cr + [] 1 from + [ 4 incr + index blum if + [ index join ] + dup size 50 = if end ] + witheach echoblum + cr + say "The 26828th Blum integer:" + cr cr + 0 1 from + [ 4 incr + index blum if 1+ + dup 26828 = if + [ drop index end ] ] + echoblum diff --git a/Task/Brazilian-numbers/Quackery/brazilian-numbers.quackery b/Task/Brazilian-numbers/Quackery/brazilian-numbers.quackery new file mode 100644 index 0000000000..2cedb0aaca --- /dev/null +++ b/Task/Brazilian-numbers/Quackery/brazilian-numbers.quackery @@ -0,0 +1,49 @@ + [ dup base put + /mod temp put + true swap + [ dup 0 > while + base share /mod + temp share != iff + [ dip not ] + done + again ] + drop + temp release + base release ] is allsame ( n n --> b ) + + [ false swap + dup 3 - times + [ dup i 2 + + allsame iff + [ dip not + conclude ] + done ] + drop ] is brazilian ( n --> b ) + + say "First 20 Brazilian numbers:" cr + [] 0 + [ dup brazilian if + [ dup dip join ] + 1+ + over size 20 = until ] + drop echo + cr + cr + say "First 20 odd Brazilian numbers:" cr + [] 1 + [ dup brazilian if + [ dup dip join ] + 2 + + over size 20 = until ] + drop echo + cr + cr + say "First 20 prime Brazilian numbers:" cr + [] 1 + [ dup isprime not iff + [ 2 + ] again + dup brazilian if + [ dup dip join ] + 2 + + over size 20 = until ] + drop echo diff --git a/Task/Bulls-and-cows/FutureBasic/bulls-and-cows.basic b/Task/Bulls-and-cows/FutureBasic/bulls-and-cows.basic new file mode 100644 index 0000000000..ee2dc80d65 --- /dev/null +++ b/Task/Bulls-and-cows/FutureBasic/bulls-and-cows.basic @@ -0,0 +1,107 @@ +include "NSLog.incl" +str15 guess, goal +short x, y +cgRect wndrect + +begin enum 1 + _window + _bullLabel + _cowLabel + _horzLine + _vertLine + _newGameBtn + _alert = 101 +end enum + +void local fn showStr( string as str15 ) + short r + x = 20 + for r = 1 to string[0] + print %(x,y)chr$( string[r] ); + x += 39 + next +end fn + +void local fn NewGame + str15 ch + goal = "" : guess = "" :y = 20 + window _window,,wndRect + text ,,fn colorRed + cls + fn showStr( "????" ) + + do + ch = chr$(rnd(9) or _"0") + if instr$(0, goal, ch) == 0 then goal += ch + until goal[0] == 4 + + nslog(@"%u",val&(goal)) //unrem for testing + y += 48 +end fn + +local fn SetWindowFrame + CGRect r = fn WindowContentRect( _window ) + r.size.height += 32 + r.origin.y -= 32 + window _window,,r + if ( r.origin.y < 150 ) + alert _alert,, @"Too many guesses!",, @"Give up", YES + fn newGame + end if +end fn + +local fn play( ch as str15 ) + short r, bulls = 0, cows = 0 + if instr$(0, guess, ch) then exit fn + guess += ch + text,,fn colorDarkGray + fn showStr( guess ) + if guess[0] < 4 then exit fn + + for r = 1 to 4 + if goal[r] == guess[r] then bulls++ : continue + if instr$(0, goal, chr$(guess[r]) ) then cows++ + next + + select + case bulls == 4 + text ,,fn colorRed + print %(x + 31, y)("W I N!") + y = 20 : fn showStr( goal ) + case else : print %(x + 35, y)bulls;" "; cows + y += 32 : guess = "" + end select + fn SetWindowFrame +end fn + + +void local fn BuildWindow + subclass window _window, @"Bulls and cows", (0,0,311,114), NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + wndrect = = fn WindowContentRect( _window ) + textlabel _bullLabel, @"🐂", (198,59,38,40) + textlabel _cowLabel, @"🐄", (255,59,38,40) + ControlSetFontWithName( _bullLabel, NULL, 30 ) + ControlSetFontWithName( _cowLabel, NULL, 30 ) + box _horzLine,, (12,50,287,5), NSBoxSeparator + box _vertLine,, (180,12,5,90), NSBoxSeparator + ViewSetAutoresizingMask( _vertLine, NSViewHeightSizable ) + button _newGameBtn,,, @"New Game", (198,13,100,32) + ViewSetAutoresizingMask( _newGameBtn, NSViewMaxYMargin ) + text @"menlo bold",24,,fn ColorWindowBackground +end fn + +void local fn DoDialog( evt as long, tag as long ) + select ( evt ) + case _windowKeyDown //: stop + short ch = intval( fn EventCharacters ) + if ch then fn play( chr$( ch or _"0" ) ):DialogEventSetBool(YES) + case _btnClick : fn NewGame + case _windowWillClose : end + end select +end fn + +on dialog fn DoDialog +fn buildWindow +fn newGame + +HandleEvents diff --git a/Task/Caesar-cipher/Forth/caesar-cipher.fth b/Task/Caesar-cipher/Forth/caesar-cipher.fth index e92410572f..ba76eb1619 100644 --- a/Task/Caesar-cipher/Forth/caesar-cipher.fth +++ b/Task/Caesar-cipher/Forth/caesar-cipher.fth @@ -1,19 +1,19 @@ -: ceasar ( c n -- c ) +: caesar ( c n -- c ) over 32 or [char] a - dup 0 26 within if over + 25 > if 26 - then + else 2drop then ; -: ceasar-string ( n str len -- ) - over + swap do i c@ over ceasar i c! loop drop ; +: caesar-string ( n str len -- ) + over + swap do i c@ over caesar i c! loop drop ; -: ceasar-inverse ( n -- 'n ) 26 swap - 26 mod ; +: caesar-inverse ( n -- 'n ) 26 swap - 26 mod ; 2variable test s" The five boxing wizards jump quickly!" test 2! -3 test 2@ ceasar-string +3 test 2@ caesar-string test 2@ cr type -3 ceasar-inverse test 2@ ceasar-string +3 caesar-inverse test 2@ caesar-string test 2@ cr type diff --git a/Task/Caesar-cipher/Icon/caesar-cipher.icon b/Task/Caesar-cipher/Icon/caesar-cipher-1.icon similarity index 100% rename from Task/Caesar-cipher/Icon/caesar-cipher.icon rename to Task/Caesar-cipher/Icon/caesar-cipher-1.icon diff --git a/Task/Caesar-cipher/Icon/caesar-cipher-2.icon b/Task/Caesar-cipher/Icon/caesar-cipher-2.icon new file mode 100644 index 0000000000..86efede9f2 --- /dev/null +++ b/Task/Caesar-cipher/Icon/caesar-cipher-2.icon @@ -0,0 +1,12 @@ +(function caeser by of + (let alphabets (proj (map char-code) (range 65 91) (range 97 123)) + shifted (.. vec (map (rotate by) alphabets)) + table (kv-dict (flatten alphabets) (flatten shifted))) + (... str (map #(or (table %) %) of))) + +(let original "The Quick Brown Fox Jumps Over The Lazy Dog." + encrypted (caeser -1 original) + decrypted (caeser 1 encrypted)) +(str "Original: " original " +Encrypted: " encrypted " +Decrypted: " decrypted) diff --git a/Task/Closures-Value-capture/Icon/closures-value-capture.icon b/Task/Closures-Value-capture/Icon/closures-value-capture-1.icon similarity index 100% rename from Task/Closures-Value-capture/Icon/closures-value-capture.icon rename to Task/Closures-Value-capture/Icon/closures-value-capture-1.icon diff --git a/Task/Closures-Value-capture/Icon/closures-value-capture-2.icon b/Task/Closures-Value-capture/Icon/closures-value-capture-2.icon new file mode 100644 index 0000000000..c8c1186480 --- /dev/null +++ b/Task/Closures-Value-capture/Icon/closures-value-capture-2.icon @@ -0,0 +1,3 @@ +(var funcs (for x (range 11) #(* x x))) + +[(0 funcs) ((3 funcs)) ((4 funcs))] diff --git a/Task/Combinations-and-permutations/Bracmat/combinations-and-permutations.bracmat b/Task/Combinations-and-permutations/Bracmat/combinations-and-permutations.bracmat index 147c7c5917..f92cf770a3 100644 --- a/Task/Combinations-and-permutations/Bracmat/combinations-and-permutations.bracmat +++ b/Task/Combinations-and-permutations/Bracmat/combinations-and-permutations.bracmat @@ -1,4 +1,4 @@ -( ( C + ( C = n k coef . !arg:(?n,?k) & (!n+-1*!k:0 + & !coef*!n*!k^-1:?coef + & !k+-1:?k + & !n+-1:?n + ) + & !coef + ) + ) + ) +& compileBinomialFunctionThatDoesFloatingPointCalculations$ + : ?binom & ( P = n k result . !arg:(?n,?k) @@ -23,6 +52,25 @@ ) & !result ) +& ( compilePermutationFunctionThatDoesFloatingPointCalculations + = + . new + $ ( UFP + , + ' ( (s.n) (s.k) + . !n+-1*!k:?k + & 1:?result + & whl + ' ( !n:>!k + & !n*!result:?result + & !n+-1:?n + ) + & !result + ) + ) + ) +& compilePermutationFunctionThatDoesFloatingPointCalculations$ + : ?permu & 0:?i & whl ' ( 1+!i:~>12:?i @@ -33,7 +81,8 @@ & whl ' ( 10+!i:~>60:?i & div$(!i.3):?k - & out$(!i C !k "=" C$(!i,!k)) + & out$(!i Cn !k "= " C$(!i,!k)) + & out$(!i Cf !k "=" (binom..go)$(!i,!k)) ) & ( displayBig = @@ -45,12 +94,26 @@ & whl ' ( !is:%?i ?is & div$(!i.3):?k - & out$(str$(!i " P " !k " = " displayBig$(P$(!i,!k)))) + & out + $ ( str + $ (!i " Pn " !k " = " displayBig$(P$(!i,!k))) + ) + & out + $ ( str + $ (!i " Pf " !k " = " (permu..go)$(!i,!k)) + ) ) & 0:?i & whl ' ( 100+!i:~>1000:?i & div$(!i.3):?k - & out$(str$(!i " C " !k " = " displayBig$(C$(!i,!k)))) + & out + $ ( str + $ (!i " Cn " !k " = " displayBig$(C$(!i,!k))) + ) + & out + $ ( str + $ (!i " Cf " !k " = " (binom..go)$(!i,!k)) + ) ) -); +& all done; diff --git a/Task/Combinations-and-permutations/Zig/combinations-and-permutations.zig b/Task/Combinations-and-permutations/Zig/combinations-and-permutations.zig new file mode 100644 index 0000000000..63ea74739c --- /dev/null +++ b/Task/Combinations-and-permutations/Zig/combinations-and-permutations.zig @@ -0,0 +1,32 @@ + const std = @import("std"); + const num = f64; + + pub fn perm(n: num, k: num) num { + var result: num = 1; + var i: num = 0; + while (i < k) : (i += 1) { + result *= n - i; + } + return result; + } + + pub fn comb(n: num, k: num) num { + return perm(n, k) / perm(k, k); + } + + pub fn main() !void { + var stdout = std.io.getStdOut().writer(); + + const p: num = 12; + const c: num = 60; + var j: num = 1; + var k: num = 10; + + while (j < p) : (j += 1) { + try stdout.print("P({d},{d}) = {d}\n", .{ p, j, @floor(perm(p, j)) }); + } + + while (k < c) : (k += 10) { + try stdout.print("C({d},{d}) = {d}\n", .{ c, k, @floor(comb(c, k)) }); + } + } diff --git a/Task/Combinations-with-repetitions/Acornsoft-Lisp/combinations-with-repetitions.lisp b/Task/Combinations-with-repetitions/Acornsoft-Lisp/combinations-with-repetitions.lisp new file mode 100644 index 0000000000..9c4ae3114a --- /dev/null +++ b/Task/Combinations-with-repetitions/Acornsoft-Lisp/combinations-with-repetitions.lisp @@ -0,0 +1,17 @@ +(defun samples (k items) + (cond + ((zerop k) '(())) + ((null items) '()) + (t (append + (mapc '(lambda (c) (cons (car items) c)) + (samples (sub1 k) items)) + (samples k (cdr items)))))) + +(defun append (a b) + (cond ((null a) b) + (t (cons (car a) (append (cdr a) b))))) + +(defun length (list (len . 0)) + (map '(lambda (e) (setq len (add1 len))) + list) + len) diff --git a/Task/Comments/Phix/comments-1.phix b/Task/Comments/Phix/comments-1.phix index 25289e8d1d..c1dc925cba 100644 --- a/Task/Comments/Phix/comments-1.phix +++ b/Task/Comments/Phix/comments-1.phix @@ -1,3 +1,4 @@ ---> - -- This is a comment +(phixonline)--> + -- this is a comment. + // this is also a comment. + with javascript_semantics + constant limit = iff(platform()=JS?100:1000), showlim=70 + atom t0 = time(), t1 = t0+1 + integer n = 1, count = 0 + printf(1,"The first %d deceptive numbers are:\n",showlim) + while count<limit do + n += 2 + if gcd(n,3*5)=1 + and not is_prime(n) + and powmod(10,n-1,n)=1 then + count += 1 + if count<=showlim then + printf(1," %7d%n",{n,remainder(count,10)=0}) + elsif count=limit or time()>t1 then + printf(1,"The %d%s is %d\r",{count,ord(count),n}) + t1 = time()+1 + end if + end if + end while + printf(1,"\n%s\n",elapsed(time()-t0)) + different: '" & s$[i] & "' (" & hex h & "h)" + print "' position: " & i + return + . + . + print " --> ok" +. +repeat + s$ = input + until s$ = "EOF" + print "'" & s$ & "'" & " length " & len s$ + call samechar s$ + print "" +. +input_data + + +2 +333 +.55 +tttTTT +4444 444k +EOF diff --git a/Task/Determine-if-a-string-has-all-unique-characters/EasyLang/determine-if-a-string-has-all-unique-characters.easy b/Task/Determine-if-a-string-has-all-unique-characters/EasyLang/determine-if-a-string-has-all-unique-characters.easy new file mode 100644 index 0000000000..83e9bfebfd --- /dev/null +++ b/Task/Determine-if-a-string-has-all-unique-characters/EasyLang/determine-if-a-string-has-all-unique-characters.easy @@ -0,0 +1,37 @@ +func$ hex h . + for d in [ h div 16 h mod 16 ] + if d > 9 + d += 7 + . + h$ &= strchar (d + 48) + . + return h$ +. +proc unichar s$ . . + len d[] 65536 + s$[] = strchars s$ + for i to len s$[] + h = strcode s$[i] + if d[h] <> 0 + write " --> duplicates: '" & s$[i] & "' (" & hex h & "h)" + print "' positions: " & d[h] & ", " & i + return + . + d[h] = i + . + print "ok" +. +repeat + s$ = input + until s$ = "EOF" + print "'" & s$ & "'" & " length " & len s$ + call unichar s$ + print "" +. +input_data + +. +abcABC +XYZ ZYX +1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ +EOF diff --git a/Task/Determine-if-a-string-is-numeric/Bracmat/determine-if-a-string-is-numeric-3.bracmat b/Task/Determine-if-a-string-is-numeric/Bracmat/determine-if-a-string-is-numeric-3.bracmat deleted file mode 100644 index 103473b1a4..0000000000 --- a/Task/Determine-if-a-string-is-numeric/Bracmat/determine-if-a-string-is-numeric-3.bracmat +++ /dev/null @@ -1,35 +0,0 @@ -(float2fraction= - integerPart decimalPart d1 dn exp sign -. @( !arg - : ~/#?integerPart - ( &0:?decimalPart:?d1:?dn - | "." - [?d1 - (|? 0|`) - ( &0:?decimalPart - | ~/#?decimalPart:>0 - ) - [?dn - ) - ( &0:?exp - | (E|e) ~/#?exp - ) - ) - & ( !integerPart*(-1:?sign):>0:?integerPart - | 1:?sign - ) - & !sign*(!integerPart+!decimalPart*10^(!d1+-1*!dn))*10^!exp -); - -( out$float2fraction$"1.2" -& out$float2fraction$"1.02" -& out$float2fraction$"1.01" -& out$float2fraction$"10.01" -& out$float2fraction$"10.01e10" -& out$float2fraction$"10.01e1" -& out$float2fraction$"10.01e2" -& out$float2fraction$"10.01e-2" -& out$float2fraction$"-10.01e-2" -& out$float2fraction$"-10e-2" -& out$float2fraction$"0.000" -); diff --git a/Task/Dynamic-variable-names/Elena/dynamic-variable-names.elena b/Task/Dynamic-variable-names/Elena/dynamic-variable-names.elena index 68021c6ff2..64232afd2c 100644 --- a/Task/Dynamic-variable-names/Elena/dynamic-variable-names.elena +++ b/Task/Dynamic-variable-names/Elena/dynamic-variable-names.elena @@ -3,19 +3,19 @@ import extensions; class TestClass { - object theVariables; + object variables; constructor() { - theVariables := new DynamicStruct() + variables := new DynamicStruct() } function() { auto prop := new MessageName(console.write:"Enter the variable name:".readLine()); - (prop.setPropertyMessage())(theVariables,42); + (prop.setPropertyMessage())(variables,42); - console.printLine(prop.toPrintable(),"=",(prop.getPropertyMessage())(theVariables)).readChar() + console.printLine(prop.toPrintable(),"=",(prop.getPropertyMessage())(variables)).readChar() } } diff --git a/Task/Dynamic-variable-names/Haskell/dynamic-variable-names.hs b/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-1.hs similarity index 100% rename from Task/Dynamic-variable-names/Haskell/dynamic-variable-names.hs rename to Task/Dynamic-variable-names/Haskell/dynamic-variable-names-1.hs diff --git a/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-2.hs b/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-2.hs new file mode 100644 index 0000000000..87264cebc2 --- /dev/null +++ b/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-2.hs @@ -0,0 +1,2 @@ +(let var-name "hello") +((eval (str "(var " var-name ")")) 123) diff --git a/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-3.hs b/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-3.hs new file mode 100644 index 0000000000..6d4ba0090d --- /dev/null +++ b/Task/Dynamic-variable-names/Haskell/dynamic-variable-names-3.hs @@ -0,0 +1,2 @@ +(let var-name "hello") +(eval (str "(var " var-name " 123)")) diff --git a/Task/Eban-numbers/EasyLang/eban-numbers.easy b/Task/Eban-numbers/EasyLang/eban-numbers.easy new file mode 100644 index 0000000000..c01bcc7bee --- /dev/null +++ b/Task/Eban-numbers/EasyLang/eban-numbers.easy @@ -0,0 +1,39 @@ +func x n . + if n = 0 or n = 2 or n = 4 or n = 6 + return 1 + . +. +proc go start stop printable . . + write start & " - " & stop & ":" + for i = start step 2 to stop + b = i div 1000000000 + r = i mod 1000000000 + m = r div 1000000 + r = i mod 1000000 + t = r div 1000 + r = r mod 1000 + if m >= 30 and m <= 66 + m = m mod 10 + . + if t >= 30 and t <= 66 + t = t mod 10 + . + if r >= 30 and r <= 66 + r = r mod 10 + . + if x b = 1 and x m = 1 and x t = 1 and x r = 1 + count += 1 + if printable = 1 + write " " & i + . + . + . + print " (count=" & count & ")" +. +go 2 1000 1 +go 1000 4000 1 +go 2 10000 0 +go 2 100000 0 +go 2 1000000 0 +go 2 10000000 0 +go 2 100000000 0 diff --git a/Task/Eban-numbers/Odin/eban-numbers.odin b/Task/Eban-numbers/Odin/eban-numbers.odin new file mode 100644 index 0000000000..dc39476c15 --- /dev/null +++ b/Task/Eban-numbers/Odin/eban-numbers.odin @@ -0,0 +1,64 @@ +package eban_numbers +/* imports */ +import "core:fmt" +/* globals */ +Range :: struct { + start: i32, + end: i32, + print: bool, +} +printcounter: i32 = 0 +/* main block */ +main :: proc() { + rgs := [?]Range{ + {2, 1000, true}, + {1000, 4000, true}, + {2, 1e4, false}, + {2, 1e5, false}, + {2, 1e6, false}, + {2, 1e7, false}, + {2, 1e8, false}, + {2, 1e9, false}, + } + for rg in rgs { + if rg.start == 2 { + fmt.printf("eban numbers up to and including %d:\n", rg.end) + } else { + fmt.printf("eban numbers between %d and %d (inclusive):\n", rg.start, rg.end) + } + count := i32(0) + for i := rg.start; i <= i32(rg.end); i += i32(2) { + b := i / 1000000000 + r := i % 1000000000 + m := r / 1000000 + r = i % 1000000 + t := r / 1000 + r %= 1000 + if m >= 30 && m <= 66 { + m %= 10 + } + if t >= 30 && t <= 66 { + t %= 10 + } + if r >= 30 && r <= 66 { + r %= 10 + } + if b == 0 || b == 2 || b == 4 || b == 6 { + if m == 0 || m == 2 || m == 4 || m == 6 { + if t == 0 || t == 2 || t == 4 || t == 6 { + if r == 0 || r == 2 || r == 4 || r == 6 { + if rg.print { + fmt.printf("%d ", i) + } + count += 1 + } + } + } + } + } + if rg.print { + fmt.println() + } + fmt.println("count =", count, "\n") + } +} diff --git a/Task/Enforced-immutability/COBOL/enforced-immutability-1.cobol b/Task/Enforced-immutability/COBOL/enforced-immutability-1.cobol index fc1dc90b52..aae817a30e 100644 --- a/Task/Enforced-immutability/COBOL/enforced-immutability-1.cobol +++ b/Task/Enforced-immutability/COBOL/enforced-immutability-1.cobol @@ -1,4 +1,4 @@ -ENVIRONMENT DIVISION. -CONFIGURATION SECTION. -SPECIAL-NAMES. - SYMBOLIC CHARACTERS NUL IS 0, TAB IS 9. + ENVIRONMENT DIVISION. + CONFIGURATION SECTION. + SPECIAL-NAMES. + SYMBOLIC CHARACTERS NUL IS 0, TAB IS 9. diff --git a/Task/Enforced-immutability/COBOL/enforced-immutability-2.cobol b/Task/Enforced-immutability/COBOL/enforced-immutability-2.cobol index 9d54d7c7a0..021a326011 100644 --- a/Task/Enforced-immutability/COBOL/enforced-immutability-2.cobol +++ b/Task/Enforced-immutability/COBOL/enforced-immutability-2.cobol @@ -1 +1 @@ -01 Foo CONSTANT AS "Foo". + 01 Foo CONSTANT AS "Foo". diff --git a/Task/Enforced-immutability/COBOL/enforced-immutability-3.cobol b/Task/Enforced-immutability/COBOL/enforced-immutability-3.cobol index dc51eeb505..c220ce91a0 100644 --- a/Task/Enforced-immutability/COBOL/enforced-immutability-3.cobol +++ b/Task/Enforced-immutability/COBOL/enforced-immutability-3.cobol @@ -1 +1 @@ -78 Foo VALUE "Foo". + 78 Foo VALUE "Foo". diff --git a/Task/Enforced-immutability/COBOL/enforced-immutability-4.cobol b/Task/Enforced-immutability/COBOL/enforced-immutability-4.cobol index 321ecd9787..1ab8b7e66e 100644 --- a/Task/Enforced-immutability/COBOL/enforced-immutability-4.cobol +++ b/Task/Enforced-immutability/COBOL/enforced-immutability-4.cobol @@ -1,2 +1,2 @@ -CONSTANT SECTION. -01 Foo VALUE "Foo". + CONSTANT SECTION. + 01 Foo VALUE "Foo". diff --git a/Task/Entropy/EasyLang/entropy.easy b/Task/Entropy/EasyLang/entropy.easy new file mode 100644 index 0000000000..c80904ea59 --- /dev/null +++ b/Task/Entropy/EasyLang/entropy.easy @@ -0,0 +1,14 @@ +func entropy s$ . + len d[] 255 + for c$ in strchars s$ + d[strcode c$] += 1 + . + for cnt in d[] + if cnt > 0 + prop = cnt / len s$ + entr -= (prop * logn prop / logn 2) + . + . + return entr +. +print entropy "1223334444" diff --git a/Task/Equilibrium-index/Elena/equilibrium-index.elena b/Task/Equilibrium-index/Elena/equilibrium-index.elena index 874de88bda..1e97922ac9 100644 --- a/Task/Equilibrium-index/Elena/equilibrium-index.elena +++ b/Task/Equilibrium-index/Elena/equilibrium-index.elena @@ -29,7 +29,7 @@ class EquilibriumEnumerator : Enumerator while(en.next()) { - var element := en.get(); + var element := *en; right -= element; bool found := (left == right); left += element; @@ -56,7 +56,7 @@ class EquilibriumEnumerator : Enumerator en.reset(); } - get() = index; + get Value() = index; enumerable() => en; } diff --git a/Task/Euclid-Mullin-sequence/Maxima/euclid-mullin-sequence.maxima b/Task/Euclid-Mullin-sequence/Maxima/euclid-mullin-sequence.maxima new file mode 100644 index 0000000000..7f74057ca2 --- /dev/null +++ b/Task/Euclid-Mullin-sequence/Maxima/euclid-mullin-sequence.maxima @@ -0,0 +1,4 @@ +euclid_mullin(n):=if n=1 then 2 else ifactors(1+product(euclid_mullin(i),i,1,n-1))[1][1]$ + +/* Test case */ +makelist(euclid_mullin(k),k,16); diff --git a/Task/Eulers-constant-0.5772.../Maxima/eulers-constant-0.5772....maxima b/Task/Eulers-constant-0.5772.../Maxima/eulers-constant-0.5772....maxima new file mode 100644 index 0000000000..3763cc1f71 --- /dev/null +++ b/Task/Eulers-constant-0.5772.../Maxima/eulers-constant-0.5772....maxima @@ -0,0 +1 @@ +%gamma,numer; diff --git a/Task/Eulers-identity/Maxima/eulers-identity.maxima b/Task/Eulers-identity/Maxima/eulers-identity.maxima new file mode 100644 index 0000000000..3664c05a55 --- /dev/null +++ b/Task/Eulers-identity/Maxima/eulers-identity.maxima @@ -0,0 +1 @@ +is(equal(%e^(%i*%pi)+1,0)); diff --git a/Task/Even-or-odd/EasyLang/even-or-odd.easy b/Task/Even-or-odd/EasyLang/even-or-odd.easy new file mode 100644 index 0000000000..4da1694a01 --- /dev/null +++ b/Task/Even-or-odd/EasyLang/even-or-odd.easy @@ -0,0 +1,6 @@ +a = 13 +if a mod 2 = 0 + print a & " is even" +else + print a & " is odd" +. diff --git a/Task/Evolutionary-algorithm/Elena/evolutionary-algorithm.elena b/Task/Evolutionary-algorithm/Elena/evolutionary-algorithm.elena index 235e31d6bd..18675d0166 100644 --- a/Task/Evolutionary-algorithm/Elena/evolutionary-algorithm.elena +++ b/Task/Evolutionary-algorithm/Elena/evolutionary-algorithm.elena @@ -27,39 +27,39 @@ extension evoHelper class EvoAlgorithm : Enumerator { - object theTarget; - object theCurrent; - object theVariantCount; + object _target; + object _current; + object _variantCount; constructor new(s,count) { - theTarget := s; - theVariantCount := count.toInt(); + _target := s; + _variantCount := count.toInt(); } - get() = theCurrent; + get Value() = _current; bool next() { - if (nil == theCurrent) - { theCurrent := theTarget.Length.randomString(); ^ true }; + if (nil == _current) + { _current := _target.Length.randomString(); ^ true }; - if (theTarget == theCurrent) + if (_target == _current) { ^ false }; - auto variants := Array.allocate(theVariantCount).populate:(x => theCurrent.mutate:P ); + auto variants := Array.allocate(_variantCount).populate:(x => _current.mutate:P ); - theCurrent := variants.sort:(a,b => a.fitnessOf:Target > b.fitnessOf:Target ).at:0; + _current := variants.sort:(a,b => a.fitnessOf:Target > b.fitnessOf:Target ).at:0; ^ true } reset() { - theCurrent := nil + _current := nil } - enumerable() => theTarget; + enumerable() => _target; } public program() diff --git a/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm.icon b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-1.icon similarity index 100% rename from Task/Evolutionary-algorithm/Icon/evolutionary-algorithm.icon rename to Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-1.icon diff --git a/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-2.icon b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-2.icon new file mode 100644 index 0000000000..f80f1d6a42 --- /dev/null +++ b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-2.icon @@ -0,0 +1,7 @@ +(var c 100) ;number of children in each generation +(var p 0.05) ;mutation probability + +(var target "METHINKS IT IS LIKE A WEASEL") +(var tsize (len target)) + +(var alphabet (to-vec " ABCDEFGHIJLKLMNOPQRSTUVWXYZ")) diff --git a/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-3.icon b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-3.icon new file mode 100644 index 0000000000..9d992a43d1 --- /dev/null +++ b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-3.icon @@ -0,0 +1,5 @@ +(var fitness (comp @(map = target) (count val))) +(var perfect-fit? (comp fitness (= tsize))) + +(var rand-char #(rand-pick alphabet)) +(var mutate (map #(if (< (rand) p) (rand-char) %))) diff --git a/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-4.icon b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-4.icon new file mode 100644 index 0000000000..8209d3fa09 --- /dev/null +++ b/Task/Evolutionary-algorithm/Icon/evolutionary-algorithm-4.icon @@ -0,0 +1,12 @@ +(function evolve generation parent + + (print (pad-left " " 3 generation) " " (... str parent) " " (fitness parent)) + + (return-when (perfect-fit? parent)) + + (let children (times c #(mutate parent)) + fittest (max-by fitness (... vec parent children))) + + (recur (inc generation) fittest)) + +(evolve 1 (times tsize rand-char)) diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper/exceptions-catch-an-exception-thrown-in-a-nested-call-1.hopper b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper/exceptions-catch-an-exception-thrown-in-a-nested-call-1.hopper new file mode 100644 index 0000000000..1e0dc6942d --- /dev/null +++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper/exceptions-catch-an-exception-thrown-in-a-nested-call-1.hopper @@ -0,0 +1,36 @@ +#include + +Main + e=0, se="" + Try + Gosub 'Foo' + Catch (e) + Get msg exception, and Move to 'se' + Printnl ("+-MAIN-FOO CALL Error: ",e, " : ", se ) + Finish +End + +Subrutines + +Define ' Foo ' + Gosub ' Bar ' +Return + +Define ' Bar ' + Set '0', Gosub ' Biz ' + Set '1', Gosub ' Biz ' +Return + +Define ' Biz, x ' + a=0, b=0 + If ( x ) + Let ' b:=Sqrt(-1) ' + Nan( a ) do{ Raise (1000,"\n+----Func BIZ: NaN!") } + Else + #( a=log(-1) + log(-1) ) + Nan( a ) do{ Raise (1001,"\n+----Func BIZ: NaN!") } + End If + + Printnl ' "a = ", a, " b = ", b ' + +Return diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper/exceptions-catch-an-exception-thrown-in-a-nested-call-2.hopper b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper/exceptions-catch-an-exception-thrown-in-a-nested-call-2.hopper new file mode 100644 index 0000000000..51375f9be7 --- /dev/null +++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Amazing-Hopper/exceptions-catch-an-exception-thrown-in-a-nested-call-2.hopper @@ -0,0 +1,53 @@ +#include + +Main + e=0, se="" + Try + Gosub 'Foo' + Catch (e) + Get msg exception, and Move to 'se' + Printnl ("+-MAIN Error: ",e, " : ", se ) + Finish +End + +Subrutines + +/* +This "Try" is not considered nested, then, it is necessary +to capture the error and raise the error +*/ +Define ' Foo ' + Try + Gosub ' Bar ' + Catch (e) + Get msg exception, and Move to 'se' + Free try // absolutly nessesary in this chase! + Raise (e, Cat ("\n+--FUNC FOO: ", se) ) + Finish +Return + +Define ' Bar ' + Try + Set '0', Gosub ' Biz ' + Set '1', Gosub ' Biz ' + Catch(e) + Get msg exception, and Move to 'se' + Free try // absolutly nessesary in this chase! + Raise (e, Cat ("\n+---FUNC BAR: ", se) ) + Finish + +Return + +Define ' Biz, x ' + a=0, b=0 + If ( x ) + Let ' b:=Sqrt(-1) ' + Nan( a ) do{ Raise (1000,"\n+----Func BIZ: NaN!") } + Else + #( a=log(-1) + log(-1) ) + Nan( a ) do{ Raise (1001,"\n+----Func BIZ: NaN!") } + End If + + Printnl ' "a = ", a, " b = ", b ' + +Return diff --git a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Elena/exceptions-catch-an-exception-thrown-in-a-nested-call.elena b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Elena/exceptions-catch-an-exception-thrown-in-a-nested-call.elena index 4dab55fb0c..06f339514f 100644 --- a/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Elena/exceptions-catch-an-exception-thrown-in-a-nested-call.elena +++ b/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/Elena/exceptions-catch-an-exception-thrown-in-a-nested-call.elena @@ -2,48 +2,48 @@ import extensions; class U0 : Exception { - constructor new() - <= new(); + constructor new() + <= super new("U0 exception"); } class U1 : Exception { - constructor new() - <= new(); + constructor new() + <= super new("U1 exception"); } singleton Exceptions { - static int i; + static int i; - bar() - <= baz(); + bar() + <= baz(); - baz() - { - if (i == 0) - { - U0.raise() - } - else - { - U1.raise() - } - } + baz() + { + if (i == 0) + { + U0.raise() + } + else + { + U1.raise() + } + } - foo() - { - for(i := 0, i < 2, i += 1) - { - try - { - self.bar() - } - catch(U0 e) - { - console.printLine("U0 Caught") - } - } + foo() + { + for(i := 0, i < 2, i := i + 1) + { + try + { + self.bar() + } + catch(U0 e) + { + console.printLine("U0 Caught") + } + } } } diff --git a/Task/Exceptions/Elena/exceptions-1.elena b/Task/Exceptions/Elena/exceptions-1.elena index 6c2d52d46d..e04e451705 100644 --- a/Task/Exceptions/Elena/exceptions-1.elena +++ b/Task/Exceptions/Elena/exceptions-1.elena @@ -1,5 +1,5 @@ class MyException : Exception { constructor new() - <= new("MyException raised"); + <= super new("MyException raised"); } diff --git a/Task/Exceptions/Elena/exceptions-3.elena b/Task/Exceptions/Elena/exceptions-3.elena index 2fb968c3a6..7b88373b10 100644 --- a/Task/Exceptions/Elena/exceptions-3.elena +++ b/Task/Exceptions/Elena/exceptions-3.elena @@ -1,8 +1,8 @@ try { - o.foo() + foo() } -catch:(MyException e) +catch(MyException e) { // handle exceptions of type MyException and derived } diff --git a/Task/Exceptions/Elena/exceptions-4.elena b/Task/Exceptions/Elena/exceptions-4.elena index 4e54a906fa..a0b642ed18 100644 --- a/Task/Exceptions/Elena/exceptions-4.elena +++ b/Task/Exceptions/Elena/exceptions-4.elena @@ -1,4 +1,8 @@ -o.foo() | on:(e) +try +{ + foo.fail() +} +catch(Exception e) { // handle any type of exception }; diff --git a/Task/Exponentiation-operator/EasyLang/exponentiation-operator.easy b/Task/Exponentiation-operator/EasyLang/exponentiation-operator.easy new file mode 100644 index 0000000000..f7a1d893bf --- /dev/null +++ b/Task/Exponentiation-operator/EasyLang/exponentiation-operator.easy @@ -0,0 +1,13 @@ +func mypow n exp . + r = 1 + if exp < 0 + exp = -exp + n = 1 / n + . + for i to exp + r *= n + . + return r +. +print mypow pi 2 +print mypow 2 -2 diff --git a/Task/Exponentiation-operator/Raku/exponentiation-operator.raku b/Task/Exponentiation-operator/Raku/exponentiation-operator.raku index d5f87c4782..d5a4750ca7 100644 --- a/Task/Exponentiation-operator/Raku/exponentiation-operator.raku +++ b/Task/Exponentiation-operator/Raku/exponentiation-operator.raku @@ -1,12 +1,11 @@ -subset Natural of Int where { $^n >= 0 } +proto pow (Real, Int --> Real) {*} +multi pow (0, 0) { fail '0**0 is undefined' } +multi pow ($base, UInt $exp) { [*] $base xx $exp } +multi pow ($base, $exp) { 1 / samewith $base, -$exp } -multi pow (0, 0) { fail '0**0 is undefined' } -multi pow ($base, Natural $exp) { [*] $base xx $exp } -multi pow ($base, Int $exp) { 1 / pow $base, -$exp } - -sub infix:<***> ($a, $b) { pow $a, $b } +multi infix:<**> (Real $a, Int $b) { pow $a, $b } # Testing say pow .75, -5; -say .75 *** -5; +say .75 ** -5; diff --git a/Task/Factorial-primes/Maxima/factorial-primes.maxima b/Task/Factorial-primes/Maxima/factorial-primes.maxima new file mode 100644 index 0000000000..e78b212a99 --- /dev/null +++ b/Task/Factorial-primes/Maxima/factorial-primes.maxima @@ -0,0 +1,6 @@ +block([i:1,count:0,result:[]], + while count<10 do (if primep(i!-1) or primep(i!+1) then (result:endcons(i,result),count:count+1),i:i+1), + result:map(lambda([x],[x,x!-1,x!+1]),result), + append(map(lambda([x],if primep(x[2]) then [x[1],x[2],"subtracted"]),result),map(lambda([x],if primep(x[3]) then [x[1],x[3],"added"]),result)), + unique(%%), + firstn(%%,10); diff --git a/Task/Factorial/Insitux/factorial-1.insitux b/Task/Factorial/Insitux/factorial-1.insitux new file mode 100644 index 0000000000..a2757e7f71 --- /dev/null +++ b/Task/Factorial/Insitux/factorial-1.insitux @@ -0,0 +1,2 @@ +(function factorial n + (... *1 (range 2 (inc n)))) diff --git a/Task/Factorial/Insitux/factorial-2.insitux b/Task/Factorial/Insitux/factorial-2.insitux new file mode 100644 index 0000000000..74910d9619 --- /dev/null +++ b/Task/Factorial/Insitux/factorial-2.insitux @@ -0,0 +1,4 @@ +(function factorial x + (if (< x 2) + 1 + (*1 x (factorial (dec x))))) diff --git a/Task/Factorial/Insitux/factorial.insitux b/Task/Factorial/Insitux/factorial.insitux deleted file mode 100644 index 9efd9c1e05..0000000000 --- a/Task/Factorial/Insitux/factorial.insitux +++ /dev/null @@ -1,3 +0,0 @@ -(function factorial n - (return-when (< n 2) 1) - (... * (range 1 (inc n)))) diff --git a/Task/Fibonacci-sequence/8080-Assembly/fibonacci-sequence-2.8080 b/Task/Fibonacci-sequence/8080-Assembly/fibonacci-sequence-2.8080 index 20d38802c5..7d99f8a760 100644 --- a/Task/Fibonacci-sequence/8080-Assembly/fibonacci-sequence-2.8080 +++ b/Task/Fibonacci-sequence/8080-Assembly/fibonacci-sequence-2.8080 @@ -2,59 +2,63 @@ ; useful equates ;------------------------------------------------------- bdos equ 5 ; BDOS entry -cr equ 13 ; ASCII carriage return -lf equ 10 ; ASCII line feed -space equ 32 ; ASCII space char +cr equ 13 ; ASCII carriage return +lf equ 10 ; ASCII line feed +space equ 32 ; ASCII space char conout equ 2 ; BDOS console output function -putstr equ 9 ; BDOS print string function +putstr equ 9 ; BDOS print string function +nterms equ 20 ; number of terms (max=24) to display ;------------------------------------------------------- - ; program code begins here + ; main code begins here ;------------------------------------------------------- - org 100h ; load point under CP/M - lxi h,0 ; save command processor's stack - dad sp + org 100h + lxi h,0 ; save CP/M's stack + dad sp shld oldstk - lxi sp,stack ; set our own stack - lxi d,signon ; print signon message - mvi c,putstr + lxi sp,stack ; set our own stack + lxi d,signon ; print signon message + mvi c,putstr call bdos - mvi a,1 ; test by displaying first 20 -mloop: push a ; save our count (putdec will trash) + mvi a,0 ; start with Fib(0) +mloop: push a ; save our count call fib call putdec - mvi a,space ; separate the numbers + mvi a,space ; separate the numbers call putchr - pop a ; get our count back - inr a ; increase it by one - cpi 20+1 ; have we reached our limit? - jnz mloop ; not yet; do another - lhld oldstk ; we're done - get CP/M's stack back + pop a ; get our count back + inr a ; increment it + cpi nterms+1 ; have we reached our limit? + jnz mloop ; no, keep going + lhld oldstk ; all done; get CP/M's stack back sphl ; restore it - ret ; back to command processor + ret ; back to command processor ;------------------------------------------------------- - ; calculate nth Fibonacci number + ; calculate nth Fibonacci number (max n = 24) ; entry: A = n ; exit: HL = Fib(n) ;------------------------------------------------------- fib: mov c,a ; C holds n - lxi d,0 ; initial value for Fib(n-2) - lxi h,1 ; intiial value for Fib(n-1) + lxi d,0 ; DE holds Fib(n-2) + lxi h,1 ; HL holds Fib(n-1) + ana a ; Fib(0) is a special case + jnz fib2 ; n > 0 so calculate normally + xchg ; otherwise return with HL=0 + ret fib2: dcr c jz fib3 ; we're done push h ; save Fib(n-1) - dad d ; HL holds Fib(n) - pop d ; Former Fib(n-1) now Fib(n-2) - jmp fib2 ; loop until done + dad d ; HL = Fib(n), soon to be Fib(n-1) + pop d ; DE = old F(n-1), now Fib(n-2) + jmp fib2 ; ready for next pass fib3: ret ;------------------------------------------------------- ; console output of char in A register ;------------------------------------------------------- -putchr: - push h +putchr: push h push d push b - mov e,a - mvi c,conout + mov e,a + mvi c,conout call bdos pop b pop d @@ -67,29 +71,29 @@ putchr: putdec: push b push d push h - lxi b,-10 - lxi d,-1 + lxi b,-10 + lxi d,-1 putdec2: - dad b - inx d - jc putdec2 - lxi b,10 - dad b + dad b + inx d + jc putdec2 + lxi b,10 + dad b xchg - mov a,h - ora l - cnz putdec ; recursive call - mov a,e - adi '0' + mov a,h + ora l + cnz putdec ; recursive call + mov a,e + adi '0' call putchr pop h pop d pop b ret ;------------------------------------------------------- - ; message and data area + ; data area ;------------------------------------------------------- -signon: db 'First 20 Fibonacci numbers:',cr,lf,'$' +signon: db 'Fibonacci number sequence:',cr,lf,'$' oldstk: dw 0 stack equ $+128 ; 64-level stack ; diff --git a/Task/Fibonacci-sequence/Elena/fibonacci-sequence-2.elena b/Task/Fibonacci-sequence/Elena/fibonacci-sequence-2.elena index 56338fabc0..93b2a68afd 100644 --- a/Task/Fibonacci-sequence/Elena/fibonacci-sequence-2.elena +++ b/Task/Fibonacci-sequence/Elena/fibonacci-sequence-2.elena @@ -7,14 +7,14 @@ public FibonacciGenerator long n_2 := 1l; long n_1 := 1l; - yield:n_2; - yield:n_1; + $yield n_2; + $yield n_1; while(true) { long n := n_2 + n_1; - yield:n; + $yield n; n_2 := n_1; n_1 := n diff --git a/Task/Fibonacci-sequence/Grain/fibonacci-sequence-1.grain b/Task/Fibonacci-sequence/Grain/fibonacci-sequence-1.grain new file mode 100644 index 0000000000..2cd3a9a841 --- /dev/null +++ b/Task/Fibonacci-sequence/Grain/fibonacci-sequence-1.grain @@ -0,0 +1,11 @@ +import String from "string" +import File from "sys/file" +let rec fib = n => if (n < 2) { + n +} else { + fib(n - 1) + fib(n - 2) +} +for (let mut i = 0; i <= 20; i += 1) { + File.fdWrite(File.stdout, Pervasives.toString(fib(i))) + ignore(File.fdWrite(File.stdout, " ")) +} diff --git a/Task/Fibonacci-sequence/Grain/fibonacci-sequence-2.grain b/Task/Fibonacci-sequence/Grain/fibonacci-sequence-2.grain new file mode 100644 index 0000000000..d9b44e07d0 --- /dev/null +++ b/Task/Fibonacci-sequence/Grain/fibonacci-sequence-2.grain @@ -0,0 +1,17 @@ +import File from "sys/file" +let fib = j => { + let mut fnow = 0, fnext = 1 + for (let mut n = 0; n <= j; n += 1) { + if (n == 0 || n == 1) { + let output1 = " " ++ toString(n) + ignore(File.fdWrite(File.stdout, output1)) + } else { + let tempf = fnow + fnext + fnow = fnext + fnext = tempf + let output2 = " " ++ toString(fnext) + ignore(File.fdWrite(File.stdout, output2)) + } + } +} +fib(20) diff --git a/Task/Fibonacci-sequence/Grain/fibonacci-sequence-3.grain b/Task/Fibonacci-sequence/Grain/fibonacci-sequence-3.grain new file mode 100644 index 0000000000..34addceda3 --- /dev/null +++ b/Task/Fibonacci-sequence/Grain/fibonacci-sequence-3.grain @@ -0,0 +1,23 @@ +import Buffer from "buffer" +import String from "string" +let fib = j => { + // set-up minimal, growable buffer + let buf = Buffer.make(j * 2) + let mut fnow = 0, fnext = 1 + for (let mut n = 0; n <= j; n += 1) { + if (n == 0 || n == 1) { + Buffer.addChar(' ', buf) + Buffer.addString(toString(n), buf) + } else { + let tempf = fnow + fnext + fnow = fnext + fnext = tempf + Buffer.addChar(' ', buf) + Buffer.addString(toString(fnext), buf) + } + } + // stringify buffer and return + Buffer.toString(buf) +} +let output = fib(20) +print(output) diff --git a/Task/Find-common-directory-path/EasyLang/find-common-directory-path.easy b/Task/Find-common-directory-path/EasyLang/find-common-directory-path.easy new file mode 100644 index 0000000000..aff2a54e84 --- /dev/null +++ b/Task/Find-common-directory-path/EasyLang/find-common-directory-path.easy @@ -0,0 +1,18 @@ +func$ comdir path$[] . + for i = 1 to len path$[1] + c$ = substr path$[1] i 1 + for j = 2 to len path$[] + if c$ <> substr path$[j] i 1 + break 2 + . + . + if c$ = "/" + f = i - 1 + . + . + return substr path$[1] 1 f +. +a$[] &= "/home/user1/tmp/coverage/test" +a$[] &= "/home/user1/tmp/covert/operator" +a$[] &= "/home/user1/tmp/coven/members" +print comdir a$[] diff --git a/Task/Find-the-intersection-of-a-line-with-a-plane/EasyLang/find-the-intersection-of-a-line-with-a-plane.easy b/Task/Find-the-intersection-of-a-line-with-a-plane/EasyLang/find-the-intersection-of-a-line-with-a-plane.easy new file mode 100644 index 0000000000..9ece60947b --- /dev/null +++ b/Task/Find-the-intersection-of-a-line-with-a-plane/EasyLang/find-the-intersection-of-a-line-with-a-plane.easy @@ -0,0 +1,30 @@ +proc minus . l[] r[] res[] . + len res[] 3 + for i to 3 + res[i] = l[i] - r[i] + . +. +func dot l[] r[] . + for i to 3 + res += l[i] * r[i] + . + return res +. +proc scale f . l[] . + for i to 3 + l[i] = l[i] * f + . +. +proc inter_point rv[] rp[] pn[] pp[] . res[] . + minus rp[] pp[] dif[] + prd1 = dot dif[] pn[] + prd2 = dot rv[] pn[] + scale (prd1 / prd2) rv[] + minus rp[] rv[] res[] +. +rv[] = [ 0.0 -1.0 -1.0 ] +rp[] = [ 0.0 0.0 10.0 ] +pn[] = [ 0.0 0.0 1.0 ] +pp[] = [ 0.0 0.0 5.0 ] +inter_point rv[] rp[] pn[] pp[] res[] +print res[] diff --git a/Task/First-class-functions/Quackery/first-class-functions-1.quackery b/Task/First-class-functions/Quackery/first-class-functions-1.quackery new file mode 100644 index 0000000000..23afa7ac65 --- /dev/null +++ b/Task/First-class-functions/Quackery/first-class-functions-1.quackery @@ -0,0 +1,57 @@ + [ $ \ +try: + float(string_from_stack()) +except: + to_stack(False) +else: + to_stack(True) + \ python ] is isfloat ( $ --> b ) + + [ nextword + dup isfloat not if + [ $ '"f" needs to be followed by a number.' + message put bail ] + ' [ ' ] swap nested join + nested swap dip join ] builds f ( [ $ --> [ $ ) + + [ $ \ +import math +a = string_from_stack() +a = str(math.sin(float(a))) +string_to_stack(a) \ python ] is sin ( $ --> $ ) + + [ $ \ +import math +a = string_from_stack() +a = str(math.asin(float(a))) +string_to_stack(a) \ python ] is asin ( $ --> $ ) + + [ $ \ +import math +a = string_from_stack() +a = str(math.cos(float(a))) +string_to_stack(a) \ python ] is cos ( $ --> $ ) + + [ $ \ +import math +a = string_from_stack() +a = str(math.acos(float(a))) +string_to_stack(a) \ python ] is acos ( $ --> $ ) + + [ $ \ +a = string_from_stack() +b = string_from_stack() +c = str(float(b) * float(a)) +string_to_stack(c) \ python ] is f* ( $ $ --> $ ) + + [ $ \ +a = string_from_stack() +b = string_from_stack() +c = str(float(b) / float(a)) +string_to_stack(c) \ python ] is f/ ( $ $ --> $ ) + + [ $ \ +a = string_from_stack() +b = string_from_stack() +c = str(float(b) ** float(a)) +string_to_stack(c) \ python ] is f** ( $ $ --> $ ) diff --git a/Task/First-class-functions/Quackery/first-class-functions-2.quackery b/Task/First-class-functions/Quackery/first-class-functions-2.quackery new file mode 100644 index 0000000000..338f0e1ae7 --- /dev/null +++ b/Task/First-class-functions/Quackery/first-class-functions-2.quackery @@ -0,0 +1,24 @@ + [ dup dup f* f* ] is cubed ( $ --> $ ) + + [ f 1 f 3 f/ f** ] is cuberoot ( $ --> $ ) + + [ table sin cos cubed ] is A ( n --> [ ) + + [ table asin acos cuberoot ] is B ( n --> [ ) + + [ dip nested nested join ] is compose ( x x --> [ ) + + [ dup dip A B compose do ] is ->A->B-> ( f n --> f ) + + ' [ f 0.5 f 1.234567 ] + witheach + [ do 3 times + [ dup echo$ + say " -> " + i^ A echo + say " -> " + i^ B echo + say " -> " + dup i^ ->A->B-> echo$ + cr ] + drop cr ] diff --git a/Task/FizzBuzz/Q/fizzbuzz-1.q b/Task/FizzBuzz/Q/fizzbuzz-1.q new file mode 100644 index 0000000000..ddc5895375 --- /dev/null +++ b/Task/FizzBuzz/Q/fizzbuzz-1.q @@ -0,0 +1 @@ +{(2 sv not x mod/:5 3)'[;`fizz;`buzz;`fizzbuzz]`$string x} diff --git a/Task/FizzBuzz/Q/fizzbuzz-2.q b/Task/FizzBuzz/Q/fizzbuzz-2.q new file mode 100644 index 0000000000..0dc95fabd9 --- /dev/null +++ b/Task/FizzBuzz/Q/fizzbuzz-2.q @@ -0,0 +1,4 @@ +q)/ Fizzbuzz +q)fb:{(2 sv not x mod/:5 3)'[;`fizz;`buzz;`fizzbuzz]`$string x} +q)fb 1+til 20 +`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz diff --git a/Task/FizzBuzz/Q/fizzbuzz-3.q b/Task/FizzBuzz/Q/fizzbuzz-3.q new file mode 100644 index 0000000000..091461983f --- /dev/null +++ b/Task/FizzBuzz/Q/fizzbuzz-3.q @@ -0,0 +1,17 @@ +q)show x:1+til 20 +1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 +q)x mod/:5 3 +1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 +1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 +q)not x mod/:5 3 +00001000010000100001b +00100100100100100100b +q)show i:2 sv not x mod/:5 3 / binary decode +0 0 1 0 2 1 0 0 1 2 0 1 0 0 3 0 0 1 0 2 +q)(`$string x;`fizz;`buzz;`fizzbuzz) +`1`2`3`4`5`6`7`8`9`10`11`12`13`14`15`16`17`18`19`20 +`fizz +`buzz +`fizzbuzz +q)i'[`$string x;`fizz;`buzz;`fizzbuzz] / Case iterator +`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz diff --git a/Task/FizzBuzz/Q/fizzbuzz.q b/Task/FizzBuzz/Q/fizzbuzz.q deleted file mode 100644 index 5a5a222cf0..0000000000 --- a/Task/FizzBuzz/Q/fizzbuzz.q +++ /dev/null @@ -1,2 +0,0 @@ -q){(sum 1 2*0=x mod/:3 5)'[`$string x;`fizz;`buzz;`fizzbuzz]}1+til 20 -`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz diff --git a/Task/Floyds-triangle/Maxima/floyds-triangle.maxima b/Task/Floyds-triangle/Maxima/floyds-triangle.maxima new file mode 100644 index 0000000000..f1d435055e --- /dev/null +++ b/Task/Floyds-triangle/Maxima/floyds-triangle.maxima @@ -0,0 +1,10 @@ +floyd_t(m):=block( + t:m*(m+1)/2, + L1:makelist(makelist(k,k,1,t),j,0,m), + L2:makelist(rest(L1[i],((i-1)^2+(i-1))/2),i,1,m+1), + makelist(firstn(L2[i],i),i,1,m), + table_form(%%))$ + +/* Test cases */ +floyd_t(5); +floyd_t(14); diff --git a/Task/Formatted-numeric-output/Maxima/formatted-numeric-output.maxima b/Task/Formatted-numeric-output/Maxima/formatted-numeric-output.maxima new file mode 100644 index 0000000000..ce15bde002 --- /dev/null +++ b/Task/Formatted-numeric-output/Maxima/formatted-numeric-output.maxima @@ -0,0 +1 @@ +printf(false,"~9,3,,,'0F",7.125); diff --git a/Task/Formatted-numeric-output/Quackery/formatted-numeric-output.quackery b/Task/Formatted-numeric-output/Quackery/formatted-numeric-output.quackery new file mode 100644 index 0000000000..72672c61b4 --- /dev/null +++ b/Task/Formatted-numeric-output/Quackery/formatted-numeric-output.quackery @@ -0,0 +1,37 @@ + [ over find swap found ] is has ( $ c --> b ) + + [ over 0 peek + char - = iff + [ dip [ behead drop ] + true unrot ] + else [ false unrot ] + over char . swap find + - char 0 swap of + swap join + swap iff char - + else space + swap join ] is left-pad ( $ n --> $ ) + + [ over char . has not if + [ dip [ char . join ] ] + over char . swap find + dip [ over size ] + 1+ - - + char 0 swap of + join ] is right-pad ( $ n --> $ ) + + [ dip left-pad right-pad ] is format ( $ n n --> $ ) + + ' [ $ "7.125" + $ "-7.125" + $ "0.125" + $ "-0.12" + $ "7.12" + $ "-7.12" + $ "0.12" + $ "-0.12" + $ "7" + $ "-7" + $ "0" ] + witheach + [ do 5 3 format echo$ cr ] diff --git a/Task/Function-definition/Amazing-Hopper/function-definition.hopper b/Task/Function-definition/Amazing-Hopper/function-definition.hopper new file mode 100644 index 0000000000..fddd71f765 --- /dev/null +++ b/Task/Function-definition/Amazing-Hopper/function-definition.hopper @@ -0,0 +1,62 @@ +/* this need data into stack */ +#context Multiplication + mul + Return \\ +#synon Multiplication *getproduct + +#context-free anothermul + /* #defn Args(*) #GENCODE $$$*$$$ #REVLIST=0,mov(#REVLIST);#ENDGEN, */ + Args 'a,b' + Return ( #(a*b) )\\ +#synon anothermul *getanotherproduct + +#include + +#prototype _multiply(_X_,_Y_) +#synon __multiply Multiply + +Main + /* "prototipos" of functions and procedures. + Solves internaly */ + Printnl ( Multiply ( 10, 4 ) ) + Printnl ( __multiply ( 10, 4 ) ) + + /* definición alternativa 1 */ + Printnl ( Set' 10,4 ', Gosub ' Multiply2 ') + + /* aseembler Hopper 1 */ + {10,4} jsub( Multiply3 ), {"\n"} print + + /* assembler Hopper 2 */ + {10,4} jsub( Multiply4 ), {"\n"} print + + /* context */ + Set '10,4', now get product, and print with newline + + /* context-free */ + Set '10,4', and get another product; then print with newline + +End + +.locals /* Subrutines */ + +_multiply(a,b) +Return ( Mul(a,b) ) + +/* Define is macro. Others macros: Function, Procedure: +#defn Define(_F_,*) _F_:,#GENCODE $$$*$$$ #REVLIST=0;mov(#REVLIST);#ENDGEN; +#defn Function(_F_,*) _F_:,#GENCODE $$$*$$$ #REVLIST=0;mov(#REVLIST);#ENDGEN; +#defn Procedure(_F_,*) _F_:,#GENCODE $$$*$$$ #REVLIST=0;mov(#REVLIST);#ENDGEN; +*/ +Define 'Multiply2, a,b' +Return ( Mul(a,b) ) + +Multiply3: + b=0, mov(b), a=0, mov(a) + {a,b}mul /* result into stack */ +Return + +Multiply4: + mul /* get values from stack, + and put result into stack */ +back /* Return */ diff --git a/Task/Function-definition/Elena/function-definition-2.elena b/Task/Function-definition/Elena/function-definition-2.elena index 667f1dd0f2..e80091723d 100644 --- a/Task/Function-definition/Elena/function-definition-2.elena +++ b/Task/Function-definition/Elena/function-definition-2.elena @@ -1 +1 @@ -symbol f := (x,y => x * y); +symbol f = (x,y => x * y); diff --git a/Task/Function-definition/Zig/function-definition.zig b/Task/Function-definition/Zig/function-definition.zig new file mode 100644 index 0000000000..f67148e5cd --- /dev/null +++ b/Task/Function-definition/Zig/function-definition.zig @@ -0,0 +1,8 @@ +fun multiply(x: i64, y: i64) i64 { + return x * y; +} + +//example call +const x: i64 = 4; +const y: i64 = 23; +_ = multipy(x, y); // --> 93 diff --git a/Task/Generate-lower-case-ASCII-alphabet/Elena/generate-lower-case-ascii-alphabet.elena b/Task/Generate-lower-case-ASCII-alphabet/Elena/generate-lower-case-ascii-alphabet.elena index 5cb866a597..af85215e6c 100644 --- a/Task/Generate-lower-case-ASCII-alphabet/Elena/generate-lower-case-ascii-alphabet.elena +++ b/Task/Generate-lower-case-ASCII-alphabet/Elena/generate-lower-case-ascii-alphabet.elena @@ -7,7 +7,7 @@ singleton Alphabet : Enumerable { char current; - get() = current; + get Value() = current; bool next() { diff --git a/Task/Gotchas/C/gotchas-11.c b/Task/Gotchas/C/gotchas-11.c new file mode 100644 index 0000000000..8bd998e6a1 --- /dev/null +++ b/Task/Gotchas/C/gotchas-11.c @@ -0,0 +1,3 @@ +(let numbers [1 2 3 4] + maximum (max numbers)) ;should be (... max numbers) +(+ maximum 5) diff --git a/Task/Gotchas/C/gotchas-12.c b/Task/Gotchas/C/gotchas-12.c new file mode 100644 index 0000000000..f43e241d84 --- /dev/null +++ b/Task/Gotchas/C/gotchas-12.c @@ -0,0 +1,2 @@ +(mock + (fn a b ((unmocked +) a b 1))) +(+ 2 3) diff --git a/Task/Greatest-common-divisor/Hoon/greatest-common-divisor.hoon b/Task/Greatest-common-divisor/Hoon/greatest-common-divisor.hoon new file mode 100644 index 0000000000..effc940b78 --- /dev/null +++ b/Task/Greatest-common-divisor/Hoon/greatest-common-divisor.hoon @@ -0,0 +1,9 @@ +:: +:: Greatest common divisor (gcd), Euclid's algorithm. +:: +|= [a=@ud b=@ud] +^- @ud +?> (gth b 0) +?: =((mod a b) 0) + b +$(a b, b (mod a b)) diff --git a/Task/Greatest-element-of-a-list/Elena/greatest-element-of-a-list.elena b/Task/Greatest-element-of-a-list/Elena/greatest-element-of-a-list.elena index ac93225e37..7bc11c96f6 100644 --- a/Task/Greatest-element-of-a-list/Elena/greatest-element-of-a-list.elena +++ b/Task/Greatest-element-of-a-list/Elena/greatest-element-of-a-list.elena @@ -9,7 +9,7 @@ extension op object maximal := nil; while (en.next()) { - var item := en.get(); + var item := *en; if (nil == maximal) { maximal := item diff --git a/Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list.icon b/Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list-1.icon similarity index 100% rename from Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list.icon rename to Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list-1.icon diff --git a/Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list-2.icon b/Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list-2.icon new file mode 100644 index 0000000000..c9268e3bf2 --- /dev/null +++ b/Task/Greatest-element-of-a-list/Icon/greatest-element-of-a-list-2.icon @@ -0,0 +1,3 @@ +(max 1 2 3 4) +;or +(... max [1 2 3 4]) diff --git a/Task/Guess-the-number-With-feedback/Elena/guess-the-number-with-feedback.elena b/Task/Guess-the-number-With-feedback/Elena/guess-the-number-with-feedback.elena index f69d03615e..fce9ca9f72 100644 --- a/Task/Guess-the-number-With-feedback/Elena/guess-the-number-with-feedback.elena +++ b/Task/Guess-the-number-With-feedback/Elena/guess-the-number-with-feedback.elena @@ -2,7 +2,7 @@ import extensions; public program() { - int randomNumber := randomGenerator.eval(1,10); + int randomNumber := randomGenerator.nextInt(1,10); console.printLine("I'm thinking of a number between 1 and 10. Can you guess it?"); bool numberCorrect := false; until(numberCorrect) diff --git a/Task/Guess-the-number/Elena/guess-the-number.elena b/Task/Guess-the-number/Elena/guess-the-number.elena index d601dcdd2c..0ec50345a3 100644 --- a/Task/Guess-the-number/Elena/guess-the-number.elena +++ b/Task/Guess-the-number/Elena/guess-the-number.elena @@ -2,7 +2,7 @@ import extensions; public program() { - int randomNumber := randomGenerator.eval(1,10); + int randomNumber := randomGenerator.nextInt(1,10); console.printLine("I'm thinking of a number between 1 and 10. Can you guess it?"); bool numberCorrect := false; until(numberCorrect) diff --git a/Task/Harmonic-series/Maxima/harmonic-series.maxima b/Task/Harmonic-series/Maxima/harmonic-series.maxima new file mode 100644 index 0000000000..2cc5d0f540 --- /dev/null +++ b/Task/Harmonic-series/Maxima/harmonic-series.maxima @@ -0,0 +1,10 @@ +harmonic(n):=apply("+",1/makelist(i,i,n))$ + +first_greater_than_n(len):=block(i:1,result:[],while harmonic(i)<=len do (result:endcons(i,result),i:i+1),last(result)+1)$ + +/* Test cases */ +/* First 20 harmonic numbers */ +makelist(harmonic(j),j,20); + +/* First harmonic number that exceeds a positive integer from 1 to 5 */ +makelist(first_greater_than_n(k),k,5); diff --git a/Task/Harshad-or-Niven-series/Maxima/harshad-or-niven-series.maxima b/Task/Harshad-or-Niven-series/Maxima/harshad-or-niven-series.maxima new file mode 100644 index 0000000000..5cc54dc054 --- /dev/null +++ b/Task/Harshad-or-Niven-series/Maxima/harshad-or-niven-series.maxima @@ -0,0 +1,25 @@ +/* Function that returns a list of digits given a nonnegative integer */ +decompose(num) := block([digits, remainder], + digits: [], + while num > 0 do + (remainder: mod(num, 10), + digits: cons(remainder, digits), + num: floor(num/10)), + digits +)$ + +/* Function that returns a list of the first len Harshad numbers */ +harshad_count(len):=block( + [i:1,count:0,result:[]], + while count0,0 |U->0,1 |D->0,-1 |L-> -1,0 |R->1,0 +let fC=function At->[fD D;fD R;fD U] |Cl->[fD R;fD D;fD L] |Ab->[fD U;fD L;fD D] |Cr->[fD L;fD U;fD R] +let order(n,g)=match g with At->[n,Cl;D,At;R,At;U,Cr] + |Cl->[n,At;R,Cl;D,Cl;L,Ab] + |Ab->[n,Cr;U,Ab;L,Ab;D,Cl] + |Cr->[n,Ab;L,Cr;U,Cr;R,At] +let hilbert=Seq.unfold(fun n->Some(n,n|>List.collect order))[Z,At] +hilbert|>Seq.take 7|>Seq.iteri(fun n g->Chart.Line(g|>Seq.collect(fun(n,g)->(fD n)::(fC g))|>Seq.scan(fun(x,y)(n,g)->(x+n,y+g))(0,0))|>Chart.withTitle(sprintf "Hilbert order %d" n)|>Chart.show) diff --git a/Task/Home-primes/Ruby/home-primes.rb b/Task/Home-primes/Ruby/home-primes.rb new file mode 100644 index 0000000000..de0816bd7e --- /dev/null +++ b/Task/Home-primes/Ruby/home-primes.rb @@ -0,0 +1,18 @@ +require 'prime' + +def concat(n) + n.prime_division.map{|pr, exp| pr.to_s * exp }.join.to_i +end + +def hp(n) + res = [n] + res << n = concat(n) until n.prime? + res +end + +def hp_to_s(ar) + return "HP#{ar[0]}(1) = #{ar[0]}" if ar.size == 1 + ar[0..-2].map.with_index(1){|n, i| "HP#{n}(#{(ar.size-i)}) = "}.join + ar.last.to_s +end + +(2..20).each {|n| puts hp_to_s(hp(n)) } diff --git a/Task/Identity-matrix/Amazing-Hopper/identity-matrix.hopper b/Task/Identity-matrix/Amazing-Hopper/identity-matrix.hopper new file mode 100644 index 0000000000..71c3a4df34 --- /dev/null +++ b/Task/Identity-matrix/Amazing-Hopper/identity-matrix.hopper @@ -0,0 +1,19 @@ +#include + +Main + Dim( 10,10 ) as eyes 'UMatrix' + + Printnl ' "UNIT MATRIX:\n", UMatrix ' + + /* Classical method */ + + Dim (10,10) as zeros (ZM) + i=1 + Iterator ( ++i, #(i<=10), #( ZM[i,i]=1 ) ) + Printnl ' "UNIT MATRIX:\n", ZM ' + + /* unit matrix non square*/ + Dim ( 5,8 ) as eyes 'rare unit matrix' + + Printnl ' "RARE UNIT MATRIX:\n", rare unit matrix ' +End diff --git a/Task/Identity-matrix/EasyLang/identity-matrix.easy b/Task/Identity-matrix/EasyLang/identity-matrix.easy new file mode 100644 index 0000000000..d1552ef970 --- /dev/null +++ b/Task/Identity-matrix/EasyLang/identity-matrix.easy @@ -0,0 +1,9 @@ +proc idmat lng . mat[][] . + len mat[][] lng + for i to lng + len mat[i][] lng + mat[i][i] = 1 + . +. +idmat 4 m[][] +print m[][] diff --git a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/8080-Assembly/idiomatically-determine-all-the-lowercase-and-uppercase-letters.8080 b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/8080-Assembly/idiomatically-determine-all-the-lowercase-and-uppercase-letters.8080 new file mode 100644 index 0000000000..57af11d0de --- /dev/null +++ b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/8080-Assembly/idiomatically-determine-all-the-lowercase-and-uppercase-letters.8080 @@ -0,0 +1,94 @@ + ;------------------------------------------------------ + ; useful equates + ;------------------------------------------------------ +bdos equ 5h ; BDOS entry +wboot equ 0 ; BDOS warm boot function +conout equ 2 ; BDOS write character to console function +prtstr equ 9 ; BDOS write string to console function +cr equ 13 ; ASCII carriage return +lf equ 10 ; ASCII line feed + ;------------------------------------------------------ + ; main code begins here + ;------------------------------------------------------ + org 100h ; entry point under CP/M + lxi sp,stack ; set a local stack + ; + ; show upper case alphabet + ; + lxi d,ucmsg + call message + mvi a,'A' +ucloop: push a + call putchr + pop a + inr a + cpi 'Z'+1 + jc ucloop + call crlf + ; + ; show lower case alphabet + ; + lxi d,lcmsg + call message + mvi a,'a' +lcloop: push a + call putchr + pop a + inr a + cpi 'z'+1 + jc lcloop + call crlf + ; + ; we're finished; exit to operating system + ; + jmp wboot + ;------------------------------------------------------- + ; console output of $-terminated string pointed to by DE + ;------------------------------------------------------- +message: + push b + push d + push h + mvi c,prtstr + call bdos + pop h + pop d + pop b + ret + ;------------------------------------------------------- + ; output CRLF to console + ;------------------------------------------------------- +crlf: push b + push d + push h + mvi e,cr + mvi c,conout + call bdos + mvi e,lf + mvi c,conout + call bdos + pop h + pop d + pop b + ret + ;------------------------------------------------------- + ; console output of char in A register + ;------------------------------------------------------- +putchr: push b + push d + push h + mov e,a + mvi c,conout + call bdos + pop h + pop d + pop b + ret + ;------------------------------------------------------ + ; messages and data area + ;------------------------------------------------------ +ucmsg: db 'Upper case: $' +lcmsg: db 'Lower case: $' +stack equ $+128 ; 64-level stack is sufficient + ; + end diff --git a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/EasyLang/idiomatically-determine-all-the-lowercase-and-uppercase-letters.easy b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/EasyLang/idiomatically-determine-all-the-lowercase-and-uppercase-letters.easy new file mode 100644 index 0000000000..aca86fb76f --- /dev/null +++ b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/EasyLang/idiomatically-determine-all-the-lowercase-and-uppercase-letters.easy @@ -0,0 +1,7 @@ +for i = strcode "a" to strcode "z" + write strchar i +. +print "" +for i = strcode "A" to strcode "Z" + write strchar i +. diff --git a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Haskell/idiomatically-determine-all-the-lowercase-and-uppercase-letters-3.hs b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Haskell/idiomatically-determine-all-the-lowercase-and-uppercase-letters-3.hs new file mode 100644 index 0000000000..164ce4f353 --- /dev/null +++ b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Haskell/idiomatically-determine-all-the-lowercase-and-uppercase-letters-3.hs @@ -0,0 +1,4 @@ +(let chars-between (comp range (map char-code) (... str))) + +(str "Upper-case: " (chars-between 65 91) " +Lower-case: " (chars-between 97 123)) diff --git a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Haskell/idiomatically-determine-all-the-lowercase-and-uppercase-letters-4.hs b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Haskell/idiomatically-determine-all-the-lowercase-and-uppercase-letters-4.hs new file mode 100644 index 0000000000..5db1667a8e --- /dev/null +++ b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Haskell/idiomatically-determine-all-the-lowercase-and-uppercase-letters-4.hs @@ -0,0 +1,4 @@ +(let ascii (map char-code (range 127))) + +(.. str "Upper-case: " (filter upper? ascii) " +Lower-case: " (filter lower? ascii)) diff --git a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Maxima/idiomatically-determine-all-the-lowercase-and-uppercase-letters.maxima b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Maxima/idiomatically-determine-all-the-lowercase-and-uppercase-letters.maxima new file mode 100644 index 0000000000..0079bab024 --- /dev/null +++ b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/Maxima/idiomatically-determine-all-the-lowercase-and-uppercase-letters.maxima @@ -0,0 +1,2 @@ +sublist(makelist(unicode(i),i,0,127),lowercasep); +sublist(makelist(unicode(i),i,0,127),uppercasep); diff --git a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/S-BASIC/idiomatically-determine-all-the-lowercase-and-uppercase-letters.basic b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/S-BASIC/idiomatically-determine-all-the-lowercase-and-uppercase-letters.basic index d6d58203ab..fe34551ab3 100644 --- a/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/S-BASIC/idiomatically-determine-all-the-lowercase-and-uppercase-letters.basic +++ b/Task/Idiomatically-determine-all-the-lowercase-and-uppercase-letters/S-BASIC/idiomatically-determine-all-the-lowercase-and-uppercase-letters.basic @@ -1,8 +1,3 @@ -comment - An S-BASIC solution to the Rosetta Code task calling for - an idiomatic generation of upper and lower case alphabets. -end - var c = byte print "Upper Case: "; for c = 'A' to 'Z' diff --git a/Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string.bracmat b/Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string-1.bracmat similarity index 100% rename from Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string.bracmat rename to Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string-1.bracmat diff --git a/Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string-2.bracmat b/Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string-2.bracmat new file mode 100644 index 0000000000..da782b3e7b --- /dev/null +++ b/Task/Increment-a-numerical-string/Bracmat/increment-a-numerical-string-2.bracmat @@ -0,0 +1 @@ +(new$(UFP,(=(s.val).!val+1)).go)$"0.234e0" diff --git a/Task/Jacobsthal-numbers/Maxima/jacobsthal-numbers.maxima b/Task/Jacobsthal-numbers/Maxima/jacobsthal-numbers.maxima new file mode 100644 index 0000000000..b1f4a3466e --- /dev/null +++ b/Task/Jacobsthal-numbers/Maxima/jacobsthal-numbers.maxima @@ -0,0 +1,17 @@ +jacobstahl(n):=(2^n-(-1)^n)/3$ + +jacobstahl_lucas(n):=2^n+(-1)^n$ + +jacobstahl_oblong(n):=jacobstahl(n)*jacobstahl(n+1)$ + +/* Function that returns a list of the first len jacobstahl primes */ +jacobstahl_primes_count(len):=block( + [i:0,count:0,result:[]], + while count #include -constexpr int64_t LIMIT = pow(2, 53); +constexpr int64_t LIMIT = static_cast(1) << 53; std::set jordan_polya_set; std::unordered_map> decompositions; diff --git a/Task/Jordan-P-lya-numbers/EasyLang/jordan-p-lya-numbers.easy b/Task/Jordan-P-lya-numbers/EasyLang/jordan-p-lya-numbers.easy new file mode 100644 index 0000000000..41b173f05f --- /dev/null +++ b/Task/Jordan-P-lya-numbers/EasyLang/jordan-p-lya-numbers.easy @@ -0,0 +1,50 @@ +fastfunc jpnum m . + n = m + limite = 7 + while 1 = 1 + fac = 1 + i = 1 + while i < limite + i += 1 + fac *= i + . + repeat + q = n div fac + if n mod fac = 0 + if q = 1 + return 1 + . + n = q + else + fac = fac / i + i -= 1 + . + until i = 1 + . + limite -= 1 + if limite = 0 + return 0 + . + n = m + . +. +numfmt 0 5 +write 1 +c = 1 +n = 2 +repeat + if jpnum n = 1 + c += 1 + if c <= 50 + write n + if c mod 10 = 0 + print "" + . + . + sn = n + . + n += 2 + until n >= 1e8 +. +print "" +print "The largest Jordan-Polya number before 100 million: " & sn diff --git a/Task/Lah-numbers/EasyLang/lah-numbers.easy b/Task/Lah-numbers/EasyLang/lah-numbers.easy new file mode 100644 index 0000000000..1fe94e7245 --- /dev/null +++ b/Task/Lah-numbers/EasyLang/lah-numbers.easy @@ -0,0 +1,16 @@ +func fac n . + r = 1 + for i = 2 to n + r *= i + . + return r +. +print 0 +print "0 1" +for n = 2 to 12 + write 0 & " " & fac n & " " + for k = 2 to n - 1 + write fac n * fac (n - 1) / (fac k * fac (k - 1)) / fac (n - k) & " " + . + print 1 & " " +. diff --git a/Task/Lah-numbers/Maxima/lah-numbers-1.maxima b/Task/Lah-numbers/Maxima/lah-numbers-1.maxima new file mode 100644 index 0000000000..d5bb36bb6e --- /dev/null +++ b/Task/Lah-numbers/Maxima/lah-numbers-1.maxima @@ -0,0 +1,5 @@ +/* Function that returns a row of Lah triangle */ +lah(n):=append([0],makelist((binomial(n,k)*(n-1)!)/(k-1)!,k,1,n))$ + +/* Test cases */ +block(makelist(lah(i),i,0,12),table_form(%%)); diff --git a/Task/Lah-numbers/Maxima/lah-numbers-2.maxima b/Task/Lah-numbers/Maxima/lah-numbers-2.maxima new file mode 100644 index 0000000000..d3f6ad0f1c --- /dev/null +++ b/Task/Lah-numbers/Maxima/lah-numbers-2.maxima @@ -0,0 +1 @@ +lmax(lah(100)); diff --git a/Task/Largest-proper-divisor-of-n/Maxima/largest-proper-divisor-of-n.maxima b/Task/Largest-proper-divisor-of-n/Maxima/largest-proper-divisor-of-n.maxima new file mode 100644 index 0000000000..36a0d8e99e --- /dev/null +++ b/Task/Largest-proper-divisor-of-n/Maxima/largest-proper-divisor-of-n.maxima @@ -0,0 +1,3 @@ +lpd(n):=if n=1 then 1 else listify(divisors(n))[length(divisors(n))-1]$ + +makelist(lpd(i),i,100); diff --git a/Task/Left-factorials/Maxima/left-factorials.maxima b/Task/Left-factorials/Maxima/left-factorials.maxima new file mode 100644 index 0000000000..b1cd494970 --- /dev/null +++ b/Task/Left-factorials/Maxima/left-factorials.maxima @@ -0,0 +1,6 @@ +l_factorial(n):=sum(k!,k,0,n-1)$ + +/* Test cases */ +makelist(l_factorial(i),i,0,10); + +makelist(l_factorial(i),i,20,110,10); diff --git a/Task/Letter-frequency/EasyLang/letter-frequency.easy b/Task/Letter-frequency/EasyLang/letter-frequency.easy new file mode 100644 index 0000000000..264e5722eb --- /dev/null +++ b/Task/Letter-frequency/EasyLang/letter-frequency.easy @@ -0,0 +1,23 @@ +len d[] 26 +repeat + s$ = input + until s$ = "" + for c$ in strchars s$ + c = strcode c$ + if c >= 97 and c <= 122 + c -= 32 + . + if c >= 65 and c <= 91 + d[c - 64] += 1 + . + . +. +for i to 26 + write strchar (96 + i) & ": " + print d[i] +. +input_data +Open a text file and count the occurrences of each letter. +Some of these programs count all characters (including +punctuation), but some only count letters A to Z. +Other tasks related to string operations: diff --git a/Task/Levenshtein-distance/EasyLang/levenshtein-distance.easy b/Task/Levenshtein-distance/EasyLang/levenshtein-distance.easy new file mode 100644 index 0000000000..9d296f2856 --- /dev/null +++ b/Task/Levenshtein-distance/EasyLang/levenshtein-distance.easy @@ -0,0 +1,21 @@ +func dist s1$ s2$ . + if len s1$ = 0 + return len s2$ + . + if len s2$ = 0 + return len s1$ + . + c1$ = substr s1$ 1 1 + c2$ = substr s2$ 1 1 + s1rest$ = substr s1$ 2 len s1$ + s2rest$ = substr s2$ 2 len s2$ + # + if c1$ = c2$ + return dist s1rest$ s2rest$ + . + min = lower dist s1rest$ s2rest$ dist s1$ s2rest$ + min = lower min dist s1rest$ s2rest$ + return min + 1 +. +print dist "kitten" "sitting" +print dist "rosettacode" "raisethysword" diff --git a/Task/List-comprehensions/Insitux/list-comprehensions.insitux b/Task/List-comprehensions/Insitux/list-comprehensions.insitux new file mode 100644 index 0000000000..eb1b578420 --- /dev/null +++ b/Task/List-comprehensions/Insitux/list-comprehensions.insitux @@ -0,0 +1,10 @@ +(function pythagorean-triples n + (let n+1 (inc n)) + (for x (range 1 n+1) + y (range x n+1) + z (range y n+1) + (unless (= (+ (* x x) (* y y)) (* z z)) + (continue)) + [x y z])) + +(pythagorean-triples 20) diff --git a/Task/Literals-Floating-point/Quackery/literals-floating-point.quackery b/Task/Literals-Floating-point/Quackery/literals-floating-point.quackery new file mode 100644 index 0000000000..862106ebfb --- /dev/null +++ b/Task/Literals-Floating-point/Quackery/literals-floating-point.quackery @@ -0,0 +1,21 @@ + [ $ \ +try: + float(string_from_stack()) +except: + to_stack(False) +else: + to_stack(True) + \ python ] is isfloat ( $ --> b ) + + [ nextword + dup isfloat not if + [ $ '"f" needs to be followed by a number.' + message put bail ] + ' [ ' ] swap nested join + nested swap dip join ] builds f ( [ $ --> [ $ ) + + [ $ \ +import math +a = string_from_stack() +a = str(math.sin(float(a))) +string_to_stack(a) \ python ] is sin ( $ --> $ ) diff --git a/Task/Literals-Integer/Icon/literals-integer.icon b/Task/Literals-Integer/Icon/literals-integer-1.icon similarity index 100% rename from Task/Literals-Integer/Icon/literals-integer.icon rename to Task/Literals-Integer/Icon/literals-integer-1.icon diff --git a/Task/Literals-Integer/Icon/literals-integer-2.icon b/Task/Literals-Integer/Icon/literals-integer-2.icon new file mode 100644 index 0000000000..940a272cfe --- /dev/null +++ b/Task/Literals-Integer/Icon/literals-integer-2.icon @@ -0,0 +1 @@ +[123 0x7F 0xFFF 0b0101001] diff --git a/Task/Logical-operations/Icon/logical-operations.icon b/Task/Logical-operations/Icon/logical-operations-1.icon similarity index 100% rename from Task/Logical-operations/Icon/logical-operations.icon rename to Task/Logical-operations/Icon/logical-operations-1.icon diff --git a/Task/Logical-operations/Icon/logical-operations-2.icon b/Task/Logical-operations/Icon/logical-operations-2.icon new file mode 100644 index 0000000000..8db702805c --- /dev/null +++ b/Task/Logical-operations/Icon/logical-operations-2.icon @@ -0,0 +1,11 @@ +(let pad (comp str (pad-right " " 10))) + +(print "a b | (and a b) (or a b) (not a) (xor a b)") +(print (str* "-" 20) "+" (str* "-" 40)) + +(join "\n" + (for a [false :a] + b [false :b] + (... str (pad a) (pad b) "| " + (for op [and or not xor] + (pad (if (= op not) (op a) (op a b))))))) diff --git a/Task/Long-primes/Maxima/long-primes.maxima b/Task/Long-primes/Maxima/long-primes.maxima new file mode 100644 index 0000000000..c58b4697ac --- /dev/null +++ b/Task/Long-primes/Maxima/long-primes.maxima @@ -0,0 +1,13 @@ +/* Test cases */ +/* Long primes up to 500 */ +sublist(makelist(i,i,500),lambda([x],primep(x) and zn_order(10,x)=x-1)); + +/* Number of long primes up to a specified limit */ +length(sublist(makelist(i,i,500),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,1000),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,2000),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,4000),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,8000),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,16000),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,32000),lambda([x],primep(x) and zn_order(10,x)=x-1))); +length(sublist(makelist(i,i,64000),lambda([x],primep(x) and zn_order(10,x)=x-1))); diff --git a/Task/Longest-common-substring/EasyLang/longest-common-substring.easy b/Task/Longest-common-substring/EasyLang/longest-common-substring.easy new file mode 100644 index 0000000000..6a31753188 --- /dev/null +++ b/Task/Longest-common-substring/EasyLang/longest-common-substring.easy @@ -0,0 +1,23 @@ +func$ lcs a$ b$ . + if a$ = "" or b$ = "" + return "" + . + while b$ <> "" + for j = len b$ downto 1 + l$ = substr b$ 1 j + for k = 1 to len a$ - j + 1 + if substr a$ k j = l$ + if len l$ > len max$ + max$ = l$ + . + break 2 + . + . + . + b$ = substr b$ 2 -1 + . + return max$ +. +print lcs "thisisatest" "testing123testing" +print lcs "thisisatest" "stesting123testing" +print lcs "thisisatestxestinoo" "xxtesting123testing" diff --git a/Task/Loops-Break/Amazing-Hopper/loops-break-1.hopper b/Task/Loops-Break/Amazing-Hopper/loops-break-1.hopper new file mode 100644 index 0000000000..caa6f73d5e --- /dev/null +++ b/Task/Loops-Break/Amazing-Hopper/loops-break-1.hopper @@ -0,0 +1,9 @@ +#include + +Main + Loop + Break if ' Int rand(20) ---show--- Is equal to (10) ' + Printnl ( "--", Int rand(20) ) + Back + Print '"\nEnd of Loop\n" ' +End diff --git a/Task/Loops-Break/Amazing-Hopper/loops-break-2.hopper b/Task/Loops-Break/Amazing-Hopper/loops-break-2.hopper new file mode 100644 index 0000000000..e174af2711 --- /dev/null +++ b/Task/Loops-Break/Amazing-Hopper/loops-break-2.hopper @@ -0,0 +1,8 @@ +main: +____CODE_JUMP____997416047:, +;{20};rand;int;show;eqto(10);jt(____CODE_JUMP____803885359) + +{"--"};{20};rand;int;{"\n"}print; +,jmp(____CODE_JUMP____997416047),____CODE_JUMP____803885359:, +{"\nEnd of Loop\n"};print; +emptystack?do{{0}};return diff --git a/Task/Loops-Break/Icon/loops-break-3.icon b/Task/Loops-Break/Icon/loops-break-3.icon new file mode 100644 index 0000000000..08897e950a --- /dev/null +++ b/Task/Loops-Break/Icon/loops-break-3.icon @@ -0,0 +1,3 @@ +(while true + (print (let x (rand-int 0 20))) + (when (= x 10) (break))) diff --git a/Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step.icon b/Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step-1.icon similarity index 100% rename from Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step.icon rename to Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step-1.icon diff --git a/Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step-2.icon b/Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step-2.icon new file mode 100644 index 0000000000..97c579fb4b --- /dev/null +++ b/Task/Loops-For-with-a-specified-step/Icon/loops-for-with-a-specified-step-2.icon @@ -0,0 +1,7 @@ +(for i (range 0 10 2) + (print i) + (continue)) + +;or +(loop 5 i + (print (* i 2))) diff --git a/Task/Loops-Foreach/Amazing-Hopper/loops-foreach.hopper b/Task/Loops-Foreach/Amazing-Hopper/loops-foreach.hopper new file mode 100644 index 0000000000..7ce7587a44 --- /dev/null +++ b/Task/Loops-Foreach/Amazing-Hopper/loops-foreach.hopper @@ -0,0 +1,17 @@ +#include + +Main + things = {}, len list=0 + Set ' 100,200,300,"Hello world!", -3,-2,-1 ' Apndlist 'things' + Let ' len list := Length(things) ' + + Printnl ' "\nNormal count:\n" ' + For each( n, things, len list ) + Printnl ' "Thing : ", n ' + Next + + Printnl ' "\n\nReverse count:\n" ' + For each reverse ( n, things, len list ) + Printnl ' "Thing : ", n ' + Next +End diff --git a/Task/Loops-Increment-loop-index-within-loop-body/Amazing-Hopper/loops-increment-loop-index-within-loop-body.hopper b/Task/Loops-Increment-loop-index-within-loop-body/Amazing-Hopper/loops-increment-loop-index-within-loop-body.hopper new file mode 100644 index 0000000000..3bd5496f17 --- /dev/null +++ b/Task/Loops-Increment-loop-index-within-loop-body/Amazing-Hopper/loops-increment-loop-index-within-loop-body.hopper @@ -0,0 +1,13 @@ +#include +Main + Set break + Set decimal '0' + i=42, c=0 + Loop if ( #(c<42) ) + Set 'i', When ( Is prime? ){ + ++c, Printnl( "n = ", c,"\t",Just right(20,Money(0,i) ) ) + #( i += (i - 1) ) + } + ++i + Back +End diff --git a/Task/Loops-Increment-loop-index-within-loop-body/EasyLang/loops-increment-loop-index-within-loop-body.easy b/Task/Loops-Increment-loop-index-within-loop-body/EasyLang/loops-increment-loop-index-within-loop-body.easy new file mode 100644 index 0000000000..210317dd18 --- /dev/null +++ b/Task/Loops-Increment-loop-index-within-loop-body/EasyLang/loops-increment-loop-index-within-loop-body.easy @@ -0,0 +1,25 @@ +fastfunc isprim num . + if num mod 2 = 0 and num > 2 + return 0 + . + i = 3 + while i <= sqrt num + if num mod i = 0 + return 0 + . + i += 2 + . + return 1 +. +counter = 0 +maxnum = pow 2 53 +for i = 42 to maxnum + if isprim i = 1 + counter += 1 + print "n=" & counter & " " & i + if counter >= 42 + break 1 + . + i += i - 1 + . +. diff --git a/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-1.quackery b/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-1.quackery new file mode 100644 index 0000000000..994ed42403 --- /dev/null +++ b/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-1.quackery @@ -0,0 +1,22 @@ + [ stack ] is f.action ( --> s ) + [ stack ] is f.end ( --> s ) + [ stack ] is f.incr ( --> s ) + [ stack ] is f.index ( --> s ) + + [ ' [ f.action f.end + f.incr f.index ] ] is f.stacks ( --> [ ) + + [ f.index share ] is index ( --> n ) + + [ f.incr replace ] is incr ( n --> ) + + [ true f.end replace ] is end ( b --> ) + + [ 1 false ]'[ + f.stacks witheach put + [ f.action share do + f.incr share + f.index tally + 1 incr + f.end share until ] + f.stacks witheach release ] is from ( n --> ) diff --git a/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-2.quackery b/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-2.quackery new file mode 100644 index 0000000000..385973b60c --- /dev/null +++ b/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-2.quackery @@ -0,0 +1,19 @@ + [ $ "" swap + number$ reverse + [ dup size 3 > while + 3 split + dip join + dip [ char , join ] + again ] + join reverse echo$ ] is echo, ( n --> ) + + 0 + 42 from + [ index prime if + [ 1+ + dup echo + say ": " + index echo, cr + index 1+ incr ] + dup 42 = if end ] + drop diff --git a/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-3.quackery b/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-3.quackery new file mode 100644 index 0000000000..7abbb21118 --- /dev/null +++ b/Task/Loops-Increment-loop-index-within-loop-body/Quackery/loops-increment-loop-index-within-loop-body-3.quackery @@ -0,0 +1,10 @@ + 0 42 + [ dup prime if + [ dip 1+ + over echo + say ": " + dup echo, cr + dup + ] + 1+ + over 42 = until ] + 2drop diff --git a/Task/Loops-Increment-loop-index-within-loop-body/Zig/loops-increment-loop-index-within-loop-body.zig b/Task/Loops-Increment-loop-index-within-loop-body/Zig/loops-increment-loop-index-within-loop-body.zig new file mode 100644 index 0000000000..0972dabf1a --- /dev/null +++ b/Task/Loops-Increment-loop-index-within-loop-body/Zig/loops-increment-loop-index-within-loop-body.zig @@ -0,0 +1,25 @@ +const std = @import("std"); + + pub fn isPrime(n: i64) bool { + if (@mod(n, 2) == 0) return n == 2; + if (@mod(n, 3) == 0) return n == 3; + var d: i64 = 5; + while (d * d <= n) { + if (@mod(n, d) == 0) return false; + d += 2; + if (@mod(n, d) == 0) return false; + d += 4; + } + return true; + } + pub fn main() !void { + var i: i64 = 42; + var n: i64 = 0; + while (n < 42) : (i += 1) { + if (isPrime(i)) { + n += 1; + std.debug.print("n = {d}\t{d}\n", .{ n, i }); + i += i - 1; + } + } + } diff --git a/Task/Loops-N-plus-one-half/Amazing-Hopper/loops-n-plus-one-half.hopper b/Task/Loops-N-plus-one-half/Amazing-Hopper/loops-n-plus-one-half.hopper new file mode 100644 index 0000000000..8e42506084 --- /dev/null +++ b/Task/Loops-N-plus-one-half/Amazing-Hopper/loops-n-plus-one-half.hopper @@ -0,0 +1,41 @@ +#include + +Main + i=1 + Loop if ' Less equal (i,10)' + Set 'i', Print if ( #(i<10), ",","") + ++i + Back + Prnl + Loop for ( i=1, #(i<=10), ++i ) + Set 'i', Print only if ( #(10-i), ",") + Next + Prnl + i=1 + Loop + Set 'i', Print only if ( #(10-i), ",") + ++i + While ' #(i<=10) ' + Prnl + i=1 + Loop + Set 'i', Print only if ( #(10-i), ",") + ++i + Until ' #(i>10) ' + Prnl + i=1 + Loop + Set 'i', and print it + Break if '#( !(10-i) )' + Set '","' + ++i + Back + Prnl + + /* assembler Hopper */ + i=1 + loop single: + {i,10,i} sub, do{{","}}, print + ++i, {i,11}, jneq(loop single) + puts("\n") +End diff --git a/Task/Loops-Nested/Amazing-Hopper/loops-nested.hopper b/Task/Loops-Nested/Amazing-Hopper/loops-nested.hopper new file mode 100644 index 0000000000..93ebbbdffb --- /dev/null +++ b/Task/Loops-Nested/Amazing-Hopper/loops-nested.hopper @@ -0,0 +1,23 @@ +#include + +#define DIMS 10 +Main + Unset decimal + Dim (DIMS,DIMS) as ceil rand (20,t) + + Set decimal '0' + Printnl ("ORIGINAL MATRIX:\n", Just right (3, Str(t)), "\n") + + aux=0 + Loop for ( i=1, #(i<=DIMS && aux<>20 ), ++i) + Loop for ( j=1, #(j<=DIMS), ++j) + When ( Equals ( 20, [i,j] Get 't' ---Copy to 'aux'---) ) { Break } + /* + Also: When( #( ((aux:= (t[i,j])) == 20) ) ) { Break } + */ + Just right (3, Str(aux)), Print only if ( #(DIMS-j), "," ) + Next + Prnl + Next + Printnl ("\nFOUNDED: ", i,",",j," = ",aux) +End diff --git a/Task/Loops-While/Amazing-Hopper/loops-while-1.hopper b/Task/Loops-While/Amazing-Hopper/loops-while-1.hopper new file mode 100644 index 0000000000..2d605e167a --- /dev/null +++ b/Task/Loops-While/Amazing-Hopper/loops-while-1.hopper @@ -0,0 +1,9 @@ +#include + +Main + i=1024 + Loop + Printnl 'i' + i \= 2 + Back if 'i' is positive +End diff --git a/Task/Loops-While/Amazing-Hopper/loops-while-2.hopper b/Task/Loops-While/Amazing-Hopper/loops-while-2.hopper new file mode 100644 index 0000000000..e165ba0530 --- /dev/null +++ b/Task/Loops-While/Amazing-Hopper/loops-while-2.hopper @@ -0,0 +1,7 @@ +main: +i=1024 +____CODE_JUMP____883612951:, +{i};{"\n"}print; +i\=2 +{i},jpos(____CODE_JUMP____883612951),____CODE_JUMP____854411479:, +emptystack?do{{0}};return diff --git a/Task/Loops-While/Inform-7/loops-while.inf b/Task/Loops-While/Inform-7/loops-while-1.inf similarity index 100% rename from Task/Loops-While/Inform-7/loops-while.inf rename to Task/Loops-While/Inform-7/loops-while-1.inf diff --git a/Task/Loops-While/Inform-7/loops-while-2.inf b/Task/Loops-While/Inform-7/loops-while-2.inf new file mode 100644 index 0000000000..041bd8a1a7 --- /dev/null +++ b/Task/Loops-While/Inform-7/loops-while-2.inf @@ -0,0 +1,5 @@ +(var i 1024) + +(while (> i 1) + (print i) + (var i (// i 2))) diff --git a/Task/Loops-With-multiple-ranges/Amazing-Hopper/loops-with-multiple-ranges.hopper b/Task/Loops-With-multiple-ranges/Amazing-Hopper/loops-with-multiple-ranges.hopper new file mode 100644 index 0000000000..13aad4901b --- /dev/null +++ b/Task/Loops-With-multiple-ranges/Amazing-Hopper/loops-with-multiple-ranges.hopper @@ -0,0 +1,28 @@ +#include + +Main + prod=1, sum=0, x=5, y=-5,z=-2,one=1, three=3, seven=7, j=0 + Set decimal '0' + + Let ' j := Neg(three) ' + Iterator( j+=three, Less equal( j, Pow(3,3) ), Set 'j'; Gosub(Body) ) + Let ' j := Neg(seven) ' + Iterator( j+=x, Less equal( j, seven ), Set 'j'; Gosub(Body) ) + j=555, Iterator( ++j, Less equal( j, Add(550,y) ), Set 'j'; Gosub(Body) ) + j=22, Iterator( j-=three, Greater equal( j, -28 ), Set 'j'; Gosub(Body) ) + j=x, Iterator( j+=z, Greater equal( j, y ), Set 'j'; Gosub(Body) ) + j=1927, Iterator( ++j, Less equal( j, 1939 ), Set 'j'; Gosub(Body) ) + Let ' j := Pow(11,x)' + Iterator( ++j, Less equal( j, Add( Pow(11,x),one) ), Set 'j'; Gosub(Body) ) + + Printnl ( "SUM = ", sum, "\nPROD = ",prod ) +End + +Subrutines + +Define ' Body, j ' + Let( sum := Add(sum, Abs(j) ) ) + When ( Less ( Abs(prod), Pow(2,27) ) And (Not zero(j)) ) { + Let( prod := Mul(prod, j) ) + } +Return diff --git a/Task/MD4/C++/md4.cpp b/Task/MD4/C++/md4.cpp index 8158e2c879..89f613a547 100644 --- a/Task/MD4/C++/md4.cpp +++ b/Task/MD4/C++/md4.cpp @@ -133,10 +133,10 @@ private: } int32_t unsigned_right_shift(const int32_t& base, const int32_t& shift) { - if ( base == 0 || shift >= 32 ) { + if ( shift < 0 || shift >= 32 || base == 0 ) { return 0; } - return ( base > 0 ) ? base >> shift : ( base + TWO_POWER_32 ) >> shift; + return ( base > 0 ) ? base >> shift : static_cast(base) >> shift; } int32_t rotate(const int32_t& t, const int32_t& s) { @@ -164,7 +164,6 @@ private: std::vector buffer; const int32_t BLOCK_LENGTH = 64; - const int64_t TWO_POWER_32 = 4'294'967'296; }; int main() { diff --git a/Task/MD4/Raku/md4.raku b/Task/MD4/Raku/md4.raku index 842b30d469..72a13698e9 100644 --- a/Task/MD4/Raku/md4.raku +++ b/Task/MD4/Raku/md4.raku @@ -1,92 +1,50 @@ sub md4($str) { - my @buf = $str.ords; - my $buflen = @buf.elems; + my buf8 $buf .= new: $str.encode; + my $buf-length = $buf.elems; + $buf.push: 0x80; + $buf.push: 0 until ($buf - (448 div 8)) %% (512 div 8); + $buf.write-uint64: $buf.elems, $buf-length*8, LittleEndian; - my \mask = (1 +< 32) - 1; - my &f = -> $x, $y, $z { ($x +& $y) +| ($x +^ mask) +& $z } - my &g = -> $x, $y, $z { ($x +& $y) +| ($x +& $z) +| ($y +& $z) } - my &h = -> $x, $y, $z { $x +^ $y +^ $z } - my &r = -> $v, $s { (($v +< $s) +& mask) +| (($v +& mask) +> (32 - $s)) } + my (&f, &g, &h, &r) = + { $^x +& $^y +| +^$x +& $^z }, + { $^x +& $^y +| $x +& $^z +| $y +& $z }, + { $^x +^ $^y +^ $^z }, + # for some reason we have to type v here + -> uint32 $v, $s { $v +< $s +| $v +> (32 - $s) } - sub pack-le (@a) { - gather for @a -> $a,$b,$c,$d { take $d +< 24 + $c +< 16 + $b +< 8 + $a } + my uint32 ($a, $b, $c, $d) = 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476; + + for @$buf.rotor(64) { + my uint32 @x = .rotor(4).map: {:256[.reverse]} + + my ($aa, $bb, $cc, $dd) = $a, $b, $c, $d; + for 0, 4, 8, 12 -> $i { + $a = r($a + f($b, $c, $d) + @x[ $i+0 ], 3); + $d = r($d + f($a, $b, $c) + @x[ $i+1 ], 7); + $c = r($c + f($d, $a, $b) + @x[ $i+2 ], 11); + $b = r($b + f($c, $d, $a) + @x[ $i+3 ], 19); + } + for 0, 1, 2, 3 -> $i { + $a = r($a + g($b, $c, $d) + @x[ $i+0 ] + 0x5a827999, 3); + $d = r($d + g($a, $b, $c) + @x[ $i+4 ] + 0x5a827999, 5); + $c = r($c + g($d, $a, $b) + @x[ $i+8 ] + 0x5a827999, 9); + $b = r($b + g($c, $d, $a) + @x[ $i+12] + 0x5a827999, 13); + } + for 0, 2, 1, 3 -> $i { + $a = r($a + h($b, $c, $d) + @x[ $i+0 ] + 0x6ed9eba1, 3); + $d = r($d + h($a, $b, $c) + @x[ $i+8 ] + 0x6ed9eba1, 9); + $c = r($c + h($d, $a, $b) + @x[ $i+4 ] + 0x6ed9eba1, 11); + $b = r($b + h($c, $d, $a) + @x[ $i+12] + 0x6ed9eba1, 15); + } + ($a,$b,$c,$d) Z[+=] ($aa,$bb,$cc,$dd); } - my ($a, $b, $c, $d) = 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476; - - my $term = False; - my $last = False; - my $off = 0; - repeat until $last { - my @block = @buf[$off..$off+63]:v; $off += 64; - - my @x; - given +@block { - when 64 { - @x = pack-le @block; - } - when 56..63 { - $term = True; - @block.push(0x80); - @block.push(slip 0 xx 63 - $_); - @x = pack-le @block; - } - when 0..55 { - @block.push($term ?? 0 !! 0x80); - @block.push(slip 0 xx 55 - $_); - @x = pack-le @block; - - my $bit_len = $buflen +< 3; - @x.push: $bit_len +& mask, $bit_len +> 32; - $last = True; - } - default { - die "oops"; - } - } - - my ($aa, $bb, $cc, $dd) = $a, $b, $c, $d; - for 0, 4, 8, 12 -> \i { - $a = r($a + f($b, $c, $d) + @x[ i+0 ], 3); - $d = r($d + f($a, $b, $c) + @x[ i+1 ], 7); - $c = r($c + f($d, $a, $b) + @x[ i+2 ], 11); - $b = r($b + f($c, $d, $a) + @x[ i+3 ], 19); - } - for 0, 1, 2, 3 -> \i { - $a = r($a + g($b, $c, $d) + @x[ i+0 ] + 0x5a827999, 3); - $d = r($d + g($a, $b, $c) + @x[ i+4 ] + 0x5a827999, 5); - $c = r($c + g($d, $a, $b) + @x[ i+8 ] + 0x5a827999, 9); - $b = r($b + g($c, $d, $a) + @x[ i+12] + 0x5a827999, 13); - } - for 0, 2, 1, 3 -> \i { - $a = r($a + h($b, $c, $d) + @x[ i+0 ] + 0x6ed9eba1, 3); - $d = r($d + h($a, $b, $c) + @x[ i+8 ] + 0x6ed9eba1, 9); - $c = r($c + h($d, $a, $b) + @x[ i+4 ] + 0x6ed9eba1, 11); - $b = r($b + h($c, $d, $a) + @x[ i+12] + 0x6ed9eba1, 15); - } - $a = ($a + $aa) +& mask; - $b = ($b + $bb) +& mask; - $c = ($c + $cc) +& mask; - $d = ($d + $dd) +& mask; - } - - sub b2l($n is copy) { - my $x = 0; - for ^4 { - $x +<= 8; - $x += $n +& 0xff; - $n +>= 8; - } - $x; - } - - b2l($a) +< 96 + - b2l($b) +< 64 + - b2l($c) +< 32 + - b2l($d); + my buf8 $abcd .= new; + for $a, $b, $c, $d { $abcd.write-uint32: 4*$++, $_, LittleEndian } + blob8.new: $abcd; } sub MAIN { my $str = 'Rosetta Code'; - say md4($str).base(16).lc; + say md4($str); } diff --git a/Task/Magic-8-ball/Maxima/magic-8-ball.maxima b/Task/Magic-8-ball/Maxima/magic-8-ball.maxima new file mode 100644 index 0000000000..d11ab22fa3 --- /dev/null +++ b/Task/Magic-8-ball/Maxima/magic-8-ball.maxima @@ -0,0 +1,9 @@ +set_random_state(make_random_state(true))$ + +block( + responses:["It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yes","Signs point to yes", + "Reply hazy, try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again", + "Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful"], + read("Ask a question"), + print(responses[random(20)]) +); diff --git a/Task/Mandelbrot-set/Inform-7/mandelbrot-set.inf b/Task/Mandelbrot-set/Inform-7/mandelbrot-set-1.inf similarity index 100% rename from Task/Mandelbrot-set/Inform-7/mandelbrot-set.inf rename to Task/Mandelbrot-set/Inform-7/mandelbrot-set-1.inf diff --git a/Task/Mandelbrot-set/Inform-7/mandelbrot-set-2.inf b/Task/Mandelbrot-set/Inform-7/mandelbrot-set-2.inf new file mode 100644 index 0000000000..d84dc8065b --- /dev/null +++ b/Task/Mandelbrot-set/Inform-7/mandelbrot-set-2.inf @@ -0,0 +1,16 @@ +(function mandelbrot width height depth + (.. str + (for yy (range height) + xx (range width) + (let c_re (/ (* (- xx (/ width 2)) 4) width) + c_im (/ (* (- yy (/ height 2)) 4) width) + x 0 y 0 i 0) + (while (and (<= (+ (** x) (** y)) 4) + (< i depth)) + (let x2 (+ c_re (- (** x) (** y))) + y (+ c_im (* 2 x y)) + x x2 + i (inc i))) + (strn ((zero? xx) "\n") (i "ABCDEFGHIJ "))))) + +(mandelbrot 48 24 10) diff --git a/Task/Mandelbrot-set/Raku/mandelbrot-set-1.raku b/Task/Mandelbrot-set/Raku/mandelbrot-set-1.raku index 71cefc5251..9d4135c4b8 100644 --- a/Task/Mandelbrot-set/Raku/mandelbrot-set-1.raku +++ b/Task/Mandelbrot-set/Raku/mandelbrot-set-1.raku @@ -1,8 +1,9 @@ -constant MAX-ITERATIONS = 1000; +constant MAX-ITERATIONS = 64; my $width = +(@*ARGS[0] // 800); my $height = $width + $width %% 2; -say "P1"; +say "P2"; say "$width $height"; +say MAX-ITERATIONS; sub cut(Range $r, UInt $n where $n > 1 --> Seq) { $r.min, * + ($r.max - $r.min) / ($n - 1) ... $r.max @@ -14,9 +15,9 @@ my @im = cut( 0 .. 5/4, 1 + ($height div 2)) X* 1i; sub mandelbrot(Complex $z is copy, Complex $c --> Int) { for 1 .. MAX-ITERATIONS { $z = $z*$z + $c; - return 0 if $z.abs > 2; + return $_ if $z.abs > 2; } - return 1; + return 0; } my @lines = hyper for @im X+ @re { diff --git a/Task/Matrix-transposition/EasyLang/matrix-transposition.easy b/Task/Matrix-transposition/EasyLang/matrix-transposition.easy new file mode 100644 index 0000000000..2fa5821aa3 --- /dev/null +++ b/Task/Matrix-transposition/EasyLang/matrix-transposition.easy @@ -0,0 +1,14 @@ +proc transpose . m[][] . + len n[][] len m[1][] + for i to len n[][] + for j to len m[][] + n[i][] &= m[j][i] + . + . + swap n[][] m[][] +. +m[][] = [ [ 1 2 3 4 ] [ 5 6 7 8 ] [ 9 10 11 12 ] ] +print m[][] +print "" +transpose m[][] +print m[][] diff --git a/Task/Matrix-transposition/Idris/matrix-transposition.idris b/Task/Matrix-transposition/Idris/matrix-transposition-1.idris similarity index 100% rename from Task/Matrix-transposition/Idris/matrix-transposition.idris rename to Task/Matrix-transposition/Idris/matrix-transposition-1.idris diff --git a/Task/Matrix-transposition/Idris/matrix-transposition-2.idris b/Task/Matrix-transposition/Idris/matrix-transposition-2.idris new file mode 100644 index 0000000000..bf15a3cf95 --- /dev/null +++ b/Task/Matrix-transposition/Idris/matrix-transposition-2.idris @@ -0,0 +1,3 @@ +(var transpose2d @(... map vec)) + +(transpose2d [[1 1 1 1] [2 4 8 16] [3 9 27 81] [4 16 64 256] [5 25 125 625]]) diff --git a/Task/Maze-generation/FutureBasic/maze-generation.basic b/Task/Maze-generation/FutureBasic/maze-generation.basic new file mode 100644 index 0000000000..b112b74bdc --- /dev/null +++ b/Task/Maze-generation/FutureBasic/maze-generation.basic @@ -0,0 +1,96 @@ +_rows = 9 +_cols = 11 +_size = 32 +_mgn = 32 + +_t = ( 1 << 0 ) +_l = ( 1 << 1 ) +_b = ( 1 << 2 ) +_r = ( 1 << 3 ) +_a = _t + _l + _b + _r + +_window = 1 + +void local fn BuildWindow + window _window, @"FutureBasic - Maze generation", (0,0,_cols*_size+_mgn*2,_rows*_size+_mgn*2), NSWindowStyleMaskTitled +end fn + + +local fn CellAvailable( r as long, c as long ) as BOOL + if ( r < 0 || c < 0 || r >= _rows || c >= _cols ) then exit fn + if ( mda_integer(r,c) == _a ) then exit fn = YES +end fn = NO + + +void local fn ProcessCell( r as long, c as long ) + long r1 = r, c1 = c, d(3), count, dir, opp + + while ( 1 ) + BlockZero( @d(0), sizeof(long) * 4 ) + count = 0 + if ( fn CellAvailable( r - 1, c ) ) then d(count) = _t : count++ + if ( fn CellAvailable( r, c - 1 ) ) then d(count) = _l : count++ + if ( fn CellAvailable( r + 1, c ) ) then d(count) = _b : count++ + if ( fn CellAvailable( r, c + 1 ) ) then d(count) = _r : count++ + if ( count == 0 ) then break + + dir = d(rnd(count)-1) + mda(r,c) = @(mda_integer(r,c) - dir) + + select ( dir ) + case _t + r1 = r-1 : opp = _b + case _l + c1 = c-1 : opp = _r + case _b + r1 = r+1 : opp = _t + case _r + c1 = c+1 : opp = _l + end select + + mda(r1,c1) = @(mda_integer(r1,c1) - opp) + fn ProcessCell( r1, c1 ) + wend +end fn + + +void local fn DrawMaze + long r, c, x = _mgn, y = _mgn, value + + pen 2,, NSLineCapStyleRound + + for r = 0 to _rows - 1 + for c = 0 to _cols - 1 + value = mda(r,c) + if ( value & _t ) then line x, y to x + _size, y + if ( value & _l ) then line x, y to x, y + _size + if ( value & _b ) then line x, y + _size to x + _size, y + _size + if ( value & _r ) then line x + _size, y to x + _size, y + _size + x += _size + next + x = _mgn + y += _size + next +end fn + + +void local fn BuildMaze + long r, c + + for r = 0 to _rows - 1 + for c = 0 to _cols - 1 + mda(r,c) = _a + next + next + + random + r = rnd(_rows) - 1 + c = rnd(_cols) - 1 + fn ProcessCell( r, c ) + fn DrawMaze +end fn + +fn BuildWindow +fn BuildMaze + +HandleEvents diff --git a/Task/Meissel-Mertens-constant/Maxima/meissel-mertens-constant.maxima b/Task/Meissel-Mertens-constant/Maxima/meissel-mertens-constant.maxima new file mode 100644 index 0000000000..f999fcb7b4 --- /dev/null +++ b/Task/Meissel-Mertens-constant/Maxima/meissel-mertens-constant.maxima @@ -0,0 +1 @@ +meissel_mertens:%gamma+lsum(log(1-(1/i))+(1/i),i,primes(2,10000000)),numer; diff --git a/Task/Miller-Rabin-primality-test/AArch64-Assembly/miller-rabin-primality-test.aarch64 b/Task/Miller-Rabin-primality-test/AArch64-Assembly/miller-rabin-primality-test.aarch64 new file mode 100644 index 0000000000..ac6ec0947a --- /dev/null +++ b/Task/Miller-Rabin-primality-test/AArch64-Assembly/miller-rabin-primality-test.aarch64 @@ -0,0 +1,298 @@ +/* ARM assembly AARCH64 Raspberry PI 3B */ +/* program testmiller64B.s */ +// optimisation : one routine + +/************************************/ +/* Constantes */ +/************************************/ +/* for this file see task include a file in language AArch64 assembly*/ +.include "../includeConstantesARM64.inc" + +.equ NBLOOP, 5 // loop number change this if necessary + // if modify, thinck to add test to little prime value + // in routine +//.include "../../ficmacros64.inc" // use for developper debugging +/*******************************************/ +/* Initialized data */ +/*******************************************/ +.data +szMessStartPgm: .asciz "Program 64 bits start \n" +szMessEndPgm: .asciz "Program normal end.\n" +szMessPrime: .asciz " is prime !!!.\n" +szMessNotPrime: .asciz " is not prime !!!.\n" +szCarriageReturn: .asciz "\n" + +/*******************************************/ +/* UnInitialized data */ +/*******************************************/ +.bss +.align 4 +sZoneConv: .skip 24 +/*******************************************/ +/* code section */ +/*******************************************/ +.text +.global main +main: // program start + ldr x0,qAdrszMessStartPgm // display start message + bl affichageMess + ldr x4,iStart // start number + ldr x5,iLimit // end number + tst x4,#1 + cinc x4,x4,eq // start with odd number +1: + mov x0,x4 + bl isPrimeMiller // test miller rabin + cmp x0,#0 + beq 2f + mov x0,x4 + ldr x1,qAdrsZoneConv + bl conversion10 // decimal conversion + ldr x0,qAdrsZoneConv + bl affichageMess + ldr x0,qAdrszMessPrime + bl affichageMess + b 3f +2: + ldr x0,qAdrszMessNotPrime + // bl affichageMess +3: + add x4,x4,#2 + cmp x4,x5 + blo 1b + + ldr x0,qAdrszMessEndPgm // display end message + bl affichageMess + +100: // standard end of the program + mov x0, #0 // return code + mov x8, #EXIT // request to exit program + svc 0 // perform system call +qAdrszMessStartPgm: .quad szMessStartPgm +qAdrszMessEndPgm: .quad szMessEndPgm +qAdrszCarriageReturn: .quad szCarriageReturn +qAdrsZoneConv: .quad sZoneConv +qAdrszMessPrime: .quad szMessPrime +qAdrszMessNotPrime: .quad szMessNotPrime +//iStart: .quad 0x0 +//iLimit: .quad 0x100 +iStart: .quad 0xFFFFFFFFFFFFFF00 +iLimit: .quad 0xFFFFFFFFFFFFFFF0 +//iStart: .quad 341550071728360 +//iLimit: .quad 341550071728380 +//359341550071728361 + +/***************************************************/ +/* test miller rabin algorithme wikipedia */ +/* unsigned */ +/***************************************************/ +/* x0 contains number */ +/* x1 contains parameter */ +/* x0 return 1 if prime 0 if composite */ +isPrimeMiller: + stp x1,lr,[sp,-16]! // TODO: save à completer + stp x2,x3,[sp,-16]! + stp x4,x5,[sp,-16]! + stp x6,x7,[sp,-16]! + stp x8,x9,[sp,-16]! + cmp x0,#1 // control 0 or 1 + csel x0,xzr,x0,ls + bls 100f + cmp x0,#2 // control = 2 + mov x1,1 + csel x0,x1,x0,eq + beq 100f + cmp x0,#3 // control = 3 + csel x0,x1,x0,eq + beq 100f + cmp x0,#5 // control = 5 + csel x0,x1,x0,eq + beq 100f + cmp x0,#7 // control = 7 + csel x0,x1,x0,eq + beq 100f + cmp x0,#11 // control = 11 + csel x0,x1,x0,eq + beq 100f + tst x0,#1 + csel x0,xzr,x0,eq // even + beq 100f + mov x4,x0 // N + sub x3,x0,#1 // D + mov x2,#2 + mov x6,#0 // S +1: // compute D * 2 power S + lsr x3,x3,#1 // D= D/2 + add x6,x6,#1 // increment S + tst x3,#1 // D even ? + beq 1b +2: + mov x8,#0 // loop counter + sub x5,x0,#3 + mov x7,3 +3: + mov x0,x7 + mov x1,x3 // exposant = D + mov x2,x4 // modulo N + bl moduloPur64 + cmp x0,#1 + beq 5f + sub x1,x4,#1 // n -1 + cmp x0,x1 + beq 5f + sub x9,x6,#1 // S - 1 +4: + mov x2,x0 + + mul x0,x2,x2 // compute square lower + umulh x1,x2,x2 // compute square upper + mov x2,x4 // and compute modulo N + bl division64R2023 + mov x0,x2 + cmp x0,#1 + csel x0,xzr,x0,eq // composite + beq 100f + sub x1,x4,#1 // n -1 + cmp x0,x1 + beq 5f + subs x9,x9,#1 + bge 4b + mov x0,#0 // composite + b 100f +5: + add x7,x7,2 + add x8,x8,#1 + cmp x8,NBLOOP + blt 3b + mov x0,#1 // prime +100: + ldp x8,x9,[sp],16 + ldp x6,x7,[sp],16 + ldp x4,x5,[sp],16 + ldp x2,x3,[sp],16 + ldp x1,lr,[sp],16 // TODO: retaur à completer + ret +/********************************************************/ +/* Calcul modulo de b puissance e modulo m */ +/* Exemple 4 puissance 13 modulo 497 = 445 */ +/********************************************************/ +/* x0 nombre */ +/* x1 exposant */ +/* x2 modulo */ +moduloPur64: + stp x1,lr,[sp,-16]! // save registres + stp x3,x4,[sp,-16]! // save registres + stp x5,x6,[sp,-16]! // save registres + stp x7,x8,[sp,-16]! // save registres + stp x9,x10,[sp,-16]! // save registres + cbz x0,100f + cbz x1,100f + mov x8,x0 + mov x7,x1 + mov x10,x2 // modulo + mov x6,1 // resultat + udiv x4,x8,x10 + msub x9,x4,x10,x8 // contient le reste +1: + tst x7,1 + beq 2f + mul x4,x9,x6 + umulh x5,x9,x6 + mov x6,x4 + mov x0,x6 + mov x1,x5 + mov x2,x10 + bl division64R2023 + mov x6,x2 +2: + mul x8,x9,x9 + umulh x5,x9,x9 + mov x0,x8 + mov x1,x5 + mov x2,x10 + bl division64R2023 + mov x9,x2 + lsr x7,x7,1 + cbnz x7,1b + mov x0,x6 // result + cmn x0,0 // clear carry not error + +100: + ldp x9,x10,[sp],16 // restaur des 2 registres + ldp x7,x8,[sp],16 // restaur des 2 registres + ldp x5,x6,[sp],16 // restaur des 2 registres + ldp x3,x4,[sp],16 // restaur des 2 registres + ldp x1,lr,[sp],16 // restaur des 2 registres + ret // retour adresse lr x30 +/***************************************************/ +/* division number 128 bits in 2 registers by number 64 bits */ +/* unsigned */ +/***************************************************/ +/* x0 contains lower part dividende */ +/* x1 contains upper part dividende */ +/* x2 contains divisor */ +/* x0 return lower part quotient */ +/* x1 return upper part quotient */ +/* x2 return remainder */ +division64R2023: + stp x3,lr,[sp,-16]! + stp x4,x5,[sp,-16]! + stp x6,x7,[sp,-16]! + mov x4,x2 // save divisor + mov x5,#0 // init upper part divisor + mov x2,x0 // save dividende + mov x3,x1 + mov x0,#0 // init result + mov x1,#0 + mov x6,#0 // init shift counter +1: // loop shift divisor + cmp x5,#0 // upper divisor <0 + blt 2f + cmp x5,x3 + bhi 2f + blo 11f + cmp x4,x2 + bhi 2f // new divisor > dividende +11: + lsl x5,x5,#1 // shift left one bit upper divisor + tst x4,#0x8000000000000000 + lsl x4,x4,#1 // shift left one bit lower divisor + orr x7,x5,#1 + csel x5,x7,x5,ne // move bit 63 lower on upper + add x6,x6,#1 // increment shift counter + b 1b + +2: // loop 2 + lsl x1,x1,#1 // shift left one bit upper quotient + tst x0,#0x8000000000000000 + lsl x0,x0,#1 // shift left one bit lower quotient + orr x7,x1,#1 + csel x1,x7,x1,ne // move bit 63 lower on upper + cmp x5,x3 // compare divisor and dividende + bhi 3f + blo 21f + cmp x4,x2 + bhi 3f +21: + subs x2,x2,x4 // < sub divisor from dividende lower + sbc x3,x3,x5 // and upper + orr x0,x0,#1 // move 1 on quotient +3: + lsr x4,x4,#1 // shift right one bit upper divisor + tst x5,1 + lsr x5,x5,#1 // and lower + orr x7,x4,#0x8000000000000000 // move bit 0 upper to 31 bit lower + csel x4,x7,x4,ne // move bit 0 upper to 63 bit lower + subs x6,x6,#1 // decrement shift counter + bge 2b // if > 0 loop 2 + +100: + ldp x6,x7,[sp],16 + ldp x4,x5,[sp],16 + ldp x3,lr,[sp],16 + ret + +/***************************************************/ +/* ROUTINES INCLUDE */ +/***************************************************/ +.include "../includeARM64.inc" diff --git a/Task/Miller-Rabin-primality-test/Quackery/miller-rabin-primality-test.quackery b/Task/Miller-Rabin-primality-test/Quackery/miller-rabin-primality-test.quackery new file mode 100644 index 0000000000..5f6727a6ec --- /dev/null +++ b/Task/Miller-Rabin-primality-test/Quackery/miller-rabin-primality-test.quackery @@ -0,0 +1,74 @@ + [ nextword + dup $ "" = if + [ $ "var needs a name" + message put bail ] + $ " [ stack 0 ] is " + over join + $ " [ " + join over join + $ " replace ] is ->" + join over join + $ " [ " + join over join + $ " share ] is " + join swap join + $ "-> " join + swap join ] builds var ( [ $ --> [ $ ) + + 10000 eratosthenes + + [ 1 & not ] is even ( n --> b ) + + var n var d var s var a + var t var x var y var c + + [ dup 10000 < iff isprime done + dup even iff + [ drop false ] done + dup ->n + [ 1 - 0 swap + [ dup even while + 1 >> dip 1+ again ] ] + ->d ->s + false ->c + 20 times + [ n-> 2 - random 2 + ->a + s-> ->t + a-> d-> n-> **mod ->x + s-> times + [ x-> 2 n-> **mod ->y + y-> 1 = + x-> 1 != + x-> n-> 1 - != + and and iff + [ true ->c conclude ] + done + y-> ->x ] + c-> iff conclude done + y-> 1 != if + [ true ->c conclude ] ] + c-> not ] is prime ( n --> b ) + + say "Primes < 100:" cr + 100 times [ i^ prime if [ i^ echo sp ] ] + cr cr + [] 1000 times + [ i^ 9223372036854774808 + dup + prime iff join else drop ] + say "There are " + dup size echo + say " primes between 9223372036854774808 and 9223372036854775808:" + cr cr + witheach [ echo i^ 1+ 4 mod iff sp else cr ] + cr cr + 4547337172376300111955330758342147474062293202868155909489 dup echo + prime iff + [ say " is prime." ] + else + [ say " is not prime." ] + cr cr + 4547337172376300111955330758342147474062293202868155909393 dup echo + prime iff + [ say "is prime." ] + else + [ say " is not prime." ] diff --git a/Task/Modular-inverse/Maxima/modular-inverse.maxima b/Task/Modular-inverse/Maxima/modular-inverse.maxima new file mode 100644 index 0000000000..ad7f32ae4a --- /dev/null +++ b/Task/Modular-inverse/Maxima/modular-inverse.maxima @@ -0,0 +1 @@ +inv_mod(42,2017); diff --git a/Task/Monty-Hall-problem/Chapel/monty-hall-problem.chapel b/Task/Monty-Hall-problem/Chapel/monty-hall-problem-1.chapel similarity index 100% rename from Task/Monty-Hall-problem/Chapel/monty-hall-problem.chapel rename to Task/Monty-Hall-problem/Chapel/monty-hall-problem-1.chapel diff --git a/Task/Monty-Hall-problem/Chapel/monty-hall-problem-2.chapel b/Task/Monty-Hall-problem/Chapel/monty-hall-problem-2.chapel new file mode 100644 index 0000000000..7aba05d408 --- /dev/null +++ b/Task/Monty-Hall-problem/Chapel/monty-hall-problem-2.chapel @@ -0,0 +1,21 @@ +use Random; + +config const numGames = 100_000_000; + +var switch, stick: uint; + +// have a separate RNG for each task; add together the results at the end +forall i in 1..numGames + with (var rand = new RandomStream(uint, parSafe = false), + reduce stick) +{ + var chosen_door = rand.getNext() % 3; + var winner_door = rand.getNext() % 3; + if chosen_door == winner_door then + stick += 1; +} + +// if you lost by sticking it means you would have won by switching +switch = numGames - stick; +writeln("Over ", numGames, " games:\n - switching wins ", + 100.0*switch / numGames, "% of the time and\n - sticking wins ", + 100.0*stick / numGames, "% of the time"); diff --git a/Task/Monty-Hall-problem/EasyLang/monty-hall-problem.easy b/Task/Monty-Hall-problem/EasyLang/monty-hall-problem.easy new file mode 100644 index 0000000000..1ee159f97e --- /dev/null +++ b/Task/Monty-Hall-problem/EasyLang/monty-hall-problem.easy @@ -0,0 +1,21 @@ +max = 1000000 +for i = 1 to max + car_door = random 3 + chosen_door = random 3 + if car_door <> chosen_door + montys_door = 6 - car_door - chosen_door + else + repeat + montys_door = random 3 + until montys_door <> car_door + . + . + if car_door = chosen_door + stay += 1 + . + if car_door = 6 - montys_door - chosen_door + switch += 1 + . +. +print "If you stick to your choice, you have a " & stay / max * 100 & " percent chance to win" +print "If you switched, you have a " & switch / max * 100 & " percent chance to win" diff --git a/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-1.m b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-1.m index 3cfcc37314..a57616b370 100644 --- a/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-1.m +++ b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-1.m @@ -1,56 +1,2 @@ -function montyHall(numDoors,numSimulations) - - assert(numDoors > 2); - - function num = randInt(n) - num = floor( n*rand()+1 ); - end - - %The first column will tallie wins, the second losses - switchedDoors = [0 0]; - stayed = [0 0]; - - - for i = (1:numSimulations) - - availableDoors = (1:numDoors); %Preallocate the available doors - winningDoor = randInt(numDoors); %Define the winning door - playersOriginalChoice = randInt(numDoors); %The player picks his initial choice - - availableDoors(playersOriginalChoice) = []; %Remove the players choice from the available doors - - %Pick the door to open from the available doors - openDoor = availableDoors(randperm(numel(availableDoors))); %Sort the available doors randomly - openDoor(openDoor == winningDoor) = []; %Make sure Monty doesn't open the winning door - openDoor = openDoor(randInt(numel(openDoor))); %Choose a random door to open - - availableDoors(availableDoors==openDoor) = []; %Remove the open door from the available doors - availableDoors(end+1) = playersOriginalChoice; %Put the player's original choice back into the pool of available doors - availableDoors = sort(availableDoors); - - playersNewChoice = availableDoors(randInt(numel(availableDoors))); %Pick one of the available doors - - if playersNewChoice == playersOriginalChoice - switch playersNewChoice == winningDoor - case true - stayed(1) = stayed(1) + 1; - case false - stayed(2) = stayed(2) + 1; - otherwise - error 'ERROR' - end - else - switch playersNewChoice == winningDoor - case true - switchedDoors(1) = switchedDoors(1) + 1; - case false - switchedDoors(2) = switchedDoors(2) + 1; - otherwise - error 'ERROR' - end - end - end - - disp(sprintf('Switch win percentage: %f%%\nStay win percentage: %f%%\n', [switchedDoors(1)/sum(switchedDoors),stayed(1)/sum(stayed)] * 100)); - -end +wins = ceil(3*rand(1e8,1)) - ceil(3*rand(1e8,1)) +mprintf('chance to win for staying: %1.6f %%\nchance to win for changing: %1.6f %%', 100*length(wins(wins==0))/length(wins), 100*length(wins(wins<>0))/length(wins)) diff --git a/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-2.m b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-2.m index 41e03e8759..aeaaa65860 100644 --- a/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-2.m +++ b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-2.m @@ -1,3 +1,2 @@ ->> montyHall(3,100000) -Switch win percentage: 66.705972% -Stay win percentage: 33.420062% +chance to win for staying: 33.334694 % +chance to win for changing: 66.665306 % diff --git a/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-3.m b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-3.m new file mode 100644 index 0000000000..3cfcc37314 --- /dev/null +++ b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-3.m @@ -0,0 +1,56 @@ +function montyHall(numDoors,numSimulations) + + assert(numDoors > 2); + + function num = randInt(n) + num = floor( n*rand()+1 ); + end + + %The first column will tallie wins, the second losses + switchedDoors = [0 0]; + stayed = [0 0]; + + + for i = (1:numSimulations) + + availableDoors = (1:numDoors); %Preallocate the available doors + winningDoor = randInt(numDoors); %Define the winning door + playersOriginalChoice = randInt(numDoors); %The player picks his initial choice + + availableDoors(playersOriginalChoice) = []; %Remove the players choice from the available doors + + %Pick the door to open from the available doors + openDoor = availableDoors(randperm(numel(availableDoors))); %Sort the available doors randomly + openDoor(openDoor == winningDoor) = []; %Make sure Monty doesn't open the winning door + openDoor = openDoor(randInt(numel(openDoor))); %Choose a random door to open + + availableDoors(availableDoors==openDoor) = []; %Remove the open door from the available doors + availableDoors(end+1) = playersOriginalChoice; %Put the player's original choice back into the pool of available doors + availableDoors = sort(availableDoors); + + playersNewChoice = availableDoors(randInt(numel(availableDoors))); %Pick one of the available doors + + if playersNewChoice == playersOriginalChoice + switch playersNewChoice == winningDoor + case true + stayed(1) = stayed(1) + 1; + case false + stayed(2) = stayed(2) + 1; + otherwise + error 'ERROR' + end + else + switch playersNewChoice == winningDoor + case true + switchedDoors(1) = switchedDoors(1) + 1; + case false + switchedDoors(2) = switchedDoors(2) + 1; + otherwise + error 'ERROR' + end + end + end + + disp(sprintf('Switch win percentage: %f%%\nStay win percentage: %f%%\n', [switchedDoors(1)/sum(switchedDoors),stayed(1)/sum(stayed)] * 100)); + +end diff --git a/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-4.m b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-4.m new file mode 100644 index 0000000000..41e03e8759 --- /dev/null +++ b/Task/Monty-Hall-problem/MATLAB/monty-hall-problem-4.m @@ -0,0 +1,3 @@ +>> montyHall(3,100000) +Switch win percentage: 66.705972% +Stay win percentage: 33.420062% diff --git a/Task/Monty-Hall-problem/Standard-ML/monty-hall-problem.ml b/Task/Monty-Hall-problem/Standard-ML/monty-hall-problem.ml new file mode 100644 index 0000000000..48b9e69ad3 --- /dev/null +++ b/Task/Monty-Hall-problem/Standard-ML/monty-hall-problem.ml @@ -0,0 +1,23 @@ +val pidint = Word64.toInt(Posix.Process.pidToWord(Posix.ProcEnv.getpid())); +val rand = Random.rand(LargeInt.toInt(Time.toSeconds(Time.now())), pidint); + +fun stick_win 0 wins = wins + | stick_win trial wins = + let + val winner_door = (Random.randNat rand) mod 3; + val chosen_door = (Random.randNat rand) mod 3; + in + if winner_door = chosen_door then + stick_win (trial-1) (wins+1) + else + stick_win (trial-1) wins + end + +val trials = 1000000; +val sticks = stick_win trials 0; +val stick_winrate = 100.0 * Real.fromInt(sticks) / Real.fromInt(trials); +(* if you lost by sticking you would have won by swapping *) +val swap_winrate = 100.0 - stick_winrate; + +(print ("sticking = " ^ Real.toString(stick_winrate) ^ "% win rate\n"); + print ("swapping = " ^ Real.toString(swap_winrate) ^ "% win rate\n")); diff --git a/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-1.quackery b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-1.quackery new file mode 100644 index 0000000000..8f204d603c --- /dev/null +++ b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-1.quackery @@ -0,0 +1,15 @@ + [ this ] is null ( --> [ ) + + [ 0 unrot + witheach + [ dip + [ behead rot ] + * + swap ] + drop ] is [a]-> ( [ [ --> n ) + + [ [] unrot + reverse + witheach + [ /mod rot + join swap ] + drop ] is ->[a] ( n [ --> [ ) diff --git a/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-2.quackery b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-2.quackery new file mode 100644 index 0000000000..d093afff98 --- /dev/null +++ b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-2.quackery @@ -0,0 +1,15 @@ + [ dip nested + reverse + witheach + [ of i if nested ] ] is array ( [ --> a ) + + [ witheach peek ] is [peek] ( [ a --> x ) + + [ dup dip + [ rot dip + [ -1 split drop + witheach + [ dip dup peek ] ] ] + reverse + witheach + [ dip swap poke ] ] is [poke] ( x a [ --> a ) diff --git a/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-3.quackery b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-3.quackery new file mode 100644 index 0000000000..931ca003d7 --- /dev/null +++ b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-3.quackery @@ -0,0 +1,18 @@ + [ swap nested + over 1 swap + witheach * + of + 2 pack ] is array ( x [ --> [ ) + + [ 0 peek ] is [layout] ( [ --> [ ) + + [ 1 peek size ] is [size] ( [ --> n ) + + [ swap unpack + unrot [a]-> peek ] is [peek] ( [ a --> x ) + + [ swap unpack + dip [ tuck [a]-> ] + rot dip + [ swap poke ] + swap 2 pack ] is [poke] ( x a [ --> a ) diff --git a/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-4.quackery b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-4.quackery new file mode 100644 index 0000000000..b526879093 --- /dev/null +++ b/Task/Multi-dimensional-array/Quackery/multi-dimensional-array-4.quackery @@ -0,0 +1,23 @@ + null ' [ 5 4 3 2 ] array + say "[ 5 4 3 2 ] array created, initialised with nulls." + cr + cr + 2 swap ' [ 3 2 1 0 ] [poke] + say "2 stored in [ 3 2 1 0 ]." + cr + 4 swap ' [ 4 3 2 1 ] [poke] + say "4 stored in [ 4 3 2 1 ]." + cr + 8 swap ' [ 4 3 2 1 ] [poke] + say "8 stored in [ 4 3 2 1 ]." + cr + cr + dup ' [ 0 0 0 0 ] [peek] echo + say " copied from [ 0 0 0 0 ]." + cr + dup ' [ 3 2 1 0 ] [peek] echo + say " copied from [ 3 2 1 0 ]." + cr + ' [ 4 3 2 1 ] [peek] echo + say " copied from [ 4 3 2 1 ]." + cr diff --git a/Task/Multiplication-tables/Icon/multiplication-tables.icon b/Task/Multiplication-tables/Icon/multiplication-tables-1.icon similarity index 100% rename from Task/Multiplication-tables/Icon/multiplication-tables.icon rename to Task/Multiplication-tables/Icon/multiplication-tables-1.icon diff --git a/Task/Multiplication-tables/Icon/multiplication-tables-2.icon b/Task/Multiplication-tables/Icon/multiplication-tables-2.icon new file mode 100644 index 0000000000..923893054b --- /dev/null +++ b/Task/Multiplication-tables/Icon/multiplication-tables-2.icon @@ -0,0 +1,9 @@ +(var pad-num (comp str (pad-left " " 4))) + +(join "\n" + (for y (range 1 13) + (... str "x" (pad-num y) + (for x (range 1 13) + (if (> y x) + " " + (pad-num (* x y))))))) diff --git a/Task/Nth-root/Bracmat/nth-root.bracmat b/Task/Nth-root/Bracmat/nth-root-1.bracmat similarity index 100% rename from Task/Nth-root/Bracmat/nth-root.bracmat rename to Task/Nth-root/Bracmat/nth-root-1.bracmat diff --git a/Task/Nth-root/Bracmat/nth-root-2.bracmat b/Task/Nth-root/Bracmat/nth-root-2.bracmat new file mode 100644 index 0000000000..cf3223cddc --- /dev/null +++ b/Task/Nth-root/Bracmat/nth-root-2.bracmat @@ -0,0 +1,51 @@ + "The body of Pow will be compiled twice: once as the the code hidden in the + UFP object called 'POW' (see below) and once as a local function of the code + hidden in the UFP object called 'Root' (also see below)." +& ( Pow + = (s.x) (s.e) + . 1:?r + & 0:?i + & whl + ' ( !i:!EPS-) + ) + & !r + ) + ) + : (=?root) +& "Create two UFP objects, POW and ROOT. They are each others' inverse." +& new$(UFP,Pow):?POW +& new$(UFP,root):?Root +& 15:?n +& (POW..go)$("-3.14159",15):?x +& out$((Root..go)$(!n,!x)); diff --git a/Task/Nth-root/Raku/nth-root.raku b/Task/Nth-root/Raku/nth-root.raku index e0056fea42..b055ecd8ff 100644 --- a/Task/Nth-root/Raku/nth-root.raku +++ b/Task/Nth-root/Raku/nth-root.raku @@ -1,11 +1,7 @@ -sub nth-root ($n, $A, $p=1e-9) -{ - my $x0 = $A / $n; - loop { - my $x1 = (($n-1) * $x0 + $A / ($x0 ** ($n-1))) / $n; - return $x1 if abs($x1-$x0) < abs($x0 * $p); - $x0 = $x1; - } +sub infix:<√>($n, $A) { + .tail given $A / $n, { (($n-1) * $_+ $A / ($_** ($n-1))) / $n } ... * ≅ *; } -say nth-root(3,8); +use Test; +plan 9; +is-approx ($_√pi)**$_, pi for 2 .. 10; diff --git a/Task/Nth/Icon/nth.icon b/Task/Nth/Icon/nth-1.icon similarity index 100% rename from Task/Nth/Icon/nth.icon rename to Task/Nth/Icon/nth-1.icon diff --git a/Task/Nth/Icon/nth-2.icon b/Task/Nth/Icon/nth-2.icon new file mode 100644 index 0000000000..a02ec651c2 --- /dev/null +++ b/Task/Nth/Icon/nth-2.icon @@ -0,0 +1,13 @@ +(function ordinal n + (if ([11 12 13] (rem n 100)) + (str n "th") + (str n (or ((rem n 10) ["th" "st" "nd" "rd"]) "th")))) + +(function line x y + (-> (range x y) + (map (comp ordinal (pad-left " " 6))) + (join " "))) + +(.. str (line 0 13) "\n" (line 1000 1013) + "\n\n" (line 13 26) "\n" (line 1013 1026) + "\n\n" (line 250 266)) diff --git a/Task/Nth/Joy/nth.joy b/Task/Nth/Joy/nth.joy new file mode 100644 index 0000000000..4bfe7c8f1b --- /dev/null +++ b/Task/Nth/Joy/nth.joy @@ -0,0 +1,5 @@ +DEFINE + suffix == abs 89 + 100 rem 9 - 10 rem [{1 2 3} in] [] [pop 0] ifte ["th" "st" "nd" "rd"] of; + nth == ['d 1 1 format] [suffix] cleave concat. + +[0 250 1000] [25 [dup nth putchars ' putch succ] times nth putchars '\n putch] step. diff --git a/Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/EasyLang/numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors.easy b/Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/EasyLang/numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors.easy new file mode 100644 index 0000000000..dff1b39e1c --- /dev/null +++ b/Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/EasyLang/numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors.easy @@ -0,0 +1,38 @@ +func has8divs n . + if n = 1 + return 1 + . + cnt = 2 + sqr = sqrt n + for d = 2 to sqr + if n mod d = 0 + cnt += 1 + if d <> sqr + cnt += 1 + . + if cnt > 8 + return 0 + . + . + . + if cnt = 8 + return 1 + . + return 0 +. +while count < 50 + x += 1 + if has8divs x = 1 + write x & " " + count += 1 + . +. +while count < 50000 + x += 1 + if has8divs x = 1 + count += 1 + if count = 500 or count = 5000 or count = 50000 + print count & "th: " & x + . + . +. diff --git a/Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/Maxima/numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors.maxima b/Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/Maxima/numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors.maxima new file mode 100644 index 0000000000..8f48b8f533 --- /dev/null +++ b/Task/Numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors/Maxima/numbers-which-are-the-cube-roots-of-the-product-of-their-proper-divisors.maxima @@ -0,0 +1,10 @@ +croot_prod_prop_divisors(n):=block([i:1,count:0,result:[]], + while count 0 + r *= dig + h -= 1 + . + sum += r + until tmp = 0 + . + until sum = curr + . + return curr +. +for n = 3 to 8 + curr = pow 10 (n - 1) + repeat + curr = next curr n pow 10 n + until curr = -1 + print curr + . +. diff --git a/Task/Own-digits-power-sum/Quackery/own-digits-power-sum.quackery b/Task/Own-digits-power-sum/Quackery/own-digits-power-sum.quackery new file mode 100644 index 0000000000..d8182a616f --- /dev/null +++ b/Task/Own-digits-power-sum/Quackery/own-digits-power-sum.quackery @@ -0,0 +1,3 @@ + 100000000 100 - times + [ i^ 100 + narcissistic if + [ i^ 100 + echo cr ] ] diff --git a/Task/Pangram-checker/EasyLang/pangram-checker.easy b/Task/Pangram-checker/EasyLang/pangram-checker.easy new file mode 100644 index 0000000000..b9a7e49287 --- /dev/null +++ b/Task/Pangram-checker/EasyLang/pangram-checker.easy @@ -0,0 +1,30 @@ +func pangr s$ . + len d[] 26 + for c$ in strchars s$ + c = strcode c$ + if c >= 97 and c <= 122 + c -= 32 + . + if c >= 65 and c <= 91 + d[c - 64] = 1 + . + . + for h in d[] + s += h + . + return s +. +repeat + s$ = input + until s$ = "" + print s$ + if pangr s$ = 26 + print " --> pangram" + . + print "" +. +input_data +This is a test. +The quick brown fox jumps over the lazy dog. +The quick brown fox jumped over the lazy dog. +QwErTyUiOpAsDfGhJkLzXcVbNm diff --git a/Task/Pangram-checker/Icon/pangram-checker-3.icon b/Task/Pangram-checker/Icon/pangram-checker-3.icon new file mode 100644 index 0000000000..5e0093992d --- /dev/null +++ b/Task/Pangram-checker/Icon/pangram-checker-3.icon @@ -0,0 +1,5 @@ +(function pangram? sentence + (let prepped (-> sentence lower-case to-vec)) + (all? prepped (map char-code (range 97 123)))) + +(pangram? "The five boxing wizards jump quickly.") diff --git a/Task/Perfect-numbers/EasyLang/perfect-numbers.easy b/Task/Perfect-numbers/EasyLang/perfect-numbers.easy new file mode 100644 index 0000000000..b558cc5ca8 --- /dev/null +++ b/Task/Perfect-numbers/EasyLang/perfect-numbers.easy @@ -0,0 +1,13 @@ +func perf n . + for i = 1 to n - 1 + if n mod i = 0 + sum += i + . + . + return if sum = n +. +for i = 2 to 10000 + if perf i = 1 + print i + . +. diff --git a/Task/Perfect-numbers/Odin/perfect-numbers.odin b/Task/Perfect-numbers/Odin/perfect-numbers.odin new file mode 100644 index 0000000000..52b2b6ac8e --- /dev/null +++ b/Task/Perfect-numbers/Odin/perfect-numbers.odin @@ -0,0 +1,21 @@ +package perfect_numbers +import "core:fmt" +main :: proc() { + fmt.println("\nPerfect numbers from 1 to 100,000:\n") + for num in 1 ..< 100001 { + if divisor_sum(num) == num { + fmt.print("num:", num, "\n") + } + if num % 10000 == 0 { + fmt.print("Count:", num, "\n") + } + } +} +divisor_sum :: proc(number: int) -> int { + sum := 0 + for i in 1 ..< number { + if number % i == 0 { + sum += i} + } + return sum +} diff --git a/Task/Permutations-Derangements/EasyLang/permutations-derangements.easy b/Task/Permutations-Derangements/EasyLang/permutations-derangements.easy new file mode 100644 index 0000000000..48b56cd0d9 --- /dev/null +++ b/Task/Permutations-Derangements/EasyLang/permutations-derangements.easy @@ -0,0 +1,43 @@ +global list[] rlist[][] . +proc permlist k . . + if k >= len list[] + for i to len list[] + if i = list[i] + return + . + . + rlist[][] &= list[] + return + . + for i = k to len list[] + swap list[i] list[k] + permlist k + 1 + swap list[k] list[i] + . +. +# +proc derang n . r[][] . + rlist[][] = [ ] + list[] = [ ] + for i to n + list[] &= i + . + permlist 1 + r[][] = rlist[][] +. +r[][] = [ ] +derang 4 r[][] +print r[][] +# +func subfac n . + if n < 2 + return 1 - n + . + return (subfac (n - 1) + subfac (n - 2)) * (n - 1) +. +# +print "counted / calculated" +for n = 0 to 9 + derang n r[][] + print n & ": " & len r[][] & " " & subfac n +. diff --git a/Task/Permutations/EasyLang/permutations.easy b/Task/Permutations/EasyLang/permutations.easy index ea80f9b9db..cadd9844a5 100644 --- a/Task/Permutations/EasyLang/permutations.easy +++ b/Task/Permutations/EasyLang/permutations.easy @@ -1,12 +1,13 @@ proc permlist k . list[] . + if k = len list[] + print list[] + return + . for i = k to len list[] swap list[i] list[k] permlist k + 1 list[] swap list[k] list[i] . - if k = len list[] - print list[] - . . l[] = [ 1 2 3 ] permlist 1 l[] diff --git a/Task/Phrase-reversals/Insitux/phrase-reversals.insitux b/Task/Phrase-reversals/Insitux/phrase-reversals.insitux new file mode 100644 index 0000000000..212f71bb58 --- /dev/null +++ b/Task/Phrase-reversals/Insitux/phrase-reversals.insitux @@ -0,0 +1,5 @@ +(let phrase "rosetta code phrase reversal") + +(print (reverse phrase)) +(-> phrase (split " ") (map reverse) (join " ") print) +(-> phrase (split " ") reverse (join " ") print) diff --git a/Task/Pick-random-element/FutureBasic/pick-random-element.basic b/Task/Pick-random-element/FutureBasic/pick-random-element.basic new file mode 100644 index 0000000000..affb2c5ae2 --- /dev/null +++ b/Task/Pick-random-element/FutureBasic/pick-random-element.basic @@ -0,0 +1,7 @@ +random + +mda(0) = {0,1,2,3,4,5,6,7,8,9} + +print mda(rnd(10)-1) + +HandleEvents diff --git a/Task/Pick-random-element/Icon/pick-random-element.icon b/Task/Pick-random-element/Icon/pick-random-element-1.icon similarity index 100% rename from Task/Pick-random-element/Icon/pick-random-element.icon rename to Task/Pick-random-element/Icon/pick-random-element-1.icon diff --git a/Task/Pick-random-element/Icon/pick-random-element-2.icon b/Task/Pick-random-element/Icon/pick-random-element-2.icon new file mode 100644 index 0000000000..e9809c05b7 --- /dev/null +++ b/Task/Pick-random-element/Icon/pick-random-element-2.icon @@ -0,0 +1 @@ +(rand-pick (range 100)) diff --git a/Task/Pick-random-element/Joy/pick-random-element.joy b/Task/Pick-random-element/Joy/pick-random-element.joy new file mode 100644 index 0000000000..ec5286c158 --- /dev/null +++ b/Task/Pick-random-element/Joy/pick-random-element.joy @@ -0,0 +1,7 @@ +DEFINE pick_random == dup size rand swap rem at. + +(* initialize random number generator *) +time 89 * clock + srand + +["zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve"] +pick_random. diff --git a/Task/Plot-coordinate-pairs/EasyLang/plot-coordinate-pairs.easy b/Task/Plot-coordinate-pairs/EasyLang/plot-coordinate-pairs.easy index 20bdf5e187..310c247c68 100644 --- a/Task/Plot-coordinate-pairs/EasyLang/plot-coordinate-pairs.easy +++ b/Task/Plot-coordinate-pairs/EasyLang/plot-coordinate-pairs.easy @@ -34,9 +34,5 @@ linewidth 0.5 for i = 1 to n x = x[i] * 9 / stx + 10 y = y[i] / sty * 10 + 5 - if i = 1 - move x y - else - line x y - . + line x y . diff --git a/Task/Price-fraction/EasyLang/price-fraction.easy b/Task/Price-fraction/EasyLang/price-fraction.easy new file mode 100644 index 0000000000..d4b23f494f --- /dev/null +++ b/Task/Price-fraction/EasyLang/price-fraction.easy @@ -0,0 +1,21 @@ +n[] = [ 10 18 26 32 38 44 50 54 58 62 66 70 74 78 82 86 90 94 98 100 ] +func conv p . + cat = (p - 1) div 5 + 1 + return n[cat] +. +for in = 5 step 5 to 100 + if in = 100 + in$ = "1.00" + elif in < 10 + in$ = "0.0" & in + else + in$ = "0." & in + . + out = conv in + if out = 100 + out$ = "1.00" + else + out$ = "0." & out + . + print in$ & " -> " & out$ +. diff --git a/Task/Prime-decomposition/Quackery/prime-decomposition.quackery b/Task/Prime-decomposition/Quackery/prime-decomposition.quackery index 61188cdb18..e578e0368b 100644 --- a/Task/Prime-decomposition/Quackery/prime-decomposition.quackery +++ b/Task/Prime-decomposition/Quackery/prime-decomposition.quackery @@ -1,6 +1,10 @@ - [ [] swap + [ dup prime iff + nested done + [] swap dup times - [ [ dup i^ 2 + /mod + [ i^ 2 + prime + not if done + [ dup i^ 2 + /mod 0 = while nip dip [ i^ 2 + join ] @@ -8,5 +12,3 @@ drop dup 1 = if conclude ] drop ] is primefactors ( n --> [ ) - - 1047552 primefactors echo diff --git a/Task/RIPEMD-160/C++/ripemd-160.cpp b/Task/RIPEMD-160/C++/ripemd-160.cpp index 722a222404..77c5bd8b0b 100644 --- a/Task/RIPEMD-160/C++/ripemd-160.cpp +++ b/Task/RIPEMD-160/C++/ripemd-160.cpp @@ -11,27 +11,27 @@ class RIPEMD160 { public: std::string message_digest(const std::string& message) { std::vector state = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 }; - + std::vector bytes = add_padding(message); for ( uint64_t i = 0; i < bytes.size() / BLOCK_LENGTH; ++i ) { std::vector schedule(16, 0); for ( uint32_t j = 0; j < BLOCK_LENGTH; ++j ) { schedule[j / 4] |= ( bytes[i + j] ) << ( j % 4 * 8 ); } - + int32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; int32_t aa = state[0], bb = state[1], cc = state[2], dd = state[3], ee = state[4]; int32_t t = 0, tt = 0; - + for ( uint32_t j = 0; j < 80; ++j ) { uint32_t jj = j / 16; t = std::rotl(a + ff(jj + 1, b, c, d) + schedule[RL[j]] + KL[jj], SL[j]) + e; tt = std::rotl(aa + ff(5 - jj, bb, cc, dd) + schedule[RR[j]] + KR[jj], SR[j]) + ee; - + a = e; e = d; d = std::rotl(static_cast(c), 10); c = b; b = t; aa = ee; ee = dd; dd = std::rotl(static_cast(cc), 10); cc = bb; bb = tt; } - + t = state[1] + c + dd; state[1] = state[2] + d + ee; state[2] = state[3] + e + aa; @@ -39,7 +39,7 @@ public: state[4] = state[0] + b + cc; state[0] = t; } - + std::stringstream stream; for ( uint32_t i = 0; i < state.size() * 4; ++i ) { int8_t byte_value = static_cast(unsigned_right_shift(state[i / 4], i % 4 * 8)); @@ -49,43 +49,23 @@ public: } private: - const uint64_t TWO_POWER_32 = 4'294'967'296; - const uint32_t BLOCK_LENGTH = 64; - - const std::vector SR = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, - 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, - 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, - 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, - 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }; - - const std::vector SL = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, - 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, - 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, - 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, - 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 }; - - const std::vector RR = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, - 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, - 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, - 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, - 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 }; - - const std::vector RL = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, - 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, - 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, - 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 }; - - const std::vector KL = { 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e }; - const std::vector KR = { 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000 }; - - int32_t unsigned_right_shift(const int32_t& base, const int32_t& shift) { - if ( base == 0 || shift >= 32 ) { - return 0; + std::vector add_padding(const std::string& message) { + std::vector bytes(message.begin(), message.end()); + bytes.emplace_back(static_cast(0x80)); + + uint32_t padding = BLOCK_LENGTH - ( bytes.size() % BLOCK_LENGTH ); + if ( padding < 8 ) { + padding += BLOCK_LENGTH; } - return ( base > 0 ) ? base >> shift : ( base + TWO_POWER_32 ) >> shift; + bytes.resize(bytes.size() + padding - 8, static_cast(0x0)); + + const uint64_t bit_length = 8 * message.length(); + for ( uint32_t i = 0; i < 8; ++i ) { + bytes.emplace_back(static_cast( bit_length >> ( 8 * i ) )); + } + return bytes; } - + uint32_t ff(const uint32_t& group, const uint32_t& x, const uint32_t& y, const uint32_t& z) { uint32_t result; switch ( group ) { @@ -98,23 +78,45 @@ private: }; return result; } - - std::vector add_padding(const std::string& message) { - std::vector bytes(message.begin(), message.end()); - bytes.emplace_back(static_cast(0x80)); - - uint32_t padding = BLOCK_LENGTH - ( bytes.size() % BLOCK_LENGTH ); - if ( padding < 8 ) { - padding += BLOCK_LENGTH; + + int32_t unsigned_right_shift(const int32_t& base, const int32_t& shift) { + if ( shift < 0 || shift >= 32 ) { + throw std::invalid_argument("Shift must be in range 0..31: " + shift); } - bytes.resize(bytes.size() + padding - 8, static_cast(0x0)); - - const uint64_t bit_length = 8 * message.length(); - for ( uint32_t i = 0; i < 8; ++i ) { - bytes.emplace_back(static_cast( bit_length >> ( 8 * i ) )); + if ( base == 0 ) { + return 0; } - return bytes; + return ( base > 0 ) ? base >> shift : static_cast(base) >> shift; } + + const std::vector SR = { 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, + 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, + 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, + 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, + 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 }; + + const std::vector SL = { 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, + 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, + 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, + 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, + 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 }; + + const std::vector RR = { 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, + 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, + 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, + 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, + 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 }; + + const std::vector RL = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, + 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, + 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, + 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 }; + + const std::vector KL = { 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e }; + const std::vector KR = { 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000 }; + + const uint32_t BLOCK_LENGTH = 64; }; int main() { diff --git a/Task/RIPEMD-160/Java/ripemd-160-2.java b/Task/RIPEMD-160/Java/ripemd-160-2.java index 151733e7a5..5c025e6737 100644 --- a/Task/RIPEMD-160/Java/ripemd-160-2.java +++ b/Task/RIPEMD-160/Java/ripemd-160-2.java @@ -14,11 +14,11 @@ final class RIPEMD160 { public static String messageDigest(String aMessage) { int[] state = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 }; - byte[] bytes = addPadding(aMessage); + byte[] bytes = addPadding(aMessage); for ( int i = 0; i < bytes.length / BLOCK_LENGTH; i++ ) { int[] schedule = new int[16]; for ( int j = 0; j < BLOCK_LENGTH; j++ ) { - schedule[j / 4] |= ( bytes[i + j] & 0xff ) << ( j % 4 * 8 ); + schedule[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( j % 4 * 8 ); } int a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; @@ -29,7 +29,7 @@ final class RIPEMD160 { int jj = j / 16; t = Integer.rotateLeft(a + ff(jj + 1, b, c, d) + schedule[RL[j]] + KL[jj], SL[j]) + e; tt = Integer.rotateLeft(aa + ff(5 - jj, bb, cc, dd) + schedule[RR[j]] + KR[jj], SR[j]) + ee; - + a = e; e = d; d = Integer.rotateLeft(c, 10); c = b; b = t; aa = ee; ee = dd; dd = Integer.rotateLeft(cc, 10); cc = bb; bb = tt; } @@ -40,7 +40,7 @@ final class RIPEMD160 { state[3] = state[4] + a + bb; state[4] = state[0] + b + cc; state[0] = t; - } + } String result = ""; for ( int i = 0; i < state.length * 4; i++ ) { @@ -52,16 +52,15 @@ final class RIPEMD160 { private static byte[] addPadding(String aMessage) { byte[] bytes = aMessage.getBytes(StandardCharsets.UTF_8); bytes = Arrays.copyOf(bytes, bytes.length + 1); - bytes[bytes.length - 1] = (byte) 0x80; - - final int length = aMessage.length(); - int padding = BLOCK_LENGTH - ( (length + 1 ) % BLOCK_LENGTH ); + bytes[bytes.length - 1] = (byte) 0x80; + + int padding = BLOCK_LENGTH - ( bytes.length % BLOCK_LENGTH ); if ( padding < 8 ) { padding += BLOCK_LENGTH; } bytes = Arrays.copyOf(bytes, bytes.length + padding); - final long bitLength = 8 * length; + final long bitLength = aMessage.length() * 8; for ( int i = 0; i < 8; i++ ) { bytes[bytes.length - 8 + i] = (byte) ( bitLength >>> ( 8 * i ) ); } diff --git a/Task/Rare-numbers/EasyLang/rare-numbers.easy b/Task/Rare-numbers/EasyLang/rare-numbers.easy new file mode 100644 index 0000000000..36557feaba --- /dev/null +++ b/Task/Rare-numbers/EasyLang/rare-numbers.easy @@ -0,0 +1,20 @@ +fastfunc next n . + while 1 = 1 + n += 1 + h = n + nrev = 0 + while h > 0 + nrev = nrev * 10 + h mod 10 + h = h div 10 + . + if sqrt (n + nrev) mod 1 = 0 + if n - nrev >= 1 and sqrt (n - nrev) mod 1 = 0 + return n + . + . + . +. +for cnt to 5 + n = next n + print n +. diff --git a/Task/Rare-numbers/Lua/rare-numbers.lua b/Task/Rare-numbers/Lua/rare-numbers.lua new file mode 100644 index 0000000000..b27b95b639 --- /dev/null +++ b/Task/Rare-numbers/Lua/rare-numbers.lua @@ -0,0 +1,46 @@ +do -- find the first five rare numbers + + local function revn ( na ) + local n, r = na, 0 + while n > 0 do + r = r * 10 r = r + ( n % 10 ) + n = math.floor( n / 10 ) + end + return r + end -- revn + + local nd, count, lim, n = 2, 0, 90, 20 + local oddNd = nd % 2 == 1 + while true do + n = n + 1 + local r = revn( n ) + if r < n then + local s, d = n + r, n - r + local tryThis = false + if oddNd + then tryThis = d % 1089 == 0 + else tryThis = s % 121 == 0 + end + if tryThis then + local rootS = math.sqrt( s ) + if rootS == math.floor(rootS ) + then + local rootD = math.sqrt( d ) + if rootD == math.floor( rootD ) + then + count = count + 1 + io.write( count, ": ", n, "\n" ) + if count >= 5 then os.exit() end + end + end + end + if n == lim + then + lim = lim * 10 + nd = nd + 1 + oddNd = not oddNd + n = math.floor( lim / 9 ) * 2 + end + end + end +end diff --git a/Task/Reflection-List-methods/Go/reflection-list-methods.go b/Task/Reflection-List-methods/Go/reflection-list-methods-1.go similarity index 100% rename from Task/Reflection-List-methods/Go/reflection-list-methods.go rename to Task/Reflection-List-methods/Go/reflection-list-methods-1.go diff --git a/Task/Reflection-List-methods/Go/reflection-list-methods-2.go b/Task/Reflection-List-methods/Go/reflection-list-methods-2.go new file mode 100644 index 0000000000..a139324aca --- /dev/null +++ b/Task/Reflection-List-methods/Go/reflection-list-methods-2.go @@ -0,0 +1,10 @@ +; lists all built-in and user-defined functions, including those within variables +(-> (symbols) + (map eval) + (filter (comp type-of (= "func")))) + +; lists only user-defined functions, including those within variables +(-> (symbols) + (map eval) + (filter (comp type-of (= "func"))) + (remove about)) diff --git a/Task/Repunit-primes/Quackery/repunit-primes.quackery b/Task/Repunit-primes/Quackery/repunit-primes.quackery new file mode 100644 index 0000000000..e5d996c7dc --- /dev/null +++ b/Task/Repunit-primes/Quackery/repunit-primes.quackery @@ -0,0 +1,19 @@ + [ base put + 1 temp put + [] 1 1000 times + [ temp share prime if + [ dup prime if + [ dip [ i^ 1+ join ] ] ] + base share * 1+ + 1 temp tally ] + drop + temp release + base release ] is repunitprimes ( n --> [ ) + + 15 times + [ i^ 2 + + dup 10 < if sp + dup echo + say ": " + repunitprimes echo + cr ] diff --git a/Task/Reverse-a-string/Io/reverse-a-string.io b/Task/Reverse-a-string/Io/reverse-a-string-1.io similarity index 100% rename from Task/Reverse-a-string/Io/reverse-a-string.io rename to Task/Reverse-a-string/Io/reverse-a-string-1.io diff --git a/Task/Reverse-a-string/Io/reverse-a-string-2.io b/Task/Reverse-a-string/Io/reverse-a-string-2.io new file mode 100644 index 0000000000..681e6fa190 --- /dev/null +++ b/Task/Reverse-a-string/Io/reverse-a-string-2.io @@ -0,0 +1 @@ +(reverse "hello") diff --git a/Task/Rot-13/Insitux/rot-13.insitux b/Task/Rot-13/Insitux/rot-13.insitux index 7dddcffd2c..7cb2596f88 100644 --- a/Task/Rot-13/Insitux/rot-13.insitux +++ b/Task/Rot-13/Insitux/rot-13.insitux @@ -8,5 +8,5 @@ (function ROT-13 text (.. str (map ROT-13-char text))) -(ROT-13 "The Quick Brown Fox Jumped Over The Lazy Dog!") -;returns "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt!" +(ROT-13 "The Quick Brown Fox Jumps Over The Lazy Dog!") +;returns "Gur Dhvpx Oebja Sbk Whzcf Bire Gur Ynml Qbt!" diff --git a/Task/Rot-13/Standard-ML/rot-13.ml b/Task/Rot-13/Standard-ML/rot-13-1.ml similarity index 100% rename from Task/Rot-13/Standard-ML/rot-13.ml rename to Task/Rot-13/Standard-ML/rot-13-1.ml diff --git a/Task/Rot-13/Standard-ML/rot-13-2.ml b/Task/Rot-13/Standard-ML/rot-13-2.ml new file mode 100644 index 0000000000..a580a96361 --- /dev/null +++ b/Task/Rot-13/Standard-ML/rot-13-2.ml @@ -0,0 +1,4 @@ +fun rot13stdin () = + case (TextIO.inputLine TextIO.stdIn) + of NONE => () + | SOME(s) => (print (rot13 s); rot13stdin ()); diff --git a/Task/Runtime-evaluation/HicEst/runtime-evaluation.hicest b/Task/Runtime-evaluation/HicEst/runtime-evaluation-1.hicest similarity index 100% rename from Task/Runtime-evaluation/HicEst/runtime-evaluation.hicest rename to Task/Runtime-evaluation/HicEst/runtime-evaluation-1.hicest diff --git a/Task/Runtime-evaluation/HicEst/runtime-evaluation-2.hicest b/Task/Runtime-evaluation/HicEst/runtime-evaluation-2.hicest new file mode 100644 index 0000000000..35d7eae088 --- /dev/null +++ b/Task/Runtime-evaluation/HicEst/runtime-evaluation-2.hicest @@ -0,0 +1,5 @@ +(var x 123) +[ + (eval "(var y 100) (+ x y)") + y +] diff --git a/Task/SHA-1/C++/sha-1.cpp b/Task/SHA-1/C++/sha-1-1.cpp similarity index 100% rename from Task/SHA-1/C++/sha-1.cpp rename to Task/SHA-1/C++/sha-1-1.cpp diff --git a/Task/SHA-1/C++/sha-1-2.cpp b/Task/SHA-1/C++/sha-1-2.cpp new file mode 100644 index 0000000000..5efd04ae81 --- /dev/null +++ b/Task/SHA-1/C++/sha-1-2.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include + +class SHA1 { +public: + std::string message_digest(const std::string& message) { + std::vector state = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 }; + + const std::vector bytes = add_padding(message); + for ( uint64_t i = 0; i < bytes.size() / BLOCK_LENGTH; ++i ) { + std::vector values(80, 0); + for ( uint32_t j = 0; j < BLOCK_LENGTH; ++j ) { + values[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( ( 3 - j % 4 ) * 8 ); + } + for ( uint32_t j = 16; j < 80; ++j ) { + uint32_t value = values[j - 3] ^ values[j - 8] ^ values[j - 14] ^ values[j - 16]; + values[j] = std::rotl(value, 1); + } + + uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; + uint32_t f = 0, k = 0; + for ( uint32_t j = 0; j < 80; ++j ) { + switch ( j / 20 ) { + case 0 : { f = ( b & c ) | ( ~b & d ); k = 0x5a827999; break; } + case 1 : { f = b ^ c ^ d; k = 0x6ed9eba1; break; } + case 2 : { f = ( b & c ) | ( b & d ) | ( c & d ); k = 0x8f1bbcdc; break; } + case 3 : { f = b ^ c ^ d; k = 0xca62c1d6; break; } + } + + uint32_t temp = std::rotl(a, 5) + f + e + k + values[j]; + e = d; d = c; c = std::rotl(b, 30); b = a; a = temp; + } + + state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; + } + + std::stringstream stream; + for ( uint32_t i = 0; i < 20; ++i ) { + int8_t byte_value = static_cast(state[i / 4] >> ( 24 - ( i % 4 ) * 8)); + stream << std::setfill('0') << std::setw(2) << std::hex << ( byte_value & 0xff ); + } + return stream.str(); + } + +private: + std::vector add_padding(const std::string& message) { + std::vector bytes(message.begin(), message.end()); + bytes.emplace_back(static_cast(0x80)); + + uint32_t padding = BLOCK_LENGTH - ( bytes.size() % BLOCK_LENGTH ); + if ( padding < 8 ) { + padding += BLOCK_LENGTH; + } + bytes.resize(bytes.size() + padding - 8, static_cast(0x0)); + + const uint64_t bit_length = 8 * message.length(); + for ( int32_t i = 7; i >= 0; --i ) { + bytes.emplace_back(static_cast(bit_length >> ( 8 * i ))); + } + return bytes; + } + + const uint32_t BLOCK_LENGTH = 64; +}; + +int main() { + SHA1 sha1; + std::cout << sha1.message_digest("Rosetta Code") << std::endl; +} diff --git a/Task/SHA-1/Java/sha-1.java b/Task/SHA-1/Java/sha-1.java new file mode 100644 index 0000000000..98030f5393 --- /dev/null +++ b/Task/SHA-1/Java/sha-1.java @@ -0,0 +1,71 @@ +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +public final class SHA1Task { + + public static void main(String[] args) { + System.out.println(SHA1.messageDigest("Rosetta Code")); + } + +} + +final class SHA1 { + + public static String messageDigest(String message) { + int[] state = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 }; + + byte[] bytes = addPadding(message); + for ( int i = 0; i < bytes.length / BLOCK_LENGTH; i++ ) { + int[] values = new int[80]; + for ( int j = 0; j < BLOCK_LENGTH; j++ ) { + values[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( ( 3 - j % 4 ) * 8 ); + } + for ( int j = 16; j < 80; j++ ) { + values[j] = Integer.rotateLeft(values[j - 3] ^ values[j - 8] ^ values[j - 14] ^ values[j - 16], 1); + } + + int a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; + int f = 0, k = 0; + for ( int j = 0; j < 80; j++ ) { + switch ( j / 20 ) { + case 0 -> { f = ( b & c ) | ( ~b & d ); k = 0x5a827999; } + case 1 -> { f = b ^ c ^ d; k = 0x6ed9eba1; } + case 2 -> { f = ( b & c ) | ( b & d ) | ( c & d ); k = 0x8f1bbcdc; } + case 3 -> { f = b ^ c ^ d; k = 0xca62c1d6; } + } + + int temp = Integer.rotateLeft(a, 5) + f + e + k + values[j]; + e = d; d = c; c = Integer.rotateLeft(b, 30); b = a; a = temp; + } + + state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; + } + + StringBuilder result = new StringBuilder(); + for ( int i = 0; i < 20; i++ ) { + result.append(String.format("%02x", ( state[i / 4] >>> 24 - ( i % 4 ) * 8 ) & 0xFF )); + } + return result.toString(); + } + + private static byte[] addPadding(String message) { + byte[] bytes = message.getBytes(StandardCharsets.UTF_8); + bytes = Arrays.copyOf(bytes, bytes.length + 1); + bytes[bytes.length - 1] = (byte) 0x80; + + int padding = BLOCK_LENGTH - ( bytes.length % BLOCK_LENGTH ); + if ( padding < 8 ) { + padding += BLOCK_LENGTH; + } + bytes = Arrays.copyOf(bytes, bytes.length + padding); + + final long bitLength = message.length() * 8; + for ( int i = 0; i < 8; i++ ) { + bytes[bytes.length - 1 - i] = (byte) ( bitLength >>> ( 8 * i ) ); + } + return bytes; + } + + private static final int BLOCK_LENGTH = 64; + +} diff --git a/Task/SHA-256/C++/sha-256.cpp b/Task/SHA-256/C++/sha-256-1.cpp similarity index 100% rename from Task/SHA-256/C++/sha-256.cpp rename to Task/SHA-256/C++/sha-256-1.cpp diff --git a/Task/SHA-256/C++/sha-256-2.cpp b/Task/SHA-256/C++/sha-256-2.cpp new file mode 100644 index 0000000000..35d2a6b832 --- /dev/null +++ b/Task/SHA-256/C++/sha-256-2.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +#include + +class SHA256 { +public: + std::string message_digest(const std::string& message) { + std::vector hash = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; + + const std::vector bytes = add_padding(message); + for ( uint64_t i = 0; i < bytes.size() / BLOCK_LENGTH; ++i ) { + std::vector words(BLOCK_LENGTH, 0); + for ( int32_t j = 0; j < BLOCK_LENGTH; ++j ) { + words[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( ( 3 - j % 4 ) * 8 ); + } + for ( int32_t j = 16; j < BLOCK_LENGTH; j++ ) { + words[j] = sigma(3, words[j - 2]) + words[j - 7] + sigma(2, words[j - 15]) + words[j - 16]; + } + + int32_t a = hash[0], b = hash[1], c = hash[2], d = hash[3], + e = hash[4], f = hash[5], g = hash[6], h = hash[7]; + + for ( int32_t j = 0; j < BLOCK_LENGTH; ++j ) { + int32_t t = h + sigma(1, e) + ch(e, f, g) + kk[j] + words[j]; + int32_t tt = sigma(0, a) + maj(a, b, c); + h = g; g = f; f = e; + e = d + t; + d = c; c = b; b = a; + a = t + tt; + } + + hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; + hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; + } + + std::stringstream stream; + for ( int32_t i = 0; i < BLOCK_LENGTH; ++i ) { + int8_t byte_value = static_cast(hash[i / 8] >> ( 7 - i % 8 ) * 4); + stream << std::hex << ( byte_value & 0xf ); + } + return stream.str(); + } + +private: + std::vector add_padding(const std::string& message) { + std::vector bytes(message.begin(), message.end()); + bytes.emplace_back(static_cast(0x80)); + + uint32_t padding = BLOCK_LENGTH - ( bytes.size() % BLOCK_LENGTH ); + if ( padding < 8 ) { + padding += BLOCK_LENGTH; + } + bytes.resize(bytes.size() + padding - 8, static_cast(0x0)); + + const uint64_t bit_length = 8 * message.length(); + for ( int32_t i = 7; i >= 0; --i ) { + bytes.emplace_back(static_cast(bit_length >> ( 8 * i ))); + } + return bytes; + } + + int32_t sigma(const uint32_t& group, const uint32_t& x) { + int32_t result; + switch ( group ) { + case 0 : result = std::rotr(x, 2) ^ std::rotr(x, 13) ^ std::rotr(x, 22); break; + case 1 : result = std::rotr(x, 6) ^ std::rotr(x, 11) ^ std::rotr(x, 25); break; + case 2 : result = std::rotr(x, 7) ^ std::rotr(x, 18) ^ ( x >> 3 ); break; + case 3 : result = std::rotr(x, 17) ^ std::rotr(x, 19) ^ ( x >> 10 ); break; + default : throw std::invalid_argument("Unexpected argument for sigma: " + std::to_string(group)); + } + return result; + } + + int32_t ch(const int32_t& x, const int32_t y, const int32_t z) { + return ( x & y ) ^ ( ~x & z ); + } + + int32_t maj(const int32_t& x, const int32_t y, const int32_t z) { + return ( x & y ) ^ ( x & z ) ^ ( y & z ); + } + + const std::vector kk = { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; + + const int32_t BLOCK_LENGTH = 64; +}; + +int main() { + SHA256 sha256; + std::cout << sha256.message_digest("Rosetta code") << std::endl; +} diff --git a/Task/SHA-256/Java/sha-256.java b/Task/SHA-256/Java/sha-256.java new file mode 100644 index 0000000000..5331ce7af5 --- /dev/null +++ b/Task/SHA-256/Java/sha-256.java @@ -0,0 +1,99 @@ +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +public final class SHA256Task { + + public static void main(String[] args) { + System.out.println(SHA256.messageDigest("Rosetta code")); + } + +} + +final class SHA256 { + + public static String messageDigest(String message) { + int[] hash = { 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 }; + + final byte[] bytes = addPadding(message); + for ( int i = 0; i < bytes.length / BLOCK_LENGTH; i++ ) { + int[] words = new int[BLOCK_LENGTH]; + for ( int j = 0; j < BLOCK_LENGTH; j++ ) { + words[j / 4] |= ( bytes[i * BLOCK_LENGTH + j] & 0xff ) << ( ( 3 - j % 4 ) * 8 ); + } + for ( int j = 16; j < BLOCK_LENGTH; j++ ) { + words[j] = sigma(3, words[j - 2]) + words[j - 7] + sigma(2, words[j - 15]) + words[j - 16]; + } + + int a = hash[0], b = hash[1], c = hash[2], d = hash[3], + e = hash[4], f = hash[5], g = hash[6], h = hash[7]; + + for ( int j = 0; j < BLOCK_LENGTH; j++ ) { + int t = h + sigma(1, e) + ch(e, f, g) + kk[j] + words[j]; + int tt = sigma(0, a) + maj(a, b, c); + h = g; g = f; f = e; + e = d + t; + d = c; c = b; b = a; + a = t + tt; + } + + hash[0] += a; hash[1] += b; hash[2] += c; hash[3] += d; + hash[4] += e; hash[5] += f; hash[6] += g; hash[7] += h; + } + + StringBuilder result = new StringBuilder(); + for ( int i = 0; i < BLOCK_LENGTH; i++ ) { + result.append(String.format("%1x", ( hash[i / 8] >>> ( 7 - i % 8 ) * 4 ) & 0xf )); + } + return result.toString(); + } + + private static byte[] addPadding(String message) { + byte[] bytes = message.getBytes(StandardCharsets.UTF_8); + bytes = Arrays.copyOf(bytes, bytes.length + 1); + bytes[bytes.length - 1] = (byte) 0x80; + + int padding = BLOCK_LENGTH - ( bytes.length % BLOCK_LENGTH ); + if ( padding < 8 ) { + padding += BLOCK_LENGTH; + } + bytes = Arrays.copyOf(bytes, bytes.length + padding); + + final long bitLength = message.length() * 8; + for ( int i = 0; i < 8; i++ ) { + bytes[bytes.length - 1 - i] = (byte) ( bitLength >>> ( 8 * i ) ); + } + return bytes; + } + + private static int sigma(int group, int x) { + return switch ( group ) { + case 0 -> Integer.rotateRight(x, 2) ^ Integer.rotateRight(x, 13) ^ Integer.rotateRight(x, 22); + case 1 -> Integer.rotateRight(x, 6) ^ Integer.rotateRight(x, 11) ^ Integer.rotateRight(x, 25); + case 2 -> Integer.rotateRight(x, 7) ^ Integer.rotateRight(x, 18) ^ ( x >>> 3 ); + case 3 -> Integer.rotateRight(x, 17) ^ Integer.rotateRight(x, 19) ^ ( x >>> 10 ); + default -> throw new AssertionError("Unexpected argument for sigma: " + group); + }; + } + + private static int ch(int x, int y, int z) { + return ( x & y ) ^ ( ~x & z ); + } + + private static int maj(int x, int y, int z) { + return ( x & y ) ^ ( x & z ) ^ ( y & z ); + } + + private static final int[] kk = new int[] { + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; + + private static final int BLOCK_LENGTH = 64; + +} diff --git a/Task/Semiprime/EasyLang/semiprime.easy b/Task/Semiprime/EasyLang/semiprime.easy new file mode 100644 index 0000000000..78f535f824 --- /dev/null +++ b/Task/Semiprime/EasyLang/semiprime.easy @@ -0,0 +1,20 @@ +func semiprime n . + a = 2 + while c < 3 and n > 1 + if n mod a = 0 + n /= a + c += 1 + else + a += 1 + . + . + if c = 2 + return 1 + . + return 0 +. +for i = 1 to 100 + if semiprime i = 1 + write i & " " + . +. diff --git a/Task/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors/Maxima/sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors.maxima b/Task/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors/Maxima/sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors.maxima new file mode 100644 index 0000000000..9fd79d8927 --- /dev/null +++ b/Task/Sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors/Maxima/sequence:-smallest-number-greater-than-previous-term-with-exactly-n-divisors.maxima @@ -0,0 +1,6 @@ +sngptend(n):=block([i:1,count:1,result:[]], + while count<=n do (if length(listify(divisors(i)))=count then (result:endcons(i,result),count:count+1),i:i+1), + result)$ + +/* Test case */ +sngptend(15); diff --git a/Task/Sequence:-smallest-number-with-exactly-n-divisors/EasyLang/sequence:-smallest-number-with-exactly-n-divisors.easy b/Task/Sequence:-smallest-number-with-exactly-n-divisors/EasyLang/sequence:-smallest-number-with-exactly-n-divisors.easy new file mode 100644 index 0000000000..f166a4adc5 --- /dev/null +++ b/Task/Sequence:-smallest-number-with-exactly-n-divisors/EasyLang/sequence:-smallest-number-with-exactly-n-divisors.easy @@ -0,0 +1,26 @@ +func cntdiv n . + i = 1 + while i <= sqrt n + if n mod i = 0 + cnt += 1 + if i <> sqrt n + cnt += 1 + . + . + i += 1 + . + return cnt +. +len seq[] 15 +i = 1 +while n < 15 + k = cntdiv i + if k <= 15 and seq[k] = 0 + seq[k] = i + n += 1 + . + i += 1 +. +for v in seq[] + print v +. diff --git a/Task/Short-circuit-evaluation/EasyLang/short-circuit-evaluation.easy b/Task/Short-circuit-evaluation/EasyLang/short-circuit-evaluation.easy new file mode 100644 index 0000000000..8df6cab727 --- /dev/null +++ b/Task/Short-circuit-evaluation/EasyLang/short-circuit-evaluation.easy @@ -0,0 +1,27 @@ +func a x . + print "->a: " & x + return x +. +func b x . + print "->b: " & x + return x +. +print "1 and 1" +if a 1 = 1 and b 1 = 1 + print "-> true" +. +print "" +print "1 or 1" +if a 1 = 1 or b 1 = 1 + print "-> true" +. +print "" +print "0 and 1" +if a 0 = 1 and b 1 = 1 + print "-> true" +. +print "" +print "0 or 1" +if a 0 = 1 or b 1 = 1 + print "-> true" +. diff --git a/Task/Short-circuit-evaluation/Insitux/short-circuit-evaluation.insitux b/Task/Short-circuit-evaluation/Insitux/short-circuit-evaluation.insitux new file mode 100644 index 0000000000..fec0306420 --- /dev/null +++ b/Task/Short-circuit-evaluation/Insitux/short-circuit-evaluation.insitux @@ -0,0 +1,9 @@ +(let a (fn (print-str "a ") %) + b (fn (print-str "b ") %) + f (pad-right " " 6)) + +(for i [true false] j [true false] + (print-str (f i) "OR " (f j) " = ") + (print (or (a i) (b j))) + (print-str (f i) "AND " (f j) " = ") + (print (and (a i) (b j)))) diff --git a/Task/Show-ASCII-table/Haskell/show-ascii-table.hs b/Task/Show-ASCII-table/Haskell/show-ascii-table-1.hs similarity index 100% rename from Task/Show-ASCII-table/Haskell/show-ascii-table.hs rename to Task/Show-ASCII-table/Haskell/show-ascii-table-1.hs diff --git a/Task/Show-ASCII-table/Haskell/show-ascii-table-2.hs b/Task/Show-ASCII-table/Haskell/show-ascii-table-2.hs new file mode 100644 index 0000000000..ba6726d3a5 --- /dev/null +++ b/Task/Show-ASCII-table/Haskell/show-ascii-table-2.hs @@ -0,0 +1,7 @@ +(-> (for i (range 16) + j (range (+ i 32) 128 16) + (let k (match j 32 "Spc" 127 "Del" (str (char-code j) " "))) + (strn ((< j 100) " ") j " : " k)) + (partition 6) + (map (join " ")) + (join "\n")) diff --git a/Task/Show-the-epoch/Java/show-the-epoch.java b/Task/Show-the-epoch/Java/show-the-epoch-1.java similarity index 100% rename from Task/Show-the-epoch/Java/show-the-epoch.java rename to Task/Show-the-epoch/Java/show-the-epoch-1.java diff --git a/Task/Show-the-epoch/Java/show-the-epoch-2.java b/Task/Show-the-epoch/Java/show-the-epoch-2.java new file mode 100644 index 0000000000..35eaccdcdc --- /dev/null +++ b/Task/Show-the-epoch/Java/show-the-epoch-2.java @@ -0,0 +1,10 @@ +import java.time.LocalDateTime; +import java.time.ZoneOffset; + +public final class ShowTheEpoch { + + public static void main(String[] args) { + System.out.println(LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC)); + } + +} diff --git a/Task/Sieve-of-Eratosthenes/Julia/sieve-of-eratosthenes-2.julia b/Task/Sieve-of-Eratosthenes/Julia/sieve-of-eratosthenes-2.julia index 54f618a7e0..117fd90794 100644 --- a/Task/Sieve-of-Eratosthenes/Julia/sieve-of-eratosthenes-2.julia +++ b/Task/Sieve-of-Eratosthenes/Julia/sieve-of-eratosthenes-2.julia @@ -1,16 +1,9 @@ -function sieve(n :: Int) - isprime = trues(n) - isprime[1] = false +function sieve(n::Integer) + primes = fill(true, n) + primes[1] = false for p in 2:n - if isprime[p] - j = p * p - if j > n - return findall(isprime) - else - for k in j:p:n - isprime[k] = false - end - end - end + primes[p] || continue + primes[p .* (2:n÷p)] .= false end + findall(primes) end diff --git a/Task/Simple-turtle-graphics/IS-BASIC/simple-turtle-graphics.basic b/Task/Simple-turtle-graphics/IS-BASIC/simple-turtle-graphics.basic index b4a0650529..36739181f3 100644 --- a/Task/Simple-turtle-graphics/IS-BASIC/simple-turtle-graphics.basic +++ b/Task/Simple-turtle-graphics/IS-BASIC/simple-turtle-graphics.basic @@ -1,8 +1,8 @@ 100 PROGRAM "Turtle.bas" 110 OPTION ANGLE DEGREES 120 GRAPHICS HIRES 4 -130 CALL HOUSE(0,200,200) -140 SET INK 2:CALL CHART(250,200,60) +130 CALL HOUSE(200,200,200) +140 SET INK 2:CALL CHART(450,200,1000,700) 150 DEF HOUSE(X,Y,L) 160 PLOT X,Y,ANGLE 0; 170 FOR I=1 TO 4 @@ -10,13 +10,20 @@ 190 NEXT 200 PLOT LEFT 60;FORWARD L;RIGHT 120;FORWARD L;X,Y, 210 END DEF -220 DEF CHART(X,Y,L) -230 PLOT X,Y, +220 DEF CHART(X,Y,X1,Y1) +230 LET PC,MX=0 240 DO 250 READ IF MISSING EXIT DO:Z -260 PLOT ANGLE 90;FORWARD Z;RIGHT 90;FORWARD L;RIGHT 90;FORWARD Z;RIGHT 90;FORWARD L -270 PLOT ANGLE 0;FORWARD L -280 LOOP -290 PLOT X,Y, -300 END DEF -310 DATA 90,60,300,200,90 +260 LET PC=PC+1:LET MX=MAX(MX,Z) +270 LOOP +280 RESTORE +290 LET L=(X1-X)/PC:LET MX=(Y1-Y)/MX +300 PLOT X,Y, +310 DO +320 READ IF MISSING EXIT DO:Z +330 PLOT ANGLE 90;FORWARD Z*MX;RIGHT 90;FORWARD L;RIGHT 90;FORWARD Z*MX;RIGHT 90;FORWARD L +340 PLOT ANGLE 0;FORWARD L +350 LOOP +360 PLOT X,Y, +370 END DEF +380 DATA 90,60,300,200,90 diff --git a/Task/Sisyphus-sequence/EasyLang/sisyphus-sequence.easy b/Task/Sisyphus-sequence/EasyLang/sisyphus-sequence.easy new file mode 100644 index 0000000000..27988008d1 --- /dev/null +++ b/Task/Sisyphus-sequence/EasyLang/sisyphus-sequence.easy @@ -0,0 +1,35 @@ +func isprim num . + if num mod 2 = 0 and num > 2 + return 0 + . + i = 3 + while i <= sqrt num + if num mod i = 0 + return 0 + . + i += 2 + . + return 1 +. +prim = 1 +proc nextprim . . + repeat + prim += 1 + until isprim prim = 1 + . +. +numfmt 0 4 +n = 1 +write n +for i = 2 to 100 + if n mod 2 <> 0 + nextprim + n += prim + else + n /= 2 + . + write n + if i mod 10 = 0 + print "" + . +. diff --git a/Task/Sisyphus-sequence/Java/sisyphus-sequence.java b/Task/Sisyphus-sequence/Java/sisyphus-sequence.java new file mode 100644 index 0000000000..f5b64e4226 --- /dev/null +++ b/Task/Sisyphus-sequence/Java/sisyphus-sequence.java @@ -0,0 +1,156 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public final class SisyphusSequence { + + public static void main(String[] args) { + final long limit = 100_000_000; + SisyphusIterator iterator = new SisyphusIterator(1_000_000_000_000L); + System.out.println("The first 100 members of the Sisyphus sequence are:"); + int[] found = new int[250]; + long next = 0; + long count = 0; + int target = 1_000; + + while ( target <= limit ) { + count += 1; + next = iterator.next(); + if ( next < 250 ) { + found[(int) next]++; + } + if ( count <= 100 ) { + System.out.print(String.format("%3d%s", next, ( count % 10 == 0 ? "\n" : " "))); + if ( count == 100 ) { + System.out.println(); + } + } else if ( count == target ) { + target *= 10; + System.out.println(String.format("%11d%s%11d%s%10d", + target, "th member is ", next, " and highest prime needed is ", iterator.getPrime())); + } + } + + display(found, 0, target, "These numbers under 250 occur the most in the first ", ""); + + final int max = Arrays.stream(found).max().orElseThrow(); + display(found, max, target, + "These numbers under 250 occur the most in the first ", "all occur " + max + " times"); + + while ( next != 36 ) { + count += 1; + next = iterator.next(); + } + System.out.println(); + System.out.println(count + "th member is " + next + " and highest prime needed is " + iterator.getPrime()); + } + + private static void display(int[] found, int search, int target, String prefix, String suffix) { + System.out.println(); + System.out.println(prefix + target + " terms:"); + for ( int i = 1; i < found.length; i++ ) { + if ( found[i] == search ) { + System.out.print(i + " "); + } + } + System.out.println(suffix); + } + +} + +final class SisyphusIterator { + + public SisyphusIterator(long limit) { + previous = 2; + prime = 0; + primeIterator = new SegmentedPrimeIterator(limit); + } + + public long next() { + if ( ( previous & 1 ) == 0 ) { + previous >>= 1; + } else { + prime = primeIterator.next(); + previous += prime; + } + return previous; + } + + public long getPrime() { + return prime; + } + + private long previous; + private long prime; + private SegmentedPrimeIterator primeIterator; + +} + +final class SegmentedPrimeIterator { + + public SegmentedPrimeIterator(long limit) { + squareRoot = (int) Math.sqrt(limit); + high = squareRoot; + smallSieve(squareRoot); + } + + public long next() { + if ( index == primes.size() ) { + index = 0; + segmentedSieve(); + } + return primes.get(index++); + } + + private void segmentedSieve() { + low += squareRoot; + high += squareRoot; + + boolean[] markedPrime = new boolean[squareRoot]; + Arrays.fill(markedPrime, true); + + for ( int i = 0; i < smallPrimes.size(); i++ ) { + long lowLimit = ( low / smallPrimes.get(i) ) * smallPrimes.get(i); + if ( lowLimit < low ) { + lowLimit += smallPrimes.get(i); + } + + for ( long j = lowLimit; j < high; j += smallPrimes.get(i) ) { + markedPrime[(int) ( j - low )] = false; + } + } + + primes.clear(); + for ( long i = low; i < high; i++ ) { + if ( markedPrime[(int) ( i - low )] ) { + primes.add(i); + } + } + } + + private void smallSieve(int squareRoot) { + boolean[] markedPrime = new boolean[squareRoot + 1]; + Arrays.fill(markedPrime, true); + + for ( int p = 2; p * p <= squareRoot; p++ ) { + if ( markedPrime[p] ) { + for ( int i = p * p; i <= squareRoot; i += p ) { + markedPrime[i] = false; + } + } + } + + for ( int p = 2; p <= squareRoot; p++ ) { + if ( markedPrime[p] ) { + primes.add((long) p); + } + } + smallPrimes.addAll(primes); + } + + private int index, squareRoot; + private long low, high; + private List primes = new ArrayList(); + private List smallPrimes = new ArrayList(); + +} diff --git a/Task/Sleep/EasyLang/sleep.easy b/Task/Sleep/EasyLang/sleep.easy new file mode 100644 index 0000000000..db1d658791 --- /dev/null +++ b/Task/Sleep/EasyLang/sleep.easy @@ -0,0 +1,5 @@ +print "How many seconds should I sleep? " +sec = number input +print "Sleeping ..." +sleep sec +print "Awake!" diff --git a/Task/Sleep/Java/sleep.java b/Task/Sleep/Java/sleep-1.java similarity index 100% rename from Task/Sleep/Java/sleep.java rename to Task/Sleep/Java/sleep-1.java diff --git a/Task/Sleep/Java/sleep-2.java b/Task/Sleep/Java/sleep-2.java new file mode 100644 index 0000000000..dfb7c6f7f4 --- /dev/null +++ b/Task/Sleep/Java/sleep-2.java @@ -0,0 +1,22 @@ +import java.util.InputMismatchException; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; + +public final class Sleep { + + public static void main(String[] args) { + try { + System.out.println("Enter time to sleep in milliseconds:"); + Scanner scanner = new Scanner(System.in); + final int delay = scanner.nextInt(); + scanner.close(); + + System.out.println("Sleeping..."); + TimeUnit.MILLISECONDS.sleep(delay); + System.out.println("Awake!"); + } catch (InputMismatchException | InterruptedException exception) { + exception.printStackTrace(System.err);; + } + } + +} diff --git a/Task/Smarandache-Wellin-primes/Java/smarandache-wellin-primes.java b/Task/Smarandache-Wellin-primes/Java/smarandache-wellin-primes.java new file mode 100644 index 0000000000..2a00c94246 --- /dev/null +++ b/Task/Smarandache-Wellin-primes/Java/smarandache-wellin-primes.java @@ -0,0 +1,81 @@ +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public final class SmarandacheWellinPrimes { + + public static void main(String[] args) { + primes = listPrimesUpTo(12_000); + smarandacheWellinPrimes(); + System.out.println(); + derivedSmarandacheWellinPrimes(); + } + + private static void smarandacheWellinPrimes() { + int count = 0; + int index = 1; + int number = 2; + String numberString = "2"; + System.out.println("The first eight Smarandache-Wellin primes are:"); + + while ( count < 8 ) { + if ( new BigInteger(numberString).isProbablePrime(CERTAINTY_LEVEL) ) { + count += 1; + System.out.println(String.format("%2d%s%-4d%s%-5d%s%d", count, ": index = ", index, + " last prime = ", number, " number of digits = ", numberString.length())); + } + + number = primes.get(index); + numberString += number; + index += 1; + } + } + + private static void derivedSmarandacheWellinPrimes() { + int count = 0; + int index = 0; + int[] digitFrequencies = new int[10]; + System.out.println("The first 20 derived Smarandache-Wellin numbers which are prime:"); + + while ( count < 20 ) { + String prime = String.valueOf(primes.get(index)); + for ( char ch : prime.toCharArray() ) { + digitFrequencies[ch - '0'] += 1; + } + + index += 1; + String joined = Arrays.stream(digitFrequencies).mapToObj(String::valueOf).collect(Collectors.joining("")); + if ( new BigInteger(joined).isProbablePrime(CERTAINTY_LEVEL) ) { + count += 1; + System.out.println(String.format("%2d%s%-4d%s%s", count, ": index = ", index, " prime = ", joined)); + } + } + } + + private static List listPrimesUpTo(int limit) { + final int halfLimit = ( limit + 1 ) / 2; + boolean[] composite = new boolean[halfLimit]; + for ( int i = 1, p = 3; i < halfLimit; p += 2, i++ ) { + if ( ! composite[i] ) { + for ( int a = i + p; a < halfLimit; a += p ) { + composite[a] = true; + } + } + } + + List result = Stream.of(2).limit(1).collect(Collectors.toList()); + for ( int i = 1, p = 3; i < halfLimit; p += 2, i++ ) { + if ( ! composite[i] ) { + result.add(p); + } + } + return result; + } + + private static List primes; + + private static final int CERTAINTY_LEVEL = 15; + +} diff --git a/Task/Snake/EasyLang/snake.easy b/Task/Snake/EasyLang/snake.easy index 2d02ed3bc0..159718d50e 100644 --- a/Task/Snake/EasyLang/snake.easy +++ b/Task/Snake/EasyLang/snake.easy @@ -16,28 +16,53 @@ clear color 997 text "SNAKE" textsize 5 -move 10 40 -text "Arrow keys for controlling" -move 10 30 -text "Press space to to start" +move 6 40 +text "Keys or mouse for controlling" +move 6 30 +text "Space or click to to start" # on key - if keybkey = "ArrowUp" and dir <> 3 - dir = 1 - elif keybkey = "ArrowRight" and dir <> 4 - dir = 2 - elif keybkey = "ArrowDown" and dir <> 1 - dir = 3 - elif keybkey = "ArrowLeft" and dir <> 2 - dir = 4 - elif keybkey = " " and game = 0 + if game = 0 and keybkey = " " start + return + . + if dir mod 2 = 1 + if keybkey = "ArrowRight" + dir = 2 + elif keybkey = "ArrowLeft" + dir = 4 + . + else + if keybkey = "ArrowUp" + dir = 1 + elif keybkey = "ArrowDown" + dir = 3 + . + . +. +on mouse_down + if game = 0 + start + return + . + if dir mod 2 = 1 + if mouse_x < sx + dir = 4 + else + dir = 2 + . + else + if mouse_y < sy + dir = 3 + else + dir = 1 + . . . on timer clear color 997 - move 2 96 + move 2 95 text "Score: " & 10 * len sx[] - 50 color 966 move rx ry @@ -93,6 +118,6 @@ on timer else color 997 move 10 10 - text "Press space for new game" + text "Space or click new game" . . diff --git a/Task/Sort-using-a-custom-comparator/Java/sort-using-a-custom-comparator-3.java b/Task/Sort-using-a-custom-comparator/Java/sort-using-a-custom-comparator-3.java new file mode 100644 index 0000000000..2d212af3a0 --- /dev/null +++ b/Task/Sort-using-a-custom-comparator/Java/sort-using-a-custom-comparator-3.java @@ -0,0 +1,17 @@ +import java.util.Comparator; +import java.util.List; + +public final class SortUsingCustomComparator { + + public static void main(String[] args) { + List list = List.of( "Here", "are", "some", "sample", "strings", "to", "be", "sorted" ); + + Comparator custom = Comparator.comparing(String::length, Comparator.reverseOrder()) + .thenComparing(Comparator.naturalOrder()); + + List sortedList = list.stream().sorted(custom).toList(); + + System.out.println(sortedList); + } + +} diff --git a/Task/Sorting-algorithms-Heapsort/Haskell/sorting-algorithms-heapsort-1.hs b/Task/Sorting-algorithms-Heapsort/Haskell/sorting-algorithms-heapsort-1.hs index eec1c87444..75f93876e4 100644 --- a/Task/Sorting-algorithms-Heapsort/Haskell/sorting-algorithms-heapsort-1.hs +++ b/Task/Sorting-algorithms-Heapsort/Haskell/sorting-algorithms-heapsort-1.hs @@ -22,5 +22,5 @@ toList :: Ord a => Tree a -> [a] toList Nil = [] toList (Node x l r) = x : toList (merge l r) -mergeSort :: Ord a => [a] -> [a] -mergeSort = toList . fromList +heapSort :: Ord a => [a] -> [a] +heapSort = toList . fromList diff --git a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-1.raku b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-1.raku new file mode 100644 index 0000000000..9cba63a48e --- /dev/null +++ b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-1.raku @@ -0,0 +1,23 @@ +#| Recursive, single-thread, mergesort implementation +sub mergesort ( @a ) { + return @a if @a <= 1; + + # recursion step + my $m = @a.elems div 2; + my @l = samewith @a[ 0 ..^ $m ]; + my @r = samewith @a[ $m ..^ @a ]; + + # short cut - in case of no overlapping left and right parts + return flat @l, @r if @l[*-1] !after @r[0]; + return flat @r, @l if @r[*-1] !after @l[0]; + + # merge step + return flat gather { + take @l[0] before @r[0] + ?? @l.shift + !! @r.shift + while @l and @r; + + take @l, @r; + } +} diff --git a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-2.raku b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-2.raku new file mode 100644 index 0000000000..cd61cfb0f7 --- /dev/null +++ b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-2.raku @@ -0,0 +1,3 @@ +my @data = 6, 7, 2, 1, 8, 9, 5, 3, 4; +say 'input = ' ~ @data; +say 'output = ' ~ @data.&merge_sort; diff --git a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-3.raku b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-3.raku new file mode 100644 index 0000000000..e49569c1f7 --- /dev/null +++ b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-3.raku @@ -0,0 +1,26 @@ +#| Recursive, naive parallel, mergesort implementation +proto mergesort-parallel-naive(| --> Positional) {*} +multi mergesort-parallel-naive(@unsorted where @unsorted.elems < 2) { @unsorted } +multi mergesort-parallel-naive(@unsorted where @unsorted.elems == 2) { + @unsorted[0] after @unsorted[1] + ?? (@unsorted[1], @unsorted[0]) + !! @unsorted +} +multi mergesort-parallel-naive(@unsorted) { + my $mid = @unsorted.elems div 2; + my Promise $left-sorted = start { flat samewith @unsorted[ 0 ..^ $mid ] }; + my @right-sorted = flat samewith @unsorted[ $mid ..^ @unsorted.elems ]; + + await $left-sorted andthen my @left-sorted = $left-sorted.result; + + return flat @left-sorted, @right-sorted if @left-sorted[*-1] !after @right-sorted[0]; + return flat @right-sorted, @left-sorted if @right-sorted[*-1] !after @left-sorted[0]; + + return flat gather { + take @left-sorted[0] before @right-sorted[0] + ?? @left-sorted.shift + !! @right-sorted.shift + while @left-sorted.elems and @right-sorted.elems; + take @left-sorted, @right-sorted; + } +} diff --git a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-4.raku b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-4.raku new file mode 100644 index 0000000000..b670a05add --- /dev/null +++ b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-4.raku @@ -0,0 +1,47 @@ +constant $BATCH-SIZE = 2**10; +my atomicint $worker = $*KERNEL.cpu-cores; + +#| Recursive, parallel, tuned, mergesort implementation +proto mergesort-parallel(| --> Positional) {*} +multi mergesort-parallel(@unsorted where @unsorted.elems < 2) { @unsorted } +multi mergesort-parallel(@unsorted where @unsorted.elems == 2) { + @unsorted[0] after @unsorted[1] + ?? (@unsorted[1], @unsorted[0]) + !! @unsorted +} +multi mergesort-parallel(@unsorted) { + my $mid = @unsorted.elems div 2; + + # atomically decide if we run left side on a new thread + my $left-sorted = ⚛$worker > 0 && + $mid > $BATCH-SIZE + ?? ( + $worker⚛--; + start { + LEAVE $worker⚛++; + samewith @unsorted[ 0 ..^ $mid ] + } + ) + !! samewith @unsorted[ 0 ..^ $mid ]; + + # recursion on the right side using current thread + my @right-sorted = samewith @unsorted[ $mid ..^ @unsorted.elems ]; + + # await calculation of left side + await $left-sorted andthen $left-sorted = flat $left-sorted.result + if $left-sorted ~~ Promise; + my @left-sorted = flat $left-sorted; + + # short cut - in case of no overlapping left and right parts + return flat @left-sorted, @right-sorted if @left-sorted[*-1] !after @right-sorted[0]; + return flat @right-sorted, @left-sorted if @right-sorted[*-1] !after @left-sorted[0]; + + # merge step + return flat gather { + take @left-sorted[0] before @right-sorted[0] + ?? @left-sorted.shift + !! @right-sorted.shift + while @left-sorted.elems and @right-sorted.elems; + take @left-sorted, @right-sorted; + } +} diff --git a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-5.raku b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-5.raku new file mode 100644 index 0000000000..c3b2fb2e68 --- /dev/null +++ b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort-5.raku @@ -0,0 +1,31 @@ +use Test; +my @testcases = + () => (), + .List => .List, + => , + => , + => , + => , + (2, 3, 1, 4, 5) => (1, 2, 3, 4, 5), + => .sort + ; +my @implementations = &mergesort, &mergesort-parallel, &mergesort-parallel-naive; +plan @testcases.elems * @implementations.elems; +for @implementations -> &fun { + say &fun.name; + is-deeply &fun(.key), .value, .key ~ " => " ~ .value for @testcases; +} +done-testing; + +use Benchmark; +my $elem-length = 8; +my @unsorted of Str = ('a'..'z').roll($elem-length).join xx 10 * $worker * $BATCH-SIZE; +my $runs = 10; + +say "Benchmarking by $runs times sorting {@unsorted.elems} strings of size $elem-length - using batches of $BATCH-SIZE strings and $worker workers for mergesort-parallel()."; +say "Hint: watch the number of Raku threads in Activity Monitor on Mac, Ressource Monitor on Windows or htop on Linux."; +for @implementations -> &fun { + print &fun.name, " => avg: "; + my ($start, $end, $diff, $avg) = timethis $runs, sub { &fun(@unsorted) } + say "$avg secs, total $diff secs"; +} diff --git a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort.raku b/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort.raku deleted file mode 100644 index 8f5c291c51..0000000000 --- a/Task/Sorting-algorithms-Merge-sort/Raku/sorting-algorithms-merge-sort.raku +++ /dev/null @@ -1,17 +0,0 @@ -sub merge_sort ( @a ) { - return @a if @a <= 1; - - my $m = @a.elems div 2; - my @l = flat merge_sort @a[ 0 ..^ $m ]; - my @r = flat merge_sort @a[ $m ..^ @a ]; - - return flat @l, @r if @l[*-1] !after @r[0]; - return flat gather { - take @l[0] before @r[0] ?? @l.shift !! @r.shift - while @l and @r; - take @l, @r; - } -} -my @data = 6, 7, 2, 1, 8, 9, 5, 3, 4; -say 'input = ' ~ @data; -say 'output = ' ~ @data.&merge_sort; diff --git a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-1.raku b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-1.raku new file mode 100644 index 0000000000..bdd140ac28 --- /dev/null +++ b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-1.raku @@ -0,0 +1,7 @@ +#| Recursive, single-thread, single-pass, quicksort implementation +multi quicksort(@unsorted where @unsorted.elems < 2) { @unsorted } +multi quicksort(@unsorted) { + my $pivot = @unsorted.pick; + my %class{Order} is default([]) = @unsorted.classify: * cmp $pivot; + |samewith(%class{Less}), |%class{Same}, |samewith(%class{More}) +} diff --git a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-2.raku b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-2.raku new file mode 100644 index 0000000000..17210b50cd --- /dev/null +++ b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-2.raku @@ -0,0 +1,9 @@ +#| 7-Line, recursive, parallel, single-pass, quicksort implementation +multi seven-line-quicksort-parallel(@unsorted where @unsorted.elems < 2) { @unsorted } +multi seven-line-quicksort-parallel(@unsorted) { + my $pivot = @unsorted.pick; + my %partitions{Order} is default([]) = @unsorted.classify( * cmp $pivot ); + my Promise $less = start { samewith(%partitions{Less}) } + my $more = samewith(%partitions{More}); + await $less andthen |$less.result, |%partitions{Same}, |$more; +} diff --git a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-3.raku b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-3.raku new file mode 100644 index 0000000000..e4d56f34ba --- /dev/null +++ b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-3.raku @@ -0,0 +1,31 @@ +constant $BATCH-SIZE = 2**10; +my atomicint $worker = $*KERNEL.cpu-cores; +#| Recursive, parallel, tuned, single-pass, quicksort implementation +proto quicksort-parallel(| --> Positional) {*} +multi quicksort-parallel(@unsorted where @unsorted.elems < 2) { @unsorted } +multi quicksort-parallel(@unsorted) { + # separate unsorted input into Order Less, Same and More compared to a random $pivot + my $pivot = @unsorted.pick; + my %partitions{Order} is default([]) = @unsorted.classify( * cmp $pivot ); + + # atomically decide if we sort the Less partition on a new thread + my $less = ⚛$worker > 0 && + %partitions{Less}.elems > $BATCH-SIZE + ?? ( + $worker⚛--; + start { + LEAVE $worker⚛++; + samewith(%partitions{Less}) + } + ) + !! samewith(%partitions{Less}); + + # meanwhile use current thread for sorting the More partition + my $more = samewith(%partitions{More}); + + # if we went parallel, we need to await the result + await $less andthen $less = $less.result if $less ~~ Promise; + + # concat all sorted partitions into a list and return + |$less, |%partitions{Same}, |$more; +} diff --git a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-4.raku b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-4.raku new file mode 100644 index 0000000000..9a312c91c5 --- /dev/null +++ b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-4.raku @@ -0,0 +1,18 @@ +use Test; +my @testcases = + () => (), + .List => .List, + => , + => , + => , + => , + (2, 3, 1, 4, 5) => (1, 2, 3, 4, 5), + => .sort +; +my @implementations = &quicksort, &seven-line-quicksort-parallel, &quicksort-parallel; +plan @testcases.elems * @implementations.elems; +for @implementations -> &fun { + say &fun.name; + is-deeply &fun(.key), .value, .key ~ " => " ~ .value for @testcases; +} +done-testing; diff --git a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-5.raku b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-5.raku new file mode 100644 index 0000000000..3a8383e288 --- /dev/null +++ b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort-5.raku @@ -0,0 +1,9 @@ +my $elem-length = 8; +my @large of Str = ('a'..'z').roll($elem-length).join xx 10 * $worker * $BATCH-SIZE; + +say "Benchmarking by sorting {@large.elems} strings of size $elem-length - using batches of $BATCH-SIZE strings and $worker workers."; +my @benchmark = gather for @implementations -> &fun { + &fun(@large); + take (&fun.name => now - ENTER now); +} +say @benchmark; diff --git a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort.raku b/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort.raku deleted file mode 100644 index aaddadae98..0000000000 --- a/Task/Sorting-algorithms-Quicksort/Raku/sorting-algorithms-quicksort.raku +++ /dev/null @@ -1,12 +0,0 @@ -# Empty list sorts to the empty list - multi quicksort([]) { () } - - # Otherwise, extract first item as pivot... - multi quicksort([$pivot, *@rest]) { - # Partition. - my $before := @rest.grep(* before $pivot); - my $after := @rest.grep(* !before $pivot); - - # Sort the partitions. - flat quicksort($before), $pivot, quicksort($after) - } diff --git a/Task/Sorting-algorithms-Quicksort/Zig/sorting-algorithms-quicksort.zig b/Task/Sorting-algorithms-Quicksort/Zig/sorting-algorithms-quicksort.zig new file mode 100644 index 0000000000..87ae8d2421 --- /dev/null +++ b/Task/Sorting-algorithms-Quicksort/Zig/sorting-algorithms-quicksort.zig @@ -0,0 +1,45 @@ +const std = @import("std"); + +pub fn quicksort(comptime t: type, arr: []t) void { + if (arr.len < 2) return; + var pivot = arr[@as(usize, @intFromFloat(@floor(@as(f64, @floatFromInt(arr.len)) / 2)))]; + var left: usize = 0; + var right: usize = arr.len - 1; + + while (left <= right) { + while (arr[left] < pivot) { + left += 1; + } + while (arr[right] > pivot) { + right -= 1; + } + if (left <= right) { + const tmp = arr[left]; + arr[left] = arr[right]; + arr[right] = tmp; + left += 1; + right -= 1; + } + } + + quicksort(t, arr[0 .. right + 1]); + quicksort(t, arr[left..]); +} + +pub fn main() !void { + const LIST_TYPE = i16; + var arr: [10]LIST_TYPE = [_]LIST_TYPE{ 4, 65, 2, -31, 0, 99, 2, 83, 782, 1 }; + var i: usize = 0; + + while (i < arr.len) : (i += 1) { + std.debug.print("{d} ", .{arr[i]}); + } + std.debug.print("\n", .{}); + + i = 0; + quicksort(LIST_TYPE, &arr); + while (i < arr.len) : (i += 1) { + std.debug.print("{d} ", .{arr[i]}); + } + std.debug.print("\n", .{}); +} diff --git a/Task/Square-form-factorization/ALGOL-68/square-form-factorization.alg b/Task/Square-form-factorization/ALGOL-68/square-form-factorization.alg new file mode 100644 index 0000000000..09991892a6 --- /dev/null +++ b/Task/Square-form-factorization/ALGOL-68/square-form-factorization.alg @@ -0,0 +1,100 @@ +BEGIN # Daniel Shanks's Square Form Factorization (SquFoF) - based on the Wren sample # + + MODE INTEGER = LONG INT; # large enough INT type # + PROC(LONG REAL)LONG REAL size sqrt = long sqrt; # sqrt for INTEGER values # + + []INTEGER multipliers = ( 1, 3, 5, 7, 11, 3 * 5, 3 * 7, 3 * 11 + , 5 * 7, 5 * 11, 7 * 11, 3 * 5 * 7, 3 * 5 * 11 + , 3 * 7 * 11, 5 * 7 * 11, 3 * 5 * 7 * 11 + ); + PROC gcd = ( INTEGER x, y )INTEGER: # iterative gcd # + BEGIN + INTEGER a := x, b := y; + WHILE b /= 0 DO + INTEGER next a = b; + b := a MOD b; + a := next a + OD; + ABS a + END # gcd # ; + + PROC squfof = ( INTEGER n )INTEGER: + IF INTEGER s = ENTIER ( size sqrt( n ) + 0.5 ); + s * s = n + THEN s + ELSE INTEGER result := 0; + FOR multiplier FROM LWB multipliers TO UPB multipliers WHILE result = 0 DO + INTEGER d = n * multipliers[ multiplier ]; + INTEGER pp := ENTIER size sqrt( d ); + INTEGER p prev := pp; + INTEGER po = p prev; + INTEGER q prev := 1; + INTEGER qq := d - ( po * po ); + INTEGER l = ENTIER size sqrt( s * 8 ); + INTEGER bb = 3 * l; + INTEGER i := 2; + INTEGER b := 0; + INTEGER q := 0; + INTEGER r := 0; + BOOL again := TRUE; + WHILE i < bb AND again DO + b := ( po + pp ) OVER qq; + pp := ( b * qq ) - pp; + q := qq; + qq := q prev + ( b * ( p prev - pp ) ); + r := ENTIER ( size sqrt( qq ) + 0.5 ); + IF i MOD 2 = 0 THEN again := r * r /= qq FI; + IF again THEN + q prev := q; + p prev := pp; + i +:= 1 + FI + OD; + IF i < bb THEN + b := ( po - pp ) OVER r; + p prev := pp := ( b * r ) + pp; + q prev := r; + qq := ( d - ( p prev * p prev ) ) OVER q prev; + i := 0; + WHILE + b := ( po + pp ) OVER qq; + p prev := pp; + pp := ( b * qq ) - pp; + q := qq; + qq := q prev + ( b * ( p prev - pp ) ); + q prev := q; + i +:= 1; + pp /= p prev + DO SKIP OD + FI; + r := gcd( n, q prev ); + IF r /= 1 AND r /=n THEN result := r FI + OD; + result + FI # squfof # ; + + []INTEGER examples = ( 2501, 12851 + , 13289, 75301 + , 120787, 967009 + , 997417, 7091569 + , 13290059, 42854447 + , 223553581, 2027651281 + , 11111111111, 100895598169 + , 1002742628021, 60012462237239 + , 287129523414791, 9007199254740931 + , 11111111111111111, 314159265358979323 + , 384307168202281507, 419244183493398773 + , 658812288346769681, 922337203685477563 + , 1000000000000000127, 1152921505680588799 + , 1537228672809128917, 4611686018427387877 + ); + + print( ( "Integer Factor Quotient", newline ) ); + print( ( "----------------------------------------", newline ) ); + FOR example FROM LWB examples TO UPB examples DO + INTEGER n = examples[ example ]; + INTEGER fact = squfof( n ); + STRING quot = IF fact = 0 THEN "fail" ELSE whole( n OVER fact, 0 ) FI; + print( ( whole( n, -20 ), " ", whole( fact, -10 ), " ", quot, newline ) ) + OD +END diff --git a/Task/Square-form-factorization/C++/square-form-factorization.cpp b/Task/Square-form-factorization/C++/square-form-factorization.cpp new file mode 100644 index 0000000000..ca846c0760 --- /dev/null +++ b/Task/Square-form-factorization/C++/square-form-factorization.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include + +uint64_t test_value = 0; +uint64_t sqrt_test_value = 0; + +class BQF { // Binary quadratic form +public: + BQF(const uint64_t& a, const uint64_t& b, const uint64_t& c) : a(a), b(b), c(c) { + q = ( sqrt_test_value + b ) / c; + bb = q * c - b; + } + + BQF rho() { + return BQF(c, bb, a + q * ( b - bb )); + } + + BQF rho_inverse() { + return BQF(c, bb, ( test_value - bb * bb ) / c); + } + + uint64_t a, b, c; +private: + uint64_t q, bb; +}; + +uint64_t squfof(const uint64_t& number) { + const uint32_t sqrt = std::sqrt(number); + if ( sqrt * sqrt == number ) { + return sqrt; + } + + test_value = number; + sqrt_test_value = std::sqrt(test_value); + + // Principal form + BQF form(0, sqrt_test_value, 1); + form = form.rho_inverse(); + + // Search principal cycle + for ( uint32_t i = 0; i < 4 * std::sqrt(2 * sqrt_test_value); i += 2 ) { + // Even step + form = form.rho(); + + uint64_t sqrt_c = std::sqrt(form.c); + if ( sqrt_c * sqrt_c == form.c ) { // Square form found + // Inverse square root + BQF form_inverse(0, -form.b, sqrt_c); + form_inverse = form_inverse.rho_inverse(); + + // Search ambiguous cycle + uint64_t previous_b = 0; + do { + previous_b = form_inverse.b; + form_inverse = form_inverse.rho(); + } while ( form_inverse.b != previous_b ); + + // Symmetry point + const uint64_t g = std::gcd(number, form_inverse.a); + if ( g != 1 ) { + return g; + } + } + + // Odd step + form = form.rho(); + } + + if ( number % 2 == 0 ) { + return 2; + } + return 0; // Failed to factorise, possibly a prime number +} + +int main() { + std::random_device random; + std::mt19937 generator(random()); + const uint64_t lower_limit = 100'000'000'000'000'000; + std::uniform_int_distribution distribution(lower_limit, 10 * lower_limit); + + for ( uint32_t i = 0; i < 20; ++i ) { + uint64_t test = distribution(random); + uint64_t factor = squfof(test); + + if ( factor == 0 ) { + std::cout << test << " - failed to factorise" << std::endl; + } else { + std::cout << test << " = " << factor << " * " << test / factor << std::endl; + } + std::cout << std::endl; + } +} diff --git a/Task/Square-form-factorization/EasyLang/square-form-factorization.easy b/Task/Square-form-factorization/EasyLang/square-form-factorization.easy new file mode 100644 index 0000000000..a8b5c67d74 --- /dev/null +++ b/Task/Square-form-factorization/EasyLang/square-form-factorization.easy @@ -0,0 +1,73 @@ +multiplier[] = [ 1 3 5 7 11 3 * 5 3 * 7 3 * 11 5 * 7 5 * 11 7 * 11 3 * 5 * 7 3 * 5 * 11 3 * 7 * 11 5 * 7 * 11 3 * 5 * 7 * 11 ] +func gcd a b . + while b <> 0 + a = a mod b + swap a b + . + return a +. +func squfof N . + s = floor (sqrt N + 0.5) + if s * s = N + return s + . + for multiplier in multiplier[] + if N > 9007199254740992 / multiplier + print "Number " & N & " is too big" + break 1 + . + D = multiplier * N + P = floor sqrt D + Po = P + Pprev = P + Qprev = 1 + Q = D - Po * Po + L = 2 * floor sqrt (2 * s) + B = 3 * L + for i = 2 to B - 1 + b = (Po + P) div Q + P = b * Q - P + q = Q + Q = Qprev + b * (Pprev - P) + r = floor (sqrt Q + 0.5) + if i mod 2 = 0 and r * r = Q + break 1 + . + Qprev = q + Pprev = P + . + if i < B + b = (Po - P) div r + P = b * r + P + Pprev = P + Qprev = r + Q = (D - Pprev * Pprev) / Qprev + i = 0 + repeat + b = (Po + P) div Q + Pprev = P + P = b * Q - P + q = Q + Q = Qprev + b * (Pprev - P) + Qprev = q + i += 1 + until P = Pprev + . + r = gcd N Qprev + if r <> 1 and r <> N + return r + . + . + . + return 0 +. +data[] = [ 2501 12851 13289 75301 120787 967009 997417 7091569 13290059 42854447 223553581 2027651281 11111111111 100895598169 1002742628021 60012462237239 287129523414791 9007199254740931 ] +for example in data[] + factor = squfof example + if factor = 0 + print example & " was not factored." + else + quotient = example / factor + print example & " has factors " & factor & " " & quotient + . +. diff --git a/Task/Square-form-factorization/Java/square-form-factorization.java b/Task/Square-form-factorization/Java/square-form-factorization.java new file mode 100644 index 0000000000..7588b63a52 --- /dev/null +++ b/Task/Square-form-factorization/Java/square-form-factorization.java @@ -0,0 +1,108 @@ +import java.math.BigInteger; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; + +public final class SquareFormFactorization { + + public static void main(String[] args) { + ThreadLocalRandom random = ThreadLocalRandom.current(); + final long lowerLimit = 10_000_000_000_000_000L; + final List tests = random.longs(20, lowerLimit, 10 * lowerLimit).boxed().toList(); + + for ( long test : tests ) { + long factor = squfof(test); + + if ( factor == 0 ) { + System.out.println(test + " - failed to factorise"); + } else if ( factor == 1 ) { + System.out.println(test + " is a prime number"); + } else { + System.out.println(test + " = " + factor + " * " + test / factor); + } + System.out.println(); + } + } + + private static long squfof(long number) { + if ( BigInteger.valueOf(number).isProbablePrime(15) ) { + return 1; // Prime number + } + + final int sqrt = (int) Math.sqrt(number); + if ( sqrt * sqrt == number ) { + return sqrt; + } + + testValue = number; + sqrtTestValue = (long) Math.sqrt(testValue); + + // Principal form + BQF form = new BQF(0, sqrtTestValue, 1); + form = form.rhoInverse(); + + // Search principal cycle + for ( int i = 0; i < 4 * (long) Math.sqrt(2 * sqrtTestValue); i += 2 ) { + // Even step + form = form.rho(); + + long sqrtC = (long) Math.sqrt(form.c); + if ( sqrtC * sqrtC == form.c ) { // Square form found + // Inverse square root + BQF formInverse = new BQF(0, -form.b, sqrtC); + formInverse = formInverse.rhoInverse(); + + // Search ambiguous cycle + long previousB = 0; + do { + previousB = formInverse.b; + formInverse = formInverse.rho(); + } while ( formInverse.b != previousB ); + + // Symmetry point + final long gcd = gcd(number, formInverse.a); + if ( gcd != 1 ) { + return gcd; + } + } + + // Odd step + form = form.rho(); + } + + if ( number % 2 == 0 ) { + return 2; + } + return 0; // Failed to factorise + } + + private static long gcd(long a, long b) { + while ( b != 0 ) { + long temp = a; a = b; b = temp % b; + } + return a; + } + + private static class BQF { // Binary quadratic form + + public BQF(long aA, long aB, long aC) { + a = aA; b = aB; c = aC; + q = ( sqrtTestValue + b ) / c; + bb = q * c - b; + } + + public BQF rho() { + return new BQF(c, bb, a + q * ( b - bb )); + } + + public BQF rhoInverse() { + return new BQF(c, bb, ( testValue - bb * bb ) / c); + } + + private long a, b, c; + private long q, bb; + + } + + private static long testValue, sqrtTestValue; + +} diff --git a/Task/Steffensens-method/Julia/steffensens-method.julia b/Task/Steffensens-method/Julia/steffensens-method.julia new file mode 100644 index 0000000000..1ff8beb6f1 --- /dev/null +++ b/Task/Steffensens-method/Julia/steffensens-method.julia @@ -0,0 +1,57 @@ +""" Aitken's extrapolation """ +function aitken(f, p0) + p1 = f(p0) + p2 = f(p1) + return p0 - (p1 - p0)^2 / (p2 - 2 * p1 + p0) +end + +""" Steffensen's method using Aitken """ +function steffensen_aitken(f, pinit, tol, maxiter) + p0 = pinit + p = aitken(f, p0) + iter = 1 + while abs(p - p0) > tol && iter < maxiter + p0 = p + p = aitken(f, p0) + iter += 1 + end + return abs(p - p0) > tol ? NaN : p +end + +""" deCasteljau function """ +function deCasteljau(c0, c1, c2, t) + s = 1.0 - t + return s * (s * c0 + t * c1) + t * (s * c1 + t * c2) +end + +xConvexLeftParabola(t) = deCasteljau(2, -8, 2, t) +yConvexRightParabola(t) = deCasteljau(1, 2, 3, t) +implicit_equation(x, y) = 5 * x^2 + y - 5 + +""" may return NaN on overflow """ +function f(t) + return t in [nothing, NaN, Inf, -Inf] ? NaN : + implicit_equation(xConvexLeftParabola(t), yConvexRightParabola(t)) + t +end + +""" test the example """ +function test_steffensen(tol = 0.00000001, iters = 1000, stepsize = 0.1) + for t0 in 0:stepsize:1.1 + print("t0 = $t0 : ") + t = steffensen_aitken(f, t0, tol, iters) + if isnan(t) + println("no answer") + else + x = xConvexLeftParabola(t) + y = yConvexRightParabola(t) + if abs(implicit_equation(x, y)) <= tol + println("intersection at ($(Float32(x)), $(Float32(y)))") + else + println("spurious solution") + end + end + end + return 0 +end + +test_steffensen() diff --git a/Task/Steffensens-method/Raku/steffensens-method.raku b/Task/Steffensens-method/Raku/steffensens-method.raku new file mode 100644 index 0000000000..11d87aabe7 --- /dev/null +++ b/Task/Steffensens-method/Raku/steffensens-method.raku @@ -0,0 +1,48 @@ +# 20230928 Raku programming solution + +sub aitken($f, $p0) { + my $p2 = $f( my $p1 = $f($p0) ); + my $p1m0 = $p1 - $p0; + return $p0 - $p1m0*$p1m0/($p2-2.0*$p1+$p0); +} + +sub steffensenAitken($f, $pinit, $tol, $maxiter) { + my ($iter, $p) = 1, aitken($f, my $p0 = $pinit); + while abs($p-$p0) > $tol and $iter < $maxiter { + $p = aitken($f, $p0 = $p); + $iter++ + } + return abs($p-$p0) > $tol ?? NaN !! $p +} + +sub deCasteljau($c0, $c1, $c2, $t) { + my $s = 1.0 - $t; + return $s*($s*$c0 + $t*$c1) + $t*($s*$c1 + $t*$c2) +} + +sub xConvexLeftParabola($t) { return deCasteljau(2.0, -8.0, 2.0, $t) } + +sub yConvexRightParabola($t) { return deCasteljau(1.0, 2.0, 3.0, $t) } + +sub implicitEquation($x, $y) { return 5.0*$x*$x + $y - 5.0 } + +sub f($t) { + implicitEquation(xConvexLeftParabola($t), yConvexRightParabola($t)) + $t +} + +my $t0 = 0.0; +for ^11 { + print "t0 = {$t0.fmt: '%0.1f'} : "; + my $t = steffensenAitken(&f, $t0, 0.00000001, 1000); + if $t.isNaN { + say "no answer"; + } else { + my ($x, $y) = xConvexLeftParabola($t), yConvexRightParabola($t); + if abs(implicitEquation($x, $y)) <= 0.000001 { + printf "intersection at (%f, %f)\n", $x, $y; + } else { + say "spurious solution"; + } + } + $t0 += 0.1; +} diff --git a/Task/Stirling-numbers-of-the-first-kind/EasyLang/stirling-numbers-of-the-first-kind.easy b/Task/Stirling-numbers-of-the-first-kind/EasyLang/stirling-numbers-of-the-first-kind.easy new file mode 100644 index 0000000000..9b5db0730b --- /dev/null +++ b/Task/Stirling-numbers-of-the-first-kind/EasyLang/stirling-numbers-of-the-first-kind.easy @@ -0,0 +1,15 @@ +print "Unsigned Stirling numbers of the first kind:" +len a[] 13 ; arrbase a[] 0 +len b[] 13 ; arrbase b[] 0 +a[0] = 1 +print 1 +for n = 1 to 12 + b[0] = 0 + write 0 & " " + for k = 1 to n + b[k] = a[k - 1] + (n - 1) * a[k] + write b[k] & " " + . + print "" + swap a[] b[] +. diff --git a/Task/Stirling-numbers-of-the-second-kind/EasyLang/stirling-numbers-of-the-second-kind.easy b/Task/Stirling-numbers-of-the-second-kind/EasyLang/stirling-numbers-of-the-second-kind.easy new file mode 100644 index 0000000000..ccd351f6a9 --- /dev/null +++ b/Task/Stirling-numbers-of-the-second-kind/EasyLang/stirling-numbers-of-the-second-kind.easy @@ -0,0 +1,17 @@ +print "Unsigned Stirling numbers of the second kind:" +len a[] 13 ; arrbase a[] 0 +len b[] 13 ; arrbase b[] 0 +a[0] = 1 +print 1 +for n = 1 to 12 + b[0] = 0 + write 0 & " " + for k = 1 to n - 1 + b[k] = k * a[k] + a[k - 1] + write b[k] & " " + . + b[n] = 1 + write 1 & " " + print "" + swap a[] b[] +. diff --git a/Task/String-append/Amazing-Hopper/string-append.hopper b/Task/String-append/Amazing-Hopper/string-append.hopper new file mode 100644 index 0000000000..34bfa1665c --- /dev/null +++ b/Task/String-append/Amazing-Hopper/string-append.hopper @@ -0,0 +1,11 @@ +#include + +Main + r="un corderito", s="María tenía", t="felpudo" + + Multicat ( s," ",r," ",t ),Get utf8, and print it + + d=0 + Let ' d := Utf8( Cat( Cat ( s, " un " ), t ) )' + Printnl ( "\n",d ) +End diff --git a/Task/String-append/FutureBasic/string-append.basic b/Task/String-append/FutureBasic/string-append.basic new file mode 100644 index 0000000000..c8546619bc --- /dev/null +++ b/Task/String-append/FutureBasic/string-append.basic @@ -0,0 +1,8 @@ +Str255 s + +s = "Hello" +s += " World!" + +print s + +HandleEvents diff --git a/Task/String-matching/EasyLang/string-matching.easy b/Task/String-matching/EasyLang/string-matching.easy new file mode 100644 index 0000000000..207ea4acb6 --- /dev/null +++ b/Task/String-matching/EasyLang/string-matching.easy @@ -0,0 +1,23 @@ +func starts s$ t$ . + if substr s$ 1 len t$ = t$ + return 1 + . + return 0 +. +func ends s$ t$ . + if substr s$ (len s$ - len t$ + 1) len t$ = t$ + return 1 + . + return 0 +. +func contains s$ t$ . + for i to len s$ - len t$ + 1 + if substr s$ i len t$ = t$ + return 1 + . + . + return 0 +. +print starts "hello world" "he" +print ends "hello world" "rld" +print contains "hello world" "wo" diff --git a/Task/Strip-a-set-of-characters-from-a-string/Amazing-Hopper/strip-a-set-of-characters-from-a-string.hopper b/Task/Strip-a-set-of-characters-from-a-string/Amazing-Hopper/strip-a-set-of-characters-from-a-string.hopper new file mode 100644 index 0000000000..fdb845705c --- /dev/null +++ b/Task/Strip-a-set-of-characters-from-a-string/Amazing-Hopper/strip-a-set-of-characters-from-a-string.hopper @@ -0,0 +1,13 @@ +#include + +Main + c = ".$%#\tEste@@@ mensaje será purgado!$$$" + + {"Hopper assembler:\n\n"} + {"$%#@.\t", c} str to utf8, delete char, {"\n"} print + + Printnl ("\nHopper Jambo formal syntax:\n\n", Char del ( "$%#@.\t", Utf8( c ) ) ) + + Set ' "\nHopper Jambo Natural syntax:\n\n", "$%#@.\t", c', Get utf8, and delete char + then print with newline +End diff --git a/Task/Strip-a-set-of-characters-from-a-string/EasyLang/strip-a-set-of-characters-from-a-string.easy b/Task/Strip-a-set-of-characters-from-a-string/EasyLang/strip-a-set-of-characters-from-a-string.easy new file mode 100644 index 0000000000..af63c27c1e --- /dev/null +++ b/Task/Strip-a-set-of-characters-from-a-string/EasyLang/strip-a-set-of-characters-from-a-string.easy @@ -0,0 +1,17 @@ +func$ strip s$ del$ . + del$[] = strchars del$ + i = 1 + repeat + c$ = substr s$ i 1 + until c$ = "" + for d$ in del$[] + if c$ = d$ + c$ = "" + . + . + r$ &= c$ + i += 1 + . + return r$ +. +print strip "She was a soul stripper. She took my heart!" "aei" diff --git a/Task/Strip-block-comments/EasyLang/strip-block-comments.easy b/Task/Strip-block-comments/EasyLang/strip-block-comments.easy new file mode 100644 index 0000000000..3eeac841dc --- /dev/null +++ b/Task/Strip-block-comments/EasyLang/strip-block-comments.easy @@ -0,0 +1,40 @@ +subr process + i = 1 + while i <= len s$ + if inc = 0 and substr s$ i 2 = "/*" + inc = 1 + i += 1 + elif inc = 1 and substr s$ i 2 = "*/" + inc = 0 + i += 1 + elif inc = 0 + write substr s$ i 1 + . + i += 1 + . + if inc = 0 + print "" + . +. +repeat + s$ = input + until error = 1 + process +. +input_data +/** + * Some comments + * longer comments here that we can parse. + * + * Rahoo + */ + function subroutine() { + a = /* inline comment */ b + c ; + } + /*/ <-- tricky comments */ + + /** + * Another comment. + */ + function something() { + } diff --git a/Task/Strip-comments-from-a-string/EasyLang/strip-comments-from-a-string.easy b/Task/Strip-comments-from-a-string/EasyLang/strip-comments-from-a-string.easy new file mode 100644 index 0000000000..fd5e4015b1 --- /dev/null +++ b/Task/Strip-comments-from-a-string/EasyLang/strip-comments-from-a-string.easy @@ -0,0 +1,22 @@ +func$ strip s$ . + i = 1 + repeat + c$ = substr s$ i 1 + until c$ = "#" or c$ = ";" or c$ = "" + if c$ = " " and sp = 0 + sp = i + elif c$ <> " " + sp = 0 + . + i += 1 + . + if sp = 0 + sp = i + . + return substr s$ 1 (sp - 1) +. +print strip "Regular string" & "." +print strip "With a hash# a comment" & "." +print strip "With a hash # a comment" & "." +print strip "With a semicolon ; a comment" & "." +print strip "No comment " & "." diff --git a/Task/Strip-control-codes-and-extended-characters-from-a-string/EasyLang/strip-control-codes-and-extended-characters-from-a-string.easy b/Task/Strip-control-codes-and-extended-characters-from-a-string/EasyLang/strip-control-codes-and-extended-characters-from-a-string.easy new file mode 100644 index 0000000000..02d400c1be --- /dev/null +++ b/Task/Strip-control-codes-and-extended-characters-from-a-string/EasyLang/strip-control-codes-and-extended-characters-from-a-string.easy @@ -0,0 +1,9 @@ +func$ strip s$ . + for c$ in strchars s$ + if strcode c$ >= 32 and strcode c$ <= 126 + r$ &= c$ + . + . + return r$ +. +print strip "\tHellö world" diff --git a/Task/Strip-whitespace-from-a-string-Top-and-tail/Amazing-Hopper/strip-whitespace-from-a-string-top-and-tail.hopper b/Task/Strip-whitespace-from-a-string-Top-and-tail/Amazing-Hopper/strip-whitespace-from-a-string-top-and-tail.hopper new file mode 100644 index 0000000000..58461e7aea --- /dev/null +++ b/Task/Strip-whitespace-from-a-string-Top-and-tail/Amazing-Hopper/strip-whitespace-from-a-string-top-and-tail.hopper @@ -0,0 +1,23 @@ +#include + +Main + + Set stack 25 + + c = "\t\t\n \n Message to triming\t\n \t" + + Printnl ("Original Message: [", c,"]") + + Set '"\n\n\UL\ENFNatural syntax:\n\n"', then bold off, and underline off + + Set '"Right trim: [", c', Do right trim; then set '"]"' + Set '"\nLeft trim: [", c', Do left trim; Set '"]"' + Set '"\nAll trim: [", c', Do trim, now set '"]"' and print with newline + + Underline( Bold( "\n\nFormal syntax:\n\n" )) + + Printnl ( "Right trim: [", Rtrim(c),\ + "]\nLeft trim: [", Ltrim(c),\ + "]\nAll trim: [",Trim(c),"]\n" ) + +End diff --git a/Task/Strip-whitespace-from-a-string-Top-and-tail/EasyLang/strip-whitespace-from-a-string-top-and-tail.easy b/Task/Strip-whitespace-from-a-string-Top-and-tail/EasyLang/strip-whitespace-from-a-string-top-and-tail.easy new file mode 100644 index 0000000000..7aa6d8e11a --- /dev/null +++ b/Task/Strip-whitespace-from-a-string-Top-and-tail/EasyLang/strip-whitespace-from-a-string-top-and-tail.easy @@ -0,0 +1,27 @@ +func iswhite c$ . + if c$ = " " or c$ = "\t" or c$ = "\n" + return 1 + . +. +func$ strip s$ top tail . + a = 1 + if top = 1 + repeat + c$ = substr s$ a 1 + until iswhite c$ = 0 + a += 1 + . + . + b = len s$ + if tail = 1 + repeat + c$ = substr s$ b 1 + until iswhite c$ = 0 + b -= 1 + . + . + return substr s$ a (b - a + 1) +. +print strip " Hello world " 1 1 & "." +print strip " Hello world " 0 1 & "." +print strip " Hello world " 1 1 & "." diff --git a/Task/Summarize-primes/Quackery/summarize-primes.quackery b/Task/Summarize-primes/Quackery/summarize-primes.quackery new file mode 100644 index 0000000000..9fd3102c66 --- /dev/null +++ b/Task/Summarize-primes/Quackery/summarize-primes.quackery @@ -0,0 +1,18 @@ + [ number$ + space 6 of swap join + -7 split nip echo$ ] is rjust ( n --> ) + + say " index prime sum" cr + say " ----- ----- ---" cr + [] 1000 times + [ i^ isprime if [ i^ join ] ] + 0 swap + witheach + [ dup dip + + over isprime iff + [ i^ 1+ rjust + rjust + dup rjust + cr ] + else drop ] + drop diff --git a/Task/Sylvesters-sequence/EasyLang/sylvesters-sequence.easy b/Task/Sylvesters-sequence/EasyLang/sylvesters-sequence.easy new file mode 100644 index 0000000000..deda357e5b --- /dev/null +++ b/Task/Sylvesters-sequence/EasyLang/sylvesters-sequence.easy @@ -0,0 +1,12 @@ +numfmt 8 0 +for i = 1 to 10 + if i = 1 + sylv = 2 + else + sylv = sylv * sylv - sylv + 1 + . + print sylv + sum += 1 / sylv +. +print "" +print sum diff --git a/Task/Sylvesters-sequence/Maxima/sylvesters-sequence.maxima b/Task/Sylvesters-sequence/Maxima/sylvesters-sequence.maxima new file mode 100644 index 0000000000..4ecc0eaacb --- /dev/null +++ b/Task/Sylvesters-sequence/Maxima/sylvesters-sequence.maxima @@ -0,0 +1,6 @@ +sylvester[n]:= if n=0 then sylvester[n]:2 else sylvester[n-1]^2-sylvester[n-1]+1$ + +/* Test cases */ +makelist(sylvester[i],i,0,9); + +apply("+",1/%); diff --git a/Task/Terminal-control-Coloured-text/C++/terminal-control-coloured-text.cpp b/Task/Terminal-control-Coloured-text/C++/terminal-control-coloured-text.cpp new file mode 100644 index 0000000000..4da7138867 --- /dev/null +++ b/Task/Terminal-control-Coloured-text/C++/terminal-control-coloured-text.cpp @@ -0,0 +1,17 @@ +#include +int main() { + std::cout << "\033[42m"; + std::cout << "\033[4;37m"; + std::cout << "Green background with underlined white text" << std::endl; + std::cout << "\033[0m" << std::endl; + + std::cout << "\033[0;103m"; + std::cout << "\033[1;34m"; + std::cout << "Bright yellow background with bold blue text" << std::endl; + std::cout << "\033[0m" << std::endl; + + std::cout << "\033[46m"; + std::cout << "\033[1;95m"; + std::cout << "Cyan background with bold bright magenta text" << std::endl; + std::cout << "\033[0m" << std::endl; +} diff --git a/Task/Terminal-control-Coloured-text/Java/terminal-control-coloured-text.java b/Task/Terminal-control-Coloured-text/Java/terminal-control-coloured-text.java new file mode 100644 index 0000000000..014d2f9dc2 --- /dev/null +++ b/Task/Terminal-control-Coloured-text/Java/terminal-control-coloured-text.java @@ -0,0 +1,107 @@ +public class TerminalControlColouredText { + + public static void main(String[] args) { + System.out.print(Color.GREEN_BACKGROUND); + System.out.print(Color.WHITE_UNDERLINED); + System.out.println("Green background with underlined white text"); + System.out.println(Color.RESET); + + System.out.print(Color.YELLOW_BACKGROUND_BRIGHT); + System.out.print(Color.BLUE_BOLD); + System.out.println("Bright yellow background with bold blue text"); + System.out.println(Color.RESET); + + System.out.print(Color.CYAN_BACKGROUND); + System.out.print(Color.MAGENTA_BOLD_BRIGHT); + System.out.println("Cyan background with bold bright magenta text"); + System.out.println(Color.RESET); + } + + private enum Color { + // Restore original background and text colours + RESET("\033[0m"), + + // Text colours + BLACK("\033[0;30m"), + RED("\033[0;31m"), + GREEN("\033[0;32m"), + YELLOW("\033[0;33m"), + BLUE("\033[0;34m"), + MAGENTA("\033[0;35m"), + CYAN("\033[0;36m"), + WHITE("\033[0;37m"), + + // Bold text colours + BLACK_BOLD("\033[1;30m"), + RED_BOLD("\033[1;31m"), + GREEN_BOLD("\033[1;32m"), + YELLOW_BOLD("\033[1;33m"), + BLUE_BOLD("\033[1;34m"), + MAGENTA_BOLD("\033[1;35m"), + CYAN_BOLD("\033[1;36m"), + WHITE_BOLD("\033[1;37m"), + + // Underlined text colours + BLACK_UNDERLINED("\033[4;30m"), + RED_UNDERLINED("\033[4;31m"), + GREEN_UNDERLINED("\033[4;32m"), + YELLOW_UNDERLINED("\033[4;33m"), + BLUE_UNDERLINED("\033[4;34m"), + MAGENTA_UNDERLINED("\033[4;35m"), + CYAN_UNDERLINED("\033[4;36m"), + WHITE_UNDERLINED("\033[4;37m"), + + // Bright text colours + BLACK_BRIGHT("\033[0;90m"), + RED_BRIGHT("\033[0;91m"), + GREEN_BRIGHT("\033[0;92m"), + YELLOW_BRIGHT("\033[0;93m"), + BLUE_BRIGHT("\033[0;94m"), + MAGENTA_BRIGHT("\033[0;95m"), + CYAN_BRIGHT("\033[0;96m"), + WHITE_BRIGHT("\033[0;97m"), + + // Bold and bright text colours + BLACK_BOLD_BRIGHT("\033[1;90m"), + RED_BOLD_BRIGHT("\033[1;91m"), + GREEN_BOLD_BRIGHT("\033[1;92m"), + YELLOW_BOLD_BRIGHT("\033[1;93m"), + BLUE_BOLD_BRIGHT("\033[1;94m"), + MAGENTA_BOLD_BRIGHT("\033[1;95m"), + CYAN_BOLD_BRIGHT("\033[1;96m"), + WHITE_BOLD_BRIGHT("\033[1;97m"), + + // Background colours + BLACK_BACKGROUND("\033[40m"), + RED_BACKGROUND("\033[41m"), + GREEN_BACKGROUND("\033[42m"), + YELLOW_BACKGROUND("\033[43m"), + BLUE_BACKGROUND("\033[44m"), + MAGENTA_BACKGROUND("\033[45m"), + CYAN_BACKGROUND("\033[46m"), + WHITE_BACKGROUND("\033[47m"), + + // Bright background colours + BLACK_BACKGROUND_BRIGHT("\033[0;100m"), + RED_BACKGROUND_BRIGHT("\033[0;101m"), + GREEN_BACKGROUND_BRIGHT("\033[0;102m"), + YELLOW_BACKGROUND_BRIGHT("\033[0;103m"), + BLUE_BACKGROUND_BRIGHT("\033[0;104m"), + MAGENTA_BACKGROUND_BRIGHT("\033[0;105m"), + CYAN_BACKGROUND_BRIGHT("\033[0;106m"), + WHITE_BACKGROUND_BRIGHT("\033[0;107m"); + + private Color(String aCode) { + code = aCode; + } + + @Override + public String toString() { + return code; + } + + private final String code; + + } + +} diff --git a/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-1.cobol b/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-1.cobol index cb58f13bf9..94ad2ba8ed 100644 --- a/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-1.cobol +++ b/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-1.cobol @@ -6,7 +6,7 @@ 01 ringer BELL. PROCEDURE DIVISION. - DISPLAY ringer + DISPLAY ringer. STOP RUN. END PROGRAM ring-terminal-bell. diff --git a/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-2.cobol b/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-2.cobol index 44ce470ca5..b7605d8e60 100644 --- a/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-2.cobol +++ b/Task/Terminal-control-Ringing-the-terminal-bell/COBOL/terminal-control-ringing-the-terminal-bell-2.cobol @@ -1,4 +1,4 @@ - *> Tectonics: cobc -xj ring-terminal-bell.cob -std=cobol85 + *> Tectonics: cobc -xj ring-terminal-bell.cob --std=cobol85 IDENTIFICATION DIVISION. PROGRAM-ID. ring-ascii-bell. @@ -10,7 +10,8 @@ ALPHABET ASCII IS STANDARD-1. PROCEDURE DIVISION. - DISPLAY FUNCTION CHAR(8) WITH NO ADVANCING + DISPLAY FUNCTION CHAR(8) WITH NO ADVANCING. + *> COBOL indexes starting from 1. STOP RUN. END PROGRAM ring-ascii-bell. diff --git a/Task/Terminal-control-Ringing-the-terminal-bell/Dc/terminal-control-ringing-the-terminal-bell.dc b/Task/Terminal-control-Ringing-the-terminal-bell/Dc/terminal-control-ringing-the-terminal-bell.dc new file mode 100644 index 0000000000..643998e3ea --- /dev/null +++ b/Task/Terminal-control-Ringing-the-terminal-bell/Dc/terminal-control-ringing-the-terminal-bell.dc @@ -0,0 +1 @@ +7P diff --git a/Task/Terminal-control-Ringing-the-terminal-bell/Joy/terminal-control-ringing-the-terminal-bell.joy b/Task/Terminal-control-Ringing-the-terminal-bell/Joy/terminal-control-ringing-the-terminal-bell.joy new file mode 100644 index 0000000000..123d6825d1 --- /dev/null +++ b/Task/Terminal-control-Ringing-the-terminal-bell/Joy/terminal-control-ringing-the-terminal-bell.joy @@ -0,0 +1 @@ +7 putch. diff --git a/Task/Terminal-control-Ringing-the-terminal-bell/OCaml/terminal-control-ringing-the-terminal-bell.ocaml b/Task/Terminal-control-Ringing-the-terminal-bell/OCaml/terminal-control-ringing-the-terminal-bell.ocaml new file mode 100644 index 0000000000..ba2c05bba6 --- /dev/null +++ b/Task/Terminal-control-Ringing-the-terminal-bell/OCaml/terminal-control-ringing-the-terminal-bell.ocaml @@ -0,0 +1 @@ +let () = print_string "\x07" diff --git a/Task/The-sieve-of-Sundaram/C++/the-sieve-of-sundaram.cpp b/Task/The-sieve-of-Sundaram/C++/the-sieve-of-sundaram.cpp new file mode 100644 index 0000000000..659ca3aa03 --- /dev/null +++ b/Task/The-sieve-of-Sundaram/C++/the-sieve-of-sundaram.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +std::vector sieve_of_sundaram(const uint32_t& limit) { + std::vector primes = {}; + if ( limit < 3 ) { + return primes; + } + + const uint32_t k = ( limit - 3 ) / 2 + 1; + std::vector marked(k, true); + for ( uint32_t i = 0; i < ( std::sqrt(limit) - 3 ) / 2 + 1; ++i ) { + uint32_t p = 2 * i + 3; + uint32_t s = ( p * p - 3 ) / 2; + for ( uint32_t j = s; j < k; j += p ) { + marked[j] = false; + } + } + + for ( uint32_t i = 0; i < k; ++i ) { + if ( marked[i] ) { + primes.emplace_back(2 * i + 3); + } + } + return primes; +} + +int main() { + std::vector primes = sieve_of_sundaram(16'000'000); + std::cout << "The first 100 odd primes generated by the Sieve of Sundaram:" << std::endl; + for ( uint32_t i = 0; i < 100; ++i ) { + std::cout << std::setw(3) << primes[i] << ( i % 10 == 9 ? "\n" :" " ); + } + std::cout << "\n" << "The 1_000_000th Sundaram prime is " << primes[1'000'000 - 1] << std::endl; +} diff --git a/Task/The-sieve-of-Sundaram/Java/the-sieve-of-sundaram.java b/Task/The-sieve-of-Sundaram/Java/the-sieve-of-sundaram.java new file mode 100644 index 0000000000..8ae2a34494 --- /dev/null +++ b/Task/The-sieve-of-Sundaram/Java/the-sieve-of-sundaram.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public final class TheSieveOfSundaram { + + public static void main(String[] args) { + List primes = sieveOfSundaram(16_000_000); + System.out.println("The first 100 odd primes generated by the Sieve of Sundaram:"); + for ( int i = 0; i < 100; i++ ) { + System.out.print(String.format("%3d%s", primes.get(i), ( i % 10 == 9 ? "\n" :" " ))); + } + System.out.println(); + System.out.println("The 1_000_000th Sundaram prime is " + primes.get(1_000_000 - 1)); + } + + private static List sieveOfSundaram(int limit) { + List primes = new ArrayList(); + if ( limit < 3 ) { + return primes; + } + + final int k = ( limit - 3 ) / 2 + 1; + boolean[] marked = new boolean[k]; + for ( int i = 0; i < ( (int) Math.sqrt(limit) - 3 ) / 2 + 1; i++ ) { + int p = 2 * i + 3; + int s = ( p * p - 3 ) / 2; + for ( int j = s; j < k; j += p ) { + marked[j] = true; + } + } + + for ( int i = 0; i < k; i++ ) { + if ( ! marked[i] ) { + primes.add(2 * i + 3); + } + } + return primes; + } + +} diff --git a/Task/The-sieve-of-Sundaram/Raku/the-sieve-of-sundaram.raku b/Task/The-sieve-of-Sundaram/Raku/the-sieve-of-sundaram.raku index 3c20171e4f..abb111533a 100644 --- a/Task/The-sieve-of-Sundaram/Raku/the-sieve-of-sundaram.raku +++ b/Task/The-sieve-of-Sundaram/Raku/the-sieve-of-sundaram.raku @@ -6,12 +6,13 @@ my int @sieve; @sieve[$k] = 0; -hyper for 1 .. $k -> \i { - my int $j = i; - while (my int $l = i + $j + 2 * i * $j) < $k { +race for (1 .. $k).batch(1000) -> @i { + for @i -> int $i { + my int $j = $i; + while (my int $l = $i + $j + 2 * $i * $j++) < $k { @sieve[$l] = 1; - $j = $j + 1; } + } } @sieve[0] = 1; diff --git a/Task/Time-a-function/EasyLang/time-a-function.easy b/Task/Time-a-function/EasyLang/time-a-function.easy new file mode 100644 index 0000000000..e5f6214948 --- /dev/null +++ b/Task/Time-a-function/EasyLang/time-a-function.easy @@ -0,0 +1,25 @@ +func fua lim . + # this is interpreted + i = 1 + while i <= lim + sum += i + i += 1 + . + return sum +. +start = systime +print fua 1e8 +print systime - start +# +fastfunc fub lim . + # this is compiled to wasm + i = 1 + while i <= lim + sum += i + i += 1 + . + return sum +. +start = systime +print fub 1e8 +print systime - start diff --git a/Task/Time-a-function/Quackery/time-a-function.quackery b/Task/Time-a-function/Quackery/time-a-function.quackery new file mode 100644 index 0000000000..e17ed465bc --- /dev/null +++ b/Task/Time-a-function/Quackery/time-a-function.quackery @@ -0,0 +1,6 @@ + [ time ]'[ do + time swap - 1000 / ] is time: ( --> n ) + + time: [ 0 314159 times 1+ echo ] + cr cr + say "That took about " echo say " milliseconds." diff --git a/Task/Tokenize-a-string/EasyLang/tokenize-a-string.easy b/Task/Tokenize-a-string/EasyLang/tokenize-a-string.easy new file mode 100644 index 0000000000..3a40548fef --- /dev/null +++ b/Task/Tokenize-a-string/EasyLang/tokenize-a-string.easy @@ -0,0 +1,3 @@ +s$ = "Hello,How,Are,You,Today" +a$[] = strsplit s$ "," +print a$[] diff --git a/Task/Tonelli-Shanks-algorithm/C++/tonelli-shanks-algorithm.cpp b/Task/Tonelli-Shanks-algorithm/C++/tonelli-shanks-algorithm.cpp new file mode 100644 index 0000000000..0b3ebd2aba --- /dev/null +++ b/Task/Tonelli-Shanks-algorithm/C++/tonelli-shanks-algorithm.cpp @@ -0,0 +1,112 @@ +#include +#include +#include + +struct Pair { + uint64_t n; + uint64_t p; +}; + +struct Solution { + uint64_t root1; + uint64_t root2; + bool is_square; +}; + +uint64_t multiply_modulus(uint64_t a, uint64_t b, const uint64_t& modulus) { + a %= modulus; b %= modulus; + if ( b < a ) { + uint64_t temp = a; a = b; b = temp; + } + + uint64_t result = 0; + while ( a > 0 ) { + if ( a % 2 == 1 ) { + result = ( result + b ) % modulus; + }; + b = ( b * 2 ) % modulus; + a >>= 1; + } + return result; +} + +uint64_t power_modulus(uint64_t base, uint64_t exponent, const uint64_t& modulus) { + if ( modulus == 1 ) { + return 0; + } + + base %= modulus; + uint64_t result = 1; + while ( exponent > 0 ) { + if ( ( exponent & 1 ) == 1 ) { + result = multiply_modulus(result, base, modulus); + } + base = multiply_modulus(base, base, modulus); + exponent >>= 1; + } + return result; +} + +uint64_t legendre(const uint64_t& a, const uint64_t& p) { + return power_modulus(a, ( p - 1 ) / 2, p); +} + +Solution tonelli_shanks(const uint64_t& n, const uint64_t& p) { + if ( legendre(n, p) != 1 ) { + return Solution(0, 0, false); + } + + // Factor out powers of 2 from p - 1 + uint64_t q = p - 1; + uint64_t s = 0; + while ( q % 2 == 0 ) { + q /= 2; + s += 1; + } + + if ( s == 1 ) { + uint64_t result = power_modulus(n, ( p + 1 ) / 4, p); + return Solution(result, p - result, true); + } + + // Find a non-square z such as ( z | p ) = -1 + uint64_t z = 2; + while ( legendre(z, p) != p - 1 ) { + z += 1; + } + + uint64_t c = power_modulus(z, q, p); + uint64_t t = power_modulus(n, q, p); + uint64_t m = s; + uint64_t result = power_modulus(n, ( q + 1 ) >> 1, p); + + while ( t != 1 ) { + uint64_t i = 1; + z = multiply_modulus(t, t, p); + while ( z != 1 && i < m - 1 ) { + i += 1; + z = multiply_modulus(z, z, p); + } + uint64_t b = power_modulus(c, 1 << ( m - i - 1 ), p); + c = multiply_modulus(b, b, p); + t = multiply_modulus(t, c, p); + m = i; + result = multiply_modulus(result, b, p); + } + return Solution(result, p - result, true); +} + +int main() { + const std::vector tests = { Pair(10, 13), Pair(56, 101), Pair(1030, 1009), Pair(1032, 1009), + Pair(44402, 100049), Pair(665820697, 1000000009), Pair(881398088036, 1000000000039) }; + + for ( const Pair& test : tests ) { + Solution solution = tonelli_shanks(test.n, test.p); + std::cout << "n = " << test.n << ", p = " << test.p; + if ( solution.is_square == true ) { + std::cout << " has solutions: " << solution.root1 << " and " << solution.root2 << std::endl << std::endl; + } else { + std::cout << " has no solutions because n is not a square modulo p" << std::endl << std::endl; + } + } +} diff --git a/Task/Unicode-variable-names/Haskell/unicode-variable-names.hs b/Task/Unicode-variable-names/Haskell/unicode-variable-names-1.hs similarity index 100% rename from Task/Unicode-variable-names/Haskell/unicode-variable-names.hs rename to Task/Unicode-variable-names/Haskell/unicode-variable-names-1.hs diff --git a/Task/Unicode-variable-names/Haskell/unicode-variable-names-2.hs b/Task/Unicode-variable-names/Haskell/unicode-variable-names-2.hs new file mode 100644 index 0000000000..7dd39abd5b --- /dev/null +++ b/Task/Unicode-variable-names/Haskell/unicode-variable-names-2.hs @@ -0,0 +1,2 @@ +(let Δ😄 1) +(inc Δ😄) diff --git a/Task/Variadic-function/Insitux/variadic-function.insitux b/Task/Variadic-function/Insitux/variadic-function.insitux index 365cf73ae7..322a8466ad 100644 --- a/Task/Variadic-function/Insitux/variadic-function.insitux +++ b/Task/Variadic-function/Insitux/variadic-function.insitux @@ -1,5 +1,4 @@ (function f - (loop-over args a - (print a))) + (print (join "\n" args))) (f 1 2 3 4)