From 61b93a2cd130ace8ddc73f628d534c7b017d254c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Tue, 1 Aug 2023 14:30:30 -0700 Subject: [PATCH] Data update --- Conf/lang.yaml | 1 + Lang/AArch64-Assembly/Best-shuffle | 1 + Lang/AArch64-Assembly/Filter | 1 + Lang/AArch64-Assembly/Sort-disjoint-sublist | 1 + Lang/ALGOL-W/Amicable-pairs | 1 + Lang/ALGOL-W/Euclid-Mullin-sequence | 1 + Lang/ALGOL-W/Pell-numbers | 1 + Lang/ANSI-BASIC/Prime-decomposition | 1 + Lang/APL/Hex-words | 1 + Lang/ARM-Assembly/Best-shuffle | 1 + Lang/ARM-Assembly/Filter | 1 + Lang/ARM-Assembly/Sort-disjoint-sublist | 1 + Lang/Applesoft-BASIC/Bifid-cipher | 1 + .../Case-sensitivity-of-identifiers | 1 + Lang/Applesoft-BASIC/Look-and-say-sequence | 1 + Lang/BASIC/Case-sensitivity-of-identifiers | 1 - ...ficient-and-perfect-number-classifications | 1 + Lang/BASIC256/Goldbachs-comet | 1 + Lang/BASIC256/Middle-three-digits | 1 + Lang/BASIC256/Number-names | 1 + Lang/BASIC256/Sieve-of-Pritchard | 1 + Lang/Bait/Loops-While | 1 + Lang/C++/Fortunate-numbers | 1 + Lang/C++/Hex-words | 1 + Lang/C++/History-variables | 1 + Lang/C++/Holidays-related-to-Easter | 1 + Lang/C++/Jordan-P-lya-numbers | 1 + Lang/C/00-LANG.txt | 93 +++++---- Lang/C3/Command-line-arguments | 1 + Lang/C3/Loops-Continue | 1 + Lang/C3/Loops-Do-while | 1 + Lang/C3/Loops-Downward-for | 1 + Lang/C3/Loops-For | 1 + Lang/C3/Loops-For-with-a-specified-step | 1 + Lang/C3/Loops-Foreach | 1 + Lang/C3/Loops-Infinite | 1 + ...ficient-and-perfect-number-classifications | 1 + Lang/Chipmunk-Basic/Ackermann-function | 1 + Lang/Chipmunk-Basic/Amicable-pairs | 1 + .../Case-sensitivity-of-identifiers | 1 + Lang/Chipmunk-Basic/Look-and-say-sequence | 1 + ...Pseudo-random-numbers-Middle-square-method | 1 + Lang/Chipmunk-Basic/Sort-disjoint-sublist | 1 + Lang/Commodore-BASIC/Execute-Brain- | 1 + Lang/Cowgol/Case-sensitivity-of-identifiers | 1 + Lang/Dart/Case-sensitivity-of-identifiers | 1 + Lang/Dart/Pick-random-element | 1 + Lang/Dart/Yin-and-yang | 1 + Lang/Draco/Case-sensitivity-of-identifiers | 1 + Lang/FreeBASIC/Sieve-of-Pritchard | 1 + ...ficient-and-perfect-number-classifications | 1 + Lang/FutureBasic/Amicable-pairs | 1 + Lang/FutureBasic/Ascending-primes | 1 + Lang/FutureBasic/Bell-numbers | 1 + Lang/FutureBasic/Compare-a-list-of-strings | 1 + .../Create-a-two-dimensional-array-at-runtime | 1 + Lang/FutureBasic/Descending-primes | 1 + Lang/FutureBasic/Duffinian-numbers | 1 + Lang/FutureBasic/Emirp-primes | 1 + Lang/FutureBasic/Extensible-prime-generator | 1 + Lang/FutureBasic/Write-entire-file | 1 + Lang/GW-BASIC/Case-sensitivity-of-identifiers | 1 + Lang/GW-BASIC/Sort-disjoint-sublist | 1 + ...ficient-and-perfect-number-classifications | 1 + Lang/Gambas/Amicable-pairs | 1 + Lang/Gambas/Wagstaff-primes | 1 + Lang/Insitux/00-LANG.txt | 8 +- Lang/Insitux/ABC-problem | 1 + Lang/Insitux/Amb | 1 + Lang/Insitux/Attractive-numbers | 1 + Lang/Insitux/Comments | 1 + Lang/Insitux/Flatten-a-list | 1 + .../Generate-lower-case-ASCII-alphabet | 1 + Lang/Insitux/Letter-frequency | 1 + Lang/Java/First-class-environments | 1 + ...st-class-functions-Use-numbers-analogously | 1 + Lang/Java/Fortunate-numbers | 1 + Lang/Java/Goldbachs-comet | 1 + Lang/Java/Gotchas | 1 + Lang/Java/HTTPS-Authenticated | 1 + Lang/Java/HTTPS-Client-authenticated | 1 + Lang/Java/Halt-and-catch-fire | 1 + Lang/Java/Hex-words | 1 + Lang/Java/Home-primes | 1 + Lang/Java/Jordan-P-lya-numbers | 1 + Lang/Lua/Bifid-cipher | 1 + Lang/Lua/Euclid-Mullin-sequence | 1 + Lang/Lua/Hex-words | 1 + Lang/Lua/Hofstadter-Q-sequence | 1 + Lang/Lua/Long-year | 1 + Lang/MACRO-11/Binary-search | 1 + .../MSX-Basic/Case-sensitivity-of-identifiers | 1 + Lang/MSX-Basic/Mandelbrot-set | 1 + Lang/MiniScript/Amicable-pairs | 1 + Lang/MiniScript/Euclid-Mullin-sequence | 1 + .../Case-sensitivity-of-identifiers | 1 + Lang/Minimal-BASIC/Sort-disjoint-sublist | 1 + Lang/Modula-2/Binary-search | 1 + Lang/Modula-2/Prime-decomposition | 1 + Lang/N-t-roff/Case-sensitivity-of-identifiers | 1 + Lang/N-t-roff/Loops-Downward-for | 1 + Lang/N-t-roff/Loops-For-with-a-specified-step | 1 + Lang/N-t-roff/Multiplication-tables | 1 + Lang/Perl/Radical-of-an-integer | 1 + Lang/PicoLisp/Abelian-sandpile-model | 1 + Lang/Plain-English/00-LANG.txt | 190 +++++++++++++++++ Lang/QBasic/Amicable-pairs | 1 + Lang/QBasic/Case-sensitivity-of-identifiers | 1 + .../Case-sensitivity-of-identifiers | 1 + Lang/RPL/00-LANG.txt | 4 +- Lang/RPL/Middle-three-digits | 1 - Lang/Ring/Euclid-Mullin-sequence | 1 + Lang/Ruby/Euclid-Mullin-sequence | 1 + Lang/Ruby/Next-highest-int-from-digits | 1 + Lang/Ruby/Pell-numbers | 1 + Lang/Ruby/Terminal-control-Cursor-movement | 1 + ...ficient-and-perfect-number-classifications | 1 + Lang/Rust/Home-primes | 1 + Lang/TRS-80-BASIC/00-LANG.txt | 8 + Lang/TRS-80-BASIC/00-META.yaml | 2 + Lang/TRS-80-BASIC/Execute-Brain- | 1 + ...ficient-and-perfect-number-classifications | 1 + Lang/True-BASIC/Ackermann-function | 1 + Lang/True-BASIC/Amicable-pairs | 1 + Lang/True-BASIC/Look-and-say-sequence | 1 + Lang/True-BASIC/Mandelbrot-set | 1 + Lang/True-BASIC/Sieve-of-Pritchard | 1 + Lang/True-BASIC/Sort-disjoint-sublist | 1 + Lang/XBasic/Case-sensitivity-of-identifiers | 1 + Lang/Yabasic/Middle-three-digits | 1 + Lang/Yabasic/Sieve-of-Pritchard | 1 + Lang/Yabasic/Sort-disjoint-sublist | 1 + Lang/Zig/Huffman-coding | 1 + Lang/Zig/Run-length-encoding | 1 + Task/ABC-problem/Insitux/abc-problem.insitux | 8 + .../PicoLisp/abelian-sandpile-model.l | 27 +++ ...t-and-perfect-number-classifications.basic | 31 +++ ...t-and-perfect-number-classifications.basic | 30 +++ ...t-and-perfect-number-classifications.basic | 30 +++ ...-and-perfect-number-classifications.gambas | 32 +++ ...t-and-perfect-number-classifications.basic | 36 ++++ ...t-and-perfect-number-classifications.basic | 32 +++ .../Chipmunk-Basic/ackermann-function.basic | 14 ++ .../True-BASIC/ackermann-function.basic | 18 ++ ...iable-to-a-class-instance-at-runtime.elena | 22 +- Task/Amb/Elena/amb.elena | 18 +- Task/Amb/Insitux/amb.insitux | 10 + .../ALGOL-60/amicable-pairs.alg | 2 +- .../ALGOL-68/amicable-pairs.alg | 11 +- .../Amicable-pairs/ALGOL-W/amicable-pairs.alg | 23 +++ .../Chipmunk-Basic/amicable-pairs.basic | 20 ++ .../FutureBasic/amicable-pairs.basic | 29 +++ .../Gambas/amicable-pairs.gambas | 33 +++ ...micable-pairs.lua => amicable-pairs-1.lua} | 0 Task/Amicable-pairs/Lua/amicable-pairs-2.lua | 15 ++ .../MiniScript/amicable-pairs.mini | 17 ++ ...micable-pairs.pli => amicable-pairs-1.pli} | 0 .../PL-I-80/amicable-pairs-2.pli | 34 +++ Task/Amicable-pairs/PL-M/amicable-pairs.plm | 5 +- .../QBasic/amicable-pairs.basic | 19 ++ .../True-BASIC/amicable-pairs.basic | 19 ++ ...rational.cpp => arithmetic-rational-1.cpp} | 0 .../C++/arithmetic-rational-2.cpp | 129 ++++++++++++ .../FutureBasic/ascending-primes.basic | 47 +++++ .../Insitux/attractive-numbers.insitux | 16 ++ .../FutureBasic/bell-numbers.basic | 18 ++ .../AArch64-Assembly/best-shuffle.aarch64 | 195 ++++++++++++++++++ .../ARM-Assembly/best-shuffle.arm | 176 ++++++++++++++++ .../Applesoft-BASIC/bifid-cipher.basic | 45 ++++ Task/Bifid-cipher/Lua/bifid-cipher.lua | 73 +++++++ .../MACRO-11/binary-search.macro11 | 46 +++++ .../Binary-search/Modula-2/binary-search.mod2 | 70 +++++++ .../case-sensitivity-of-identifiers.basic | 1 + .../case-sensitivity-of-identifiers.basic | 5 + .../case-sensitivity-of-identifiers.cowgol | 13 ++ .../Dart/case-sensitivity-of-identifiers.dart | 5 + .../case-sensitivity-of-identifiers.draco | 8 + .../case-sensitivity-of-identifiers.basic | 5 + .../case-sensitivity-of-identifiers.basic | 5 + .../case-sensitivity-of-identifiers.basic | 4 + .../case-sensitivity-of-identifiers.ntroff | 4 + .../case-sensitivity-of-identifiers.basic | 0 .../case-sensitivity-of-identifiers.basic | 4 + .../case-sensitivity-of-identifiers.basic | 14 ++ .../case-sensitivity-of-identifiers.basic | 3 +- Task/Chaocipher/00-TASK.txt | 2 +- .../C3/command-line-arguments.c3 | 10 + Task/Comments/Insitux/comments.insitux | 10 + .../compare-a-list-of-strings.basic | 44 ++++ ...e-a-two-dimensional-array-at-runtime.basic | 12 ++ .../FutureBasic/descending-primes.basic | 47 +++++ .../00-TASK.txt | 5 + ...ilosophers.py => dining-philosophers-1.py} | 0 .../Python/dining-philosophers-2.py | 189 +++++++++++++++++ .../FutureBasic/duffinian-numbers.basic | 70 +++++++ .../FutureBasic/emirp-primes.basic | 60 ++++++ .../ALGOL-W/euclid-mullin-sequence.alg | 22 ++ ...uence.awk => euclid-mullin-sequence-1.awk} | 0 .../AWK/euclid-mullin-sequence-2.awk | 24 +++ .../Go/euclid-mullin-sequence.go | 29 +-- .../Lua/euclid-mullin-sequence-1.lua | 20 ++ .../Lua/euclid-mullin-sequence-2.lua | 24 +++ .../MiniScript/euclid-mullin-sequence.mini | 19 ++ .../Ring/euclid-mullin-sequence.ring | 18 ++ .../Ruby/euclid-mullin-sequence.rb | 15 ++ .../Wren/euclid-mullin-sequence-1.wren | 45 +--- .../Wren/euclid-mullin-sequence-2.wren | 33 ++- .../Commodore-BASIC/execute-brain-.basic | 65 ++++++ .../TRS-80-BASIC/execute-brain-.basic | 73 +++++++ .../extensible-prime-generator.basic | 53 +++++ Task/Filter/AArch64-Assembly/filter.aarch64 | 142 +++++++++++++ Task/Filter/ARM-Assembly/filter.arm | 144 +++++++++++++ .../Java/first-class-environments.java | 75 +++++++ ...ass-functions-use-numbers-analogously.java | 24 +++ Task/FizzBuzz/00-TASK.txt | 6 +- .../Insitux/flatten-a-list.insitux | 1 + .../C++/fortunate-numbers.cpp | 50 +++++ .../Java/fortunate-numbers.java | 41 ++++ ...generate-lower-case-ascii-alphabet.insitux | 4 + .../BASIC256/goldbachs-comet.basic | 30 +++ .../Goldbachs-comet/Java/goldbachs-comet.java | 76 +++++++ Task/Gotchas/Java/gotchas.java | 47 +++++ .../FutureBasic/greatest-common-divisor.basic | 63 +++++- .../Java/https-authenticated.java | 39 ++++ .../Java/https-client-authenticated.java | 41 ++++ .../hailstone-sequence-2.applescript | 1 + .../Java/halt-and-catch-fire.java | 11 + Task/Hello-world-Text/C3/hello-world-text.c3 | 5 +- Task/Hex-words/APL/hex-words.apl | 20 ++ Task/Hex-words/C++/hex-words.cpp | 71 +++++++ Task/Hex-words/Java/hex-words.java | 62 ++++++ Task/Hex-words/Lua/hex-words.lua | 89 ++++++++ .../C++/history-variables.cpp | 60 ++++++ .../Lua/hofstadter-q-sequence.lua | 28 +++ .../C++/holidays-related-to-easter.cpp | 52 +++++ Task/Home-primes/Java/home-primes.java | 117 +++++++++++ Task/Home-primes/Rust/home-primes.rust | 57 +++++ Task/Huffman-coding/Zig/huffman-coding.zig | 135 ++++++++++++ .../Python/inheritance-single-2.py | 2 +- ...a => interactive-programming-repl--1.java} | 0 .../Java/interactive-programming-repl--2.java | 14 ++ .../isograms-and-heterograms-4.applescript | 69 +++++++ .../C++/jordan-p-lya-numbers.cpp | 80 +++++++ .../Java/jordan-p-lya-numbers.java | 67 ++++++ .../Jq/jordan-p-lya-numbers.jq | 8 +- .../Insitux/letter-frequency.insitux | 8 + Task/Long-year/Lua/long-year.lua | 12 ++ Task/Long-year/S-BASIC/long-year.basic | 4 +- .../look-and-say-sequence.basic | 12 ++ .../look-and-say-sequence.basic | 23 +++ .../Insitux/look-and-say-sequence.insitux | 4 +- .../True-BASIC/look-and-say-sequence.basic | 15 ++ Task/Loops-Continue/C3/loops-continue.c3 | 10 + Task/Loops-Do-while/C3/loops-do-while.c3 | 6 + .../C3/loops-downward-for.c3 | 4 + .../N-t-roff/loops-downward-for.ntroff | 4 + .../S-BASIC/loops-downward-for.basic | 2 +- .../C3/loops-for-with-a-specified-step.c3 | 1 + .../loops-for-with-a-specified-step.ntroff | 4 + Task/Loops-For/C3/loops-for.c3 | 5 + Task/Loops-Foreach/C3/loops-foreach.c3 | 2 + Task/Loops-Infinite/C3/loops-infinite-1.c3 | 1 + Task/Loops-Infinite/C3/loops-infinite-2.c3 | 1 + Task/Loops-Infinite/C3/loops-infinite-3.c3 | 1 + Task/Loops-Infinite/C3/loops-infinite-4.c3 | 6 + Task/Loops-While/Bait/loops-while.bait | 7 + .../Julia/mandelbrot-set-4.julia | 8 +- .../Julia/mandelbrot-set-6.julia | 12 +- .../MSX-Basic/mandelbrot-set.basic | 21 ++ .../Mandelbrot-set/Python/mandelbrot-set-5.py | 6 + .../Mandelbrot-set/Python/mandelbrot-set-7.py | 12 +- .../True-BASIC/mandelbrot-set.basic | 29 +++ .../BASIC256/middle-three-digits.basic | 23 +++ .../RPL/middle-three-digits.rpl | 16 -- .../Yabasic/middle-three-digits.basic | 29 +++ .../N-t-roff/multiplication-tables.ntroff | 19 ++ .../Ruby/next-highest-int-from-digits.rb | 15 ++ Task/Number-names/BASIC256/number-names.basic | 59 ++++++ .../C3/parametric-polymorphism-1.c3 | 10 +- .../C3/parametric-polymorphism-2.c3 | 6 +- Task/Pell-numbers/ALGOL-68/pell-numbers.alg | 40 +--- Task/Pell-numbers/ALGOL-W/pell-numbers.alg | 90 ++++++++ Task/Pell-numbers/Ruby/pell-numbers.rb | 37 ++++ .../Dart/pick-random-element.dart | 11 + .../REXX/pick-random-element-1.rexx | 63 ++++-- .../ANSI-BASIC/prime-decomposition.basic | 31 +++ .../Modula-2/prime-decomposition.mod2 | 55 +++++ ...-random-numbers-middle-square-method.basic | 5 + .../pseudo-random-numbers-splitmix64.phix | 94 +++++---- .../Perl/radical-of-an-integer.pl | 40 ++++ .../Forth/read-a-file-line-by-line-1.fth | 26 ++- .../Forth/read-a-file-line-by-line-2.fth | 19 +- .../Zig/run-length-encoding.zig | 129 ++++++++++++ .../BASIC256/sieve-of-pritchard.basic | 75 +++++++ .../FreeBASIC/sieve-of-pritchard.basic | 73 +++++++ .../True-BASIC/sieve-of-pritchard.basic | 76 +++++++ .../Yabasic/sieve-of-pritchard.basic | 70 +++++++ .../sort-disjoint-sublist.aarch64 | 150 ++++++++++++++ .../ARM-Assembly/sort-disjoint-sublist.arm | 139 +++++++++++++ .../sort-disjoint-sublist.basic | 28 +++ .../GW-BASIC/sort-disjoint-sublist.basic | 25 +++ .../Minimal-BASIC/sort-disjoint-sublist.basic | 28 +++ .../True-BASIC/sort-disjoint-sublist.basic | 33 +++ .../Yabasic/sort-disjoint-sublist.basic | 23 +++ .../Fortran/sorting-algorithms-quicksort.f | 2 +- .../terminal-control-clear-the-screen-3.rb | 2 + .../Ruby/terminal-control-cursor-movement.rb | 17 ++ .../Gambas/wagstaff-primes.gambas | 26 +++ .../C++/{word-wheel.cpp => word-wheel-1.cpp} | 0 Task/Word-wheel/C++/word-wheel-2.cpp | 88 ++++++++ Task/Word-wheel/Java/word-wheel.java | 82 ++++++-- .../FutureBasic/write-entire-file.basic | 13 ++ Task/Yin-and-yang/Dart/yin-and-yang.dart | 45 ++++ 313 files changed, 6160 insertions(+), 346 deletions(-) create mode 120000 Lang/AArch64-Assembly/Best-shuffle create mode 120000 Lang/AArch64-Assembly/Filter create mode 120000 Lang/AArch64-Assembly/Sort-disjoint-sublist create mode 120000 Lang/ALGOL-W/Amicable-pairs create mode 120000 Lang/ALGOL-W/Euclid-Mullin-sequence create mode 120000 Lang/ALGOL-W/Pell-numbers create mode 120000 Lang/ANSI-BASIC/Prime-decomposition create mode 120000 Lang/APL/Hex-words create mode 120000 Lang/ARM-Assembly/Best-shuffle create mode 120000 Lang/ARM-Assembly/Filter create mode 120000 Lang/ARM-Assembly/Sort-disjoint-sublist create mode 120000 Lang/Applesoft-BASIC/Bifid-cipher create mode 120000 Lang/Applesoft-BASIC/Case-sensitivity-of-identifiers create mode 120000 Lang/Applesoft-BASIC/Look-and-say-sequence delete mode 120000 Lang/BASIC/Case-sensitivity-of-identifiers create mode 120000 Lang/BASIC256/Abundant-deficient-and-perfect-number-classifications create mode 120000 Lang/BASIC256/Goldbachs-comet create mode 120000 Lang/BASIC256/Middle-three-digits create mode 120000 Lang/BASIC256/Number-names create mode 120000 Lang/BASIC256/Sieve-of-Pritchard create mode 120000 Lang/Bait/Loops-While create mode 120000 Lang/C++/Fortunate-numbers create mode 120000 Lang/C++/Hex-words create mode 120000 Lang/C++/History-variables create mode 120000 Lang/C++/Holidays-related-to-Easter create mode 120000 Lang/C++/Jordan-P-lya-numbers create mode 120000 Lang/C3/Command-line-arguments create mode 120000 Lang/C3/Loops-Continue create mode 120000 Lang/C3/Loops-Do-while create mode 120000 Lang/C3/Loops-Downward-for create mode 120000 Lang/C3/Loops-For create mode 120000 Lang/C3/Loops-For-with-a-specified-step create mode 120000 Lang/C3/Loops-Foreach create mode 120000 Lang/C3/Loops-Infinite create mode 120000 Lang/Chipmunk-Basic/Abundant-deficient-and-perfect-number-classifications create mode 120000 Lang/Chipmunk-Basic/Ackermann-function create mode 120000 Lang/Chipmunk-Basic/Amicable-pairs create mode 120000 Lang/Chipmunk-Basic/Case-sensitivity-of-identifiers create mode 120000 Lang/Chipmunk-Basic/Look-and-say-sequence create mode 120000 Lang/Chipmunk-Basic/Pseudo-random-numbers-Middle-square-method create mode 120000 Lang/Chipmunk-Basic/Sort-disjoint-sublist create mode 120000 Lang/Commodore-BASIC/Execute-Brain- create mode 120000 Lang/Cowgol/Case-sensitivity-of-identifiers create mode 120000 Lang/Dart/Case-sensitivity-of-identifiers create mode 120000 Lang/Dart/Pick-random-element create mode 120000 Lang/Dart/Yin-and-yang create mode 120000 Lang/Draco/Case-sensitivity-of-identifiers create mode 120000 Lang/FreeBASIC/Sieve-of-Pritchard create mode 120000 Lang/FutureBasic/Abundant-deficient-and-perfect-number-classifications create mode 120000 Lang/FutureBasic/Amicable-pairs create mode 120000 Lang/FutureBasic/Ascending-primes create mode 120000 Lang/FutureBasic/Bell-numbers create mode 120000 Lang/FutureBasic/Compare-a-list-of-strings create mode 120000 Lang/FutureBasic/Create-a-two-dimensional-array-at-runtime create mode 120000 Lang/FutureBasic/Descending-primes create mode 120000 Lang/FutureBasic/Duffinian-numbers create mode 120000 Lang/FutureBasic/Emirp-primes create mode 120000 Lang/FutureBasic/Extensible-prime-generator create mode 120000 Lang/FutureBasic/Write-entire-file create mode 120000 Lang/GW-BASIC/Case-sensitivity-of-identifiers create mode 120000 Lang/GW-BASIC/Sort-disjoint-sublist create mode 120000 Lang/Gambas/Abundant-deficient-and-perfect-number-classifications create mode 120000 Lang/Gambas/Amicable-pairs create mode 120000 Lang/Gambas/Wagstaff-primes create mode 120000 Lang/Insitux/ABC-problem create mode 120000 Lang/Insitux/Amb create mode 120000 Lang/Insitux/Attractive-numbers create mode 120000 Lang/Insitux/Comments create mode 120000 Lang/Insitux/Flatten-a-list create mode 120000 Lang/Insitux/Generate-lower-case-ASCII-alphabet create mode 120000 Lang/Insitux/Letter-frequency create mode 120000 Lang/Java/First-class-environments create mode 120000 Lang/Java/First-class-functions-Use-numbers-analogously create mode 120000 Lang/Java/Fortunate-numbers create mode 120000 Lang/Java/Goldbachs-comet create mode 120000 Lang/Java/Gotchas create mode 120000 Lang/Java/HTTPS-Authenticated create mode 120000 Lang/Java/HTTPS-Client-authenticated create mode 120000 Lang/Java/Halt-and-catch-fire create mode 120000 Lang/Java/Hex-words create mode 120000 Lang/Java/Home-primes create mode 120000 Lang/Java/Jordan-P-lya-numbers create mode 120000 Lang/Lua/Bifid-cipher create mode 120000 Lang/Lua/Euclid-Mullin-sequence create mode 120000 Lang/Lua/Hex-words create mode 120000 Lang/Lua/Hofstadter-Q-sequence create mode 120000 Lang/Lua/Long-year create mode 120000 Lang/MACRO-11/Binary-search create mode 120000 Lang/MSX-Basic/Case-sensitivity-of-identifiers create mode 120000 Lang/MSX-Basic/Mandelbrot-set create mode 120000 Lang/MiniScript/Amicable-pairs create mode 120000 Lang/MiniScript/Euclid-Mullin-sequence create mode 120000 Lang/Minimal-BASIC/Case-sensitivity-of-identifiers create mode 120000 Lang/Minimal-BASIC/Sort-disjoint-sublist create mode 120000 Lang/Modula-2/Binary-search create mode 120000 Lang/Modula-2/Prime-decomposition create mode 120000 Lang/N-t-roff/Case-sensitivity-of-identifiers create mode 120000 Lang/N-t-roff/Loops-Downward-for create mode 120000 Lang/N-t-roff/Loops-For-with-a-specified-step create mode 120000 Lang/N-t-roff/Multiplication-tables create mode 120000 Lang/Perl/Radical-of-an-integer create mode 120000 Lang/PicoLisp/Abelian-sandpile-model create mode 120000 Lang/QBasic/Amicable-pairs create mode 120000 Lang/QBasic/Case-sensitivity-of-identifiers create mode 120000 Lang/Quite-BASIC/Case-sensitivity-of-identifiers delete mode 120000 Lang/RPL/Middle-three-digits create mode 120000 Lang/Ring/Euclid-Mullin-sequence create mode 120000 Lang/Ruby/Euclid-Mullin-sequence create mode 120000 Lang/Ruby/Next-highest-int-from-digits create mode 120000 Lang/Ruby/Pell-numbers create mode 120000 Lang/Ruby/Terminal-control-Cursor-movement create mode 120000 Lang/Run-BASIC/Abundant-deficient-and-perfect-number-classifications create mode 120000 Lang/Rust/Home-primes create mode 100644 Lang/TRS-80-BASIC/00-LANG.txt create mode 100644 Lang/TRS-80-BASIC/00-META.yaml create mode 120000 Lang/TRS-80-BASIC/Execute-Brain- create mode 120000 Lang/True-BASIC/Abundant-deficient-and-perfect-number-classifications create mode 120000 Lang/True-BASIC/Ackermann-function create mode 120000 Lang/True-BASIC/Amicable-pairs create mode 120000 Lang/True-BASIC/Look-and-say-sequence create mode 120000 Lang/True-BASIC/Mandelbrot-set create mode 120000 Lang/True-BASIC/Sieve-of-Pritchard create mode 120000 Lang/True-BASIC/Sort-disjoint-sublist create mode 120000 Lang/XBasic/Case-sensitivity-of-identifiers create mode 120000 Lang/Yabasic/Middle-three-digits create mode 120000 Lang/Yabasic/Sieve-of-Pritchard create mode 120000 Lang/Yabasic/Sort-disjoint-sublist create mode 120000 Lang/Zig/Huffman-coding create mode 120000 Lang/Zig/Run-length-encoding create mode 100644 Task/ABC-problem/Insitux/abc-problem.insitux create mode 100644 Task/Abelian-sandpile-model/PicoLisp/abelian-sandpile-model.l create mode 100644 Task/Abundant-deficient-and-perfect-number-classifications/BASIC256/abundant-deficient-and-perfect-number-classifications.basic create mode 100644 Task/Abundant-deficient-and-perfect-number-classifications/Chipmunk-Basic/abundant-deficient-and-perfect-number-classifications.basic create mode 100644 Task/Abundant-deficient-and-perfect-number-classifications/FutureBasic/abundant-deficient-and-perfect-number-classifications.basic create mode 100644 Task/Abundant-deficient-and-perfect-number-classifications/Gambas/abundant-deficient-and-perfect-number-classifications.gambas create mode 100644 Task/Abundant-deficient-and-perfect-number-classifications/Run-BASIC/abundant-deficient-and-perfect-number-classifications.basic create mode 100644 Task/Abundant-deficient-and-perfect-number-classifications/True-BASIC/abundant-deficient-and-perfect-number-classifications.basic create mode 100644 Task/Ackermann-function/Chipmunk-Basic/ackermann-function.basic create mode 100644 Task/Ackermann-function/True-BASIC/ackermann-function.basic create mode 100644 Task/Amb/Insitux/amb.insitux create mode 100644 Task/Amicable-pairs/ALGOL-W/amicable-pairs.alg create mode 100644 Task/Amicable-pairs/Chipmunk-Basic/amicable-pairs.basic create mode 100644 Task/Amicable-pairs/FutureBasic/amicable-pairs.basic create mode 100644 Task/Amicable-pairs/Gambas/amicable-pairs.gambas rename Task/Amicable-pairs/Lua/{amicable-pairs.lua => amicable-pairs-1.lua} (100%) create mode 100644 Task/Amicable-pairs/Lua/amicable-pairs-2.lua create mode 100644 Task/Amicable-pairs/MiniScript/amicable-pairs.mini rename Task/Amicable-pairs/PL-I-80/{amicable-pairs.pli => amicable-pairs-1.pli} (100%) create mode 100644 Task/Amicable-pairs/PL-I-80/amicable-pairs-2.pli create mode 100644 Task/Amicable-pairs/QBasic/amicable-pairs.basic create mode 100644 Task/Amicable-pairs/True-BASIC/amicable-pairs.basic rename Task/Arithmetic-Rational/C++/{arithmetic-rational.cpp => arithmetic-rational-1.cpp} (100%) create mode 100644 Task/Arithmetic-Rational/C++/arithmetic-rational-2.cpp create mode 100644 Task/Ascending-primes/FutureBasic/ascending-primes.basic create mode 100644 Task/Attractive-numbers/Insitux/attractive-numbers.insitux create mode 100644 Task/Bell-numbers/FutureBasic/bell-numbers.basic create mode 100644 Task/Best-shuffle/AArch64-Assembly/best-shuffle.aarch64 create mode 100644 Task/Best-shuffle/ARM-Assembly/best-shuffle.arm create mode 100644 Task/Bifid-cipher/Applesoft-BASIC/bifid-cipher.basic create mode 100644 Task/Bifid-cipher/Lua/bifid-cipher.lua create mode 100644 Task/Binary-search/MACRO-11/binary-search.macro11 create mode 100644 Task/Binary-search/Modula-2/binary-search.mod2 create mode 100644 Task/Case-sensitivity-of-identifiers/Applesoft-BASIC/case-sensitivity-of-identifiers.basic create mode 100644 Task/Case-sensitivity-of-identifiers/Chipmunk-Basic/case-sensitivity-of-identifiers.basic create mode 100644 Task/Case-sensitivity-of-identifiers/Cowgol/case-sensitivity-of-identifiers.cowgol create mode 100644 Task/Case-sensitivity-of-identifiers/Dart/case-sensitivity-of-identifiers.dart create mode 100644 Task/Case-sensitivity-of-identifiers/Draco/case-sensitivity-of-identifiers.draco create mode 100644 Task/Case-sensitivity-of-identifiers/GW-BASIC/case-sensitivity-of-identifiers.basic create mode 100644 Task/Case-sensitivity-of-identifiers/MSX-Basic/case-sensitivity-of-identifiers.basic create mode 100644 Task/Case-sensitivity-of-identifiers/Minimal-BASIC/case-sensitivity-of-identifiers.basic create mode 100644 Task/Case-sensitivity-of-identifiers/N-t-roff/case-sensitivity-of-identifiers.ntroff rename Task/Case-sensitivity-of-identifiers/{BASIC => QBasic}/case-sensitivity-of-identifiers.basic (100%) create mode 100644 Task/Case-sensitivity-of-identifiers/Quite-BASIC/case-sensitivity-of-identifiers.basic create mode 100644 Task/Case-sensitivity-of-identifiers/XBasic/case-sensitivity-of-identifiers.basic create mode 100644 Task/Command-line-arguments/C3/command-line-arguments.c3 create mode 100644 Task/Comments/Insitux/comments.insitux create mode 100644 Task/Compare-a-list-of-strings/FutureBasic/compare-a-list-of-strings.basic create mode 100644 Task/Create-a-two-dimensional-array-at-runtime/FutureBasic/create-a-two-dimensional-array-at-runtime.basic create mode 100644 Task/Descending-primes/FutureBasic/descending-primes.basic rename Task/Dining-philosophers/Python/{dining-philosophers.py => dining-philosophers-1.py} (100%) create mode 100644 Task/Dining-philosophers/Python/dining-philosophers-2.py create mode 100644 Task/Duffinian-numbers/FutureBasic/duffinian-numbers.basic create mode 100644 Task/Emirp-primes/FutureBasic/emirp-primes.basic create mode 100644 Task/Euclid-Mullin-sequence/ALGOL-W/euclid-mullin-sequence.alg rename Task/Euclid-Mullin-sequence/AWK/{euclid-mullin-sequence.awk => euclid-mullin-sequence-1.awk} (100%) create mode 100644 Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence-2.awk create mode 100644 Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-1.lua create mode 100644 Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-2.lua create mode 100644 Task/Euclid-Mullin-sequence/MiniScript/euclid-mullin-sequence.mini create mode 100644 Task/Euclid-Mullin-sequence/Ring/euclid-mullin-sequence.ring create mode 100644 Task/Euclid-Mullin-sequence/Ruby/euclid-mullin-sequence.rb create mode 100644 Task/Execute-Brain-/Commodore-BASIC/execute-brain-.basic create mode 100644 Task/Execute-Brain-/TRS-80-BASIC/execute-brain-.basic create mode 100644 Task/Extensible-prime-generator/FutureBasic/extensible-prime-generator.basic create mode 100644 Task/Filter/AArch64-Assembly/filter.aarch64 create mode 100644 Task/Filter/ARM-Assembly/filter.arm create mode 100644 Task/First-class-environments/Java/first-class-environments.java create mode 100644 Task/First-class-functions-Use-numbers-analogously/Java/first-class-functions-use-numbers-analogously.java create mode 100644 Task/Flatten-a-list/Insitux/flatten-a-list.insitux create mode 100644 Task/Fortunate-numbers/C++/fortunate-numbers.cpp create mode 100644 Task/Fortunate-numbers/Java/fortunate-numbers.java create mode 100644 Task/Generate-lower-case-ASCII-alphabet/Insitux/generate-lower-case-ascii-alphabet.insitux create mode 100644 Task/Goldbachs-comet/BASIC256/goldbachs-comet.basic create mode 100644 Task/Goldbachs-comet/Java/goldbachs-comet.java create mode 100644 Task/Gotchas/Java/gotchas.java create mode 100644 Task/HTTPS-Authenticated/Java/https-authenticated.java create mode 100644 Task/HTTPS-Client-authenticated/Java/https-client-authenticated.java create mode 100644 Task/Halt-and-catch-fire/Java/halt-and-catch-fire.java create mode 100644 Task/Hex-words/APL/hex-words.apl create mode 100644 Task/Hex-words/C++/hex-words.cpp create mode 100644 Task/Hex-words/Java/hex-words.java create mode 100644 Task/Hex-words/Lua/hex-words.lua create mode 100644 Task/History-variables/C++/history-variables.cpp create mode 100644 Task/Hofstadter-Q-sequence/Lua/hofstadter-q-sequence.lua create mode 100644 Task/Holidays-related-to-Easter/C++/holidays-related-to-easter.cpp create mode 100644 Task/Home-primes/Java/home-primes.java create mode 100644 Task/Home-primes/Rust/home-primes.rust create mode 100644 Task/Huffman-coding/Zig/huffman-coding.zig rename Task/Interactive-programming-repl-/Java/{interactive-programming-repl-.java => interactive-programming-repl--1.java} (100%) create mode 100644 Task/Interactive-programming-repl-/Java/interactive-programming-repl--2.java create mode 100644 Task/Isograms-and-heterograms/AppleScript/isograms-and-heterograms-4.applescript create mode 100644 Task/Jordan-P-lya-numbers/C++/jordan-p-lya-numbers.cpp create mode 100644 Task/Jordan-P-lya-numbers/Java/jordan-p-lya-numbers.java create mode 100644 Task/Letter-frequency/Insitux/letter-frequency.insitux create mode 100644 Task/Long-year/Lua/long-year.lua create mode 100644 Task/Look-and-say-sequence/Applesoft-BASIC/look-and-say-sequence.basic create mode 100644 Task/Look-and-say-sequence/Chipmunk-Basic/look-and-say-sequence.basic create mode 100644 Task/Look-and-say-sequence/True-BASIC/look-and-say-sequence.basic create mode 100644 Task/Loops-Continue/C3/loops-continue.c3 create mode 100644 Task/Loops-Do-while/C3/loops-do-while.c3 create mode 100644 Task/Loops-Downward-for/C3/loops-downward-for.c3 create mode 100644 Task/Loops-Downward-for/N-t-roff/loops-downward-for.ntroff create mode 100644 Task/Loops-For-with-a-specified-step/C3/loops-for-with-a-specified-step.c3 create mode 100644 Task/Loops-For-with-a-specified-step/N-t-roff/loops-for-with-a-specified-step.ntroff create mode 100644 Task/Loops-For/C3/loops-for.c3 create mode 100644 Task/Loops-Foreach/C3/loops-foreach.c3 create mode 100644 Task/Loops-Infinite/C3/loops-infinite-1.c3 create mode 100644 Task/Loops-Infinite/C3/loops-infinite-2.c3 create mode 100644 Task/Loops-Infinite/C3/loops-infinite-3.c3 create mode 100644 Task/Loops-Infinite/C3/loops-infinite-4.c3 create mode 100644 Task/Loops-While/Bait/loops-while.bait create mode 100644 Task/Mandelbrot-set/MSX-Basic/mandelbrot-set.basic create mode 100644 Task/Mandelbrot-set/True-BASIC/mandelbrot-set.basic create mode 100644 Task/Middle-three-digits/BASIC256/middle-three-digits.basic delete mode 100644 Task/Middle-three-digits/RPL/middle-three-digits.rpl create mode 100644 Task/Middle-three-digits/Yabasic/middle-three-digits.basic create mode 100644 Task/Multiplication-tables/N-t-roff/multiplication-tables.ntroff create mode 100644 Task/Next-highest-int-from-digits/Ruby/next-highest-int-from-digits.rb create mode 100644 Task/Number-names/BASIC256/number-names.basic create mode 100644 Task/Pell-numbers/ALGOL-W/pell-numbers.alg create mode 100644 Task/Pell-numbers/Ruby/pell-numbers.rb create mode 100644 Task/Pick-random-element/Dart/pick-random-element.dart create mode 100644 Task/Prime-decomposition/ANSI-BASIC/prime-decomposition.basic create mode 100644 Task/Prime-decomposition/Modula-2/prime-decomposition.mod2 create mode 100644 Task/Pseudo-random-numbers-Middle-square-method/Chipmunk-Basic/pseudo-random-numbers-middle-square-method.basic create mode 100644 Task/Radical-of-an-integer/Perl/radical-of-an-integer.pl create mode 100644 Task/Run-length-encoding/Zig/run-length-encoding.zig create mode 100644 Task/Sieve-of-Pritchard/BASIC256/sieve-of-pritchard.basic create mode 100644 Task/Sieve-of-Pritchard/FreeBASIC/sieve-of-pritchard.basic create mode 100644 Task/Sieve-of-Pritchard/True-BASIC/sieve-of-pritchard.basic create mode 100644 Task/Sieve-of-Pritchard/Yabasic/sieve-of-pritchard.basic create mode 100644 Task/Sort-disjoint-sublist/AArch64-Assembly/sort-disjoint-sublist.aarch64 create mode 100644 Task/Sort-disjoint-sublist/ARM-Assembly/sort-disjoint-sublist.arm create mode 100644 Task/Sort-disjoint-sublist/Chipmunk-Basic/sort-disjoint-sublist.basic create mode 100644 Task/Sort-disjoint-sublist/GW-BASIC/sort-disjoint-sublist.basic create mode 100644 Task/Sort-disjoint-sublist/Minimal-BASIC/sort-disjoint-sublist.basic create mode 100644 Task/Sort-disjoint-sublist/True-BASIC/sort-disjoint-sublist.basic create mode 100644 Task/Sort-disjoint-sublist/Yabasic/sort-disjoint-sublist.basic create mode 100644 Task/Terminal-control-Clear-the-screen/Ruby/terminal-control-clear-the-screen-3.rb create mode 100644 Task/Terminal-control-Cursor-movement/Ruby/terminal-control-cursor-movement.rb create mode 100644 Task/Wagstaff-primes/Gambas/wagstaff-primes.gambas rename Task/Word-wheel/C++/{word-wheel.cpp => word-wheel-1.cpp} (100%) create mode 100644 Task/Word-wheel/C++/word-wheel-2.cpp create mode 100644 Task/Write-entire-file/FutureBasic/write-entire-file.basic create mode 100644 Task/Yin-and-yang/Dart/yin-and-yang.dart diff --git a/Conf/lang.yaml b/Conf/lang.yaml index 27a023d46c..0525999c55 100644 --- a/Conf/lang.yaml +++ b/Conf/lang.yaml @@ -811,6 +811,7 @@ Transact-SQL: .sql Transd: .transd TransFORTH: .fth Trith: .trith +TRS-80 BASIC: .basic True BASIC: .basic TSE SAL: .tse Turbo-Basic XL: .basic diff --git a/Lang/AArch64-Assembly/Best-shuffle b/Lang/AArch64-Assembly/Best-shuffle new file mode 120000 index 0000000000..a0951b5654 --- /dev/null +++ b/Lang/AArch64-Assembly/Best-shuffle @@ -0,0 +1 @@ +../../Task/Best-shuffle/AArch64-Assembly \ No newline at end of file diff --git a/Lang/AArch64-Assembly/Filter b/Lang/AArch64-Assembly/Filter new file mode 120000 index 0000000000..d64eba35c1 --- /dev/null +++ b/Lang/AArch64-Assembly/Filter @@ -0,0 +1 @@ +../../Task/Filter/AArch64-Assembly \ No newline at end of file diff --git a/Lang/AArch64-Assembly/Sort-disjoint-sublist b/Lang/AArch64-Assembly/Sort-disjoint-sublist new file mode 120000 index 0000000000..af0be59923 --- /dev/null +++ b/Lang/AArch64-Assembly/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/AArch64-Assembly \ No newline at end of file diff --git a/Lang/ALGOL-W/Amicable-pairs b/Lang/ALGOL-W/Amicable-pairs new file mode 120000 index 0000000000..eb00d630bb --- /dev/null +++ b/Lang/ALGOL-W/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/ALGOL-W \ No newline at end of file diff --git a/Lang/ALGOL-W/Euclid-Mullin-sequence b/Lang/ALGOL-W/Euclid-Mullin-sequence new file mode 120000 index 0000000000..31033b3496 --- /dev/null +++ b/Lang/ALGOL-W/Euclid-Mullin-sequence @@ -0,0 +1 @@ +../../Task/Euclid-Mullin-sequence/ALGOL-W \ No newline at end of file diff --git a/Lang/ALGOL-W/Pell-numbers b/Lang/ALGOL-W/Pell-numbers new file mode 120000 index 0000000000..e4ac5c7f0d --- /dev/null +++ b/Lang/ALGOL-W/Pell-numbers @@ -0,0 +1 @@ +../../Task/Pell-numbers/ALGOL-W \ No newline at end of file diff --git a/Lang/ANSI-BASIC/Prime-decomposition b/Lang/ANSI-BASIC/Prime-decomposition new file mode 120000 index 0000000000..0d416fe46e --- /dev/null +++ b/Lang/ANSI-BASIC/Prime-decomposition @@ -0,0 +1 @@ +../../Task/Prime-decomposition/ANSI-BASIC \ No newline at end of file diff --git a/Lang/APL/Hex-words b/Lang/APL/Hex-words new file mode 120000 index 0000000000..7a46a08841 --- /dev/null +++ b/Lang/APL/Hex-words @@ -0,0 +1 @@ +../../Task/Hex-words/APL \ No newline at end of file diff --git a/Lang/ARM-Assembly/Best-shuffle b/Lang/ARM-Assembly/Best-shuffle new file mode 120000 index 0000000000..041ec84a9a --- /dev/null +++ b/Lang/ARM-Assembly/Best-shuffle @@ -0,0 +1 @@ +../../Task/Best-shuffle/ARM-Assembly \ No newline at end of file diff --git a/Lang/ARM-Assembly/Filter b/Lang/ARM-Assembly/Filter new file mode 120000 index 0000000000..7be8949b1d --- /dev/null +++ b/Lang/ARM-Assembly/Filter @@ -0,0 +1 @@ +../../Task/Filter/ARM-Assembly \ No newline at end of file diff --git a/Lang/ARM-Assembly/Sort-disjoint-sublist b/Lang/ARM-Assembly/Sort-disjoint-sublist new file mode 120000 index 0000000000..c5cadcbc7b --- /dev/null +++ b/Lang/ARM-Assembly/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/ARM-Assembly \ No newline at end of file diff --git a/Lang/Applesoft-BASIC/Bifid-cipher b/Lang/Applesoft-BASIC/Bifid-cipher new file mode 120000 index 0000000000..1e2daab5d3 --- /dev/null +++ b/Lang/Applesoft-BASIC/Bifid-cipher @@ -0,0 +1 @@ +../../Task/Bifid-cipher/Applesoft-BASIC \ No newline at end of file diff --git a/Lang/Applesoft-BASIC/Case-sensitivity-of-identifiers b/Lang/Applesoft-BASIC/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..123351bd24 --- /dev/null +++ b/Lang/Applesoft-BASIC/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Applesoft-BASIC \ No newline at end of file diff --git a/Lang/Applesoft-BASIC/Look-and-say-sequence b/Lang/Applesoft-BASIC/Look-and-say-sequence new file mode 120000 index 0000000000..134c9adfcf --- /dev/null +++ b/Lang/Applesoft-BASIC/Look-and-say-sequence @@ -0,0 +1 @@ +../../Task/Look-and-say-sequence/Applesoft-BASIC \ No newline at end of file diff --git a/Lang/BASIC/Case-sensitivity-of-identifiers b/Lang/BASIC/Case-sensitivity-of-identifiers deleted file mode 120000 index e8b0ce1495..0000000000 --- a/Lang/BASIC/Case-sensitivity-of-identifiers +++ /dev/null @@ -1 +0,0 @@ -../../Task/Case-sensitivity-of-identifiers/BASIC \ No newline at end of file diff --git a/Lang/BASIC256/Abundant-deficient-and-perfect-number-classifications b/Lang/BASIC256/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..8290029269 --- /dev/null +++ b/Lang/BASIC256/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/BASIC256 \ No newline at end of file diff --git a/Lang/BASIC256/Goldbachs-comet b/Lang/BASIC256/Goldbachs-comet new file mode 120000 index 0000000000..6a3eabcffe --- /dev/null +++ b/Lang/BASIC256/Goldbachs-comet @@ -0,0 +1 @@ +../../Task/Goldbachs-comet/BASIC256 \ No newline at end of file diff --git a/Lang/BASIC256/Middle-three-digits b/Lang/BASIC256/Middle-three-digits new file mode 120000 index 0000000000..a8c1d6ac74 --- /dev/null +++ b/Lang/BASIC256/Middle-three-digits @@ -0,0 +1 @@ +../../Task/Middle-three-digits/BASIC256 \ No newline at end of file diff --git a/Lang/BASIC256/Number-names b/Lang/BASIC256/Number-names new file mode 120000 index 0000000000..ba5d524763 --- /dev/null +++ b/Lang/BASIC256/Number-names @@ -0,0 +1 @@ +../../Task/Number-names/BASIC256 \ No newline at end of file diff --git a/Lang/BASIC256/Sieve-of-Pritchard b/Lang/BASIC256/Sieve-of-Pritchard new file mode 120000 index 0000000000..266a24b469 --- /dev/null +++ b/Lang/BASIC256/Sieve-of-Pritchard @@ -0,0 +1 @@ +../../Task/Sieve-of-Pritchard/BASIC256 \ No newline at end of file diff --git a/Lang/Bait/Loops-While b/Lang/Bait/Loops-While new file mode 120000 index 0000000000..4c1f6d7aff --- /dev/null +++ b/Lang/Bait/Loops-While @@ -0,0 +1 @@ +../../Task/Loops-While/Bait \ No newline at end of file diff --git a/Lang/C++/Fortunate-numbers b/Lang/C++/Fortunate-numbers new file mode 120000 index 0000000000..7264ffc786 --- /dev/null +++ b/Lang/C++/Fortunate-numbers @@ -0,0 +1 @@ +../../Task/Fortunate-numbers/C++ \ No newline at end of file diff --git a/Lang/C++/Hex-words b/Lang/C++/Hex-words new file mode 120000 index 0000000000..faf96263f0 --- /dev/null +++ b/Lang/C++/Hex-words @@ -0,0 +1 @@ +../../Task/Hex-words/C++ \ No newline at end of file diff --git a/Lang/C++/History-variables b/Lang/C++/History-variables new file mode 120000 index 0000000000..1e4a8dbc3b --- /dev/null +++ b/Lang/C++/History-variables @@ -0,0 +1 @@ +../../Task/History-variables/C++ \ No newline at end of file diff --git a/Lang/C++/Holidays-related-to-Easter b/Lang/C++/Holidays-related-to-Easter new file mode 120000 index 0000000000..021ab990c1 --- /dev/null +++ b/Lang/C++/Holidays-related-to-Easter @@ -0,0 +1 @@ +../../Task/Holidays-related-to-Easter/C++ \ No newline at end of file diff --git a/Lang/C++/Jordan-P-lya-numbers b/Lang/C++/Jordan-P-lya-numbers new file mode 120000 index 0000000000..2ced79cc8d --- /dev/null +++ b/Lang/C++/Jordan-P-lya-numbers @@ -0,0 +1 @@ +../../Task/Jordan-P-lya-numbers/C++ \ No newline at end of file diff --git a/Lang/C/00-LANG.txt b/Lang/C/00-LANG.txt index e91629b964..de69a4599c 100644 --- a/Lang/C/00-LANG.txt +++ b/Lang/C/00-LANG.txt @@ -29,27 +29,27 @@ C has since spread to many other [[:Category:Platforms|platforms]], and is now o ==Overview== ===Curly Braces=== -C uses curly braces as a separator for sections of code. All curly braces must be "balanced," i.e. every left curly brace must have a right curly brace after it. Nesting curly brace pairs inside curly braces is also acceptable as long as none of them are "lonely." Most advanced code editors will help you with curly braces by automatically typing the right brace as soon as you type the left one. +C uses curly braces as a separator for sections of code. All curly braces must be "balanced," i.e. every left curly brace must have a right curly brace after it. Nesting curly brace pairs inside curly braces is also acceptable as long as none of them are "lonely." -int main() -{ +Most advanced code editors will help you with curly braces by automatically typing the right brace as soon as you type the left one. It is a matter of style as to whether you prefer to place an opening curly brace on its own line or at the end of the previous line. Here we use the latter style. -// your main program goes here -// if you forgot either of these curly braces you would get an error message when you try to compile! +int main() { -} + // Your main program goes here. + // If you forgot either of these curly braces you would get an error message when you try to compile! + +} The contents of a function, if statement, etc. must be enclosed in curly braces for the code to count as part of that section. -{ -//this wouldn't actually compile as none of these variables were declared in this scope. More on that later. +{ + // This wouldn't actually compile as none of these variables were declared in this scope. More on that later. -if (K == 3) -{ -X = Y; //this line will be skipped if K doesn't equal 3. -} -Y = Z; //this is not part of the if statement. It will execute even if K doesn't equal 3. + if (K == 3) { + X = Y; // This line will be skipped if K doesn't equal 3. + } + Y = Z; // This is not part of the if statement. It will execute even if K doesn't equal 3. -} +} ===Semicolons=== Any "executable" statement must end in a semicolon, such as an assignment or function call. If you get an error message from your compiler, it won't explicitly tell you "Expected semicolon at end of line X." Go to the line number it says the error is at, and look a few lines above that. You might have forgotten a semicolon there. @@ -59,58 +59,57 @@ Unlike assembly which lets you jump anywhere or read any memory address, C impos ===Functions=== A function is made up of three parts: its return type, its name, and its arguments. -int main(void) //This is the function "main," which takes no arguments and returns a 32-bit signed integer value. +int main(void) // This is the function "main," which takes no arguments and returns a 32-bit signed integer value. -int sum(int a,int b) //This is the function "sum," which takes two integer arguments and returns an integer. +int sum(int a, int b) // This is the function "sum," which takes two integer arguments and returns an integer. void PlaySound(char songName) -//This takes a character string as an argument and presumably sends a command to sound hardware. -//It returns no values. Functions that have a return value of "void" typically do some sort of -//procedure whose outcome does not need to be measured or remembered later. +// This takes a character string as an argument and presumably sends a command to sound hardware. +// It returns no values. Functions that have a return value of "void" typically do some sort of +// procedure whose outcome does not need to be measured or remembered later. Note that the variable names listed as arguments when declaring a function are known as formal parameters and only are there to define the function. Variables with those names need not be declared or defined in your actual function, nor do they refer to any variables in your program that happen to have the same name. Essentially, formal parameters act as placeholders for the actual function parameters that you'll be using. -int foo(int x){ -return x; +int foo(int x) { + return x; } // "x" doesn't need to be a variable in your real program. If it is, that's not related in any way to the "x" here. -int main() -{ +int main() { -int y; -int z = 2; + int y; + int z = 2; -y = foo(z); //note that x was never involved. That's because the "x" earlier was the formal parameter. + y = foo(z); // Note that x was never involved. That's because the "x" earlier was the formal parameter. -} +} ===Assignment=== C allows you to define a variable as equal to a value, in more ways than just simple numerals. -int a = 3; //declare the variable a of type int, define it equal to decimal 3. +int a = 3; // Declare the variable a of type int, define it equal to decimal 3. -int b = -1; //declare the variable b of type int, define it equal to -1 (0xFFFFFFFF in hex) +int b = -1; // Declare the variable b of type int and equal to -1 (0xFFFFFFFF in hex). char letter = "A"; -//declare the variable "letter" of type char, it equals capital A. -//C allows you to treat an ascii value as its numeric equivalent whenever you feel like it. Other languages do not. +// Declare the variable "letter" of type char and equal to capital A. +// C allows you to treat an ascii value as its numeric equivalent whenever you feel like it. Other languages do not. -char myString = "Hello"; //define the array "myString" containing the letters "Hello" followed by a null terminator. +char *myString = "Hello"; // Define the array "myString" containing the letters "Hello" followed by a null terminator. -int myArray[5] = {10,20,30,40,50}; -//declare the array variable "myArray" containing integer values, with a maximum size of 5 elements. -//Then assign 10 to the beginning, 20 after it, 30 after that, and so on. +int myArray[5] = {10, 20, 30, 40, 50}; +// Declare the array variable "myArray" containing integer values, with a maximum size of 5 elements. +// Then assign 10 to the beginning, 20 after it, 30 after that, and so on. -int c = sum(a,b); -//declare the integer variable "c". -//Define it to equal the output of the function sum using the previously defined variables "a" and "b" as arguments. -//When this line of code is executed, the computer will perform the function "sum(a,b)" and store the result in c. -//This is only valid if the return type of the function "sum" matches the type of the variable "c." +int c = sum(a, b); +// Declare the integer variable "c". +// Define it to equal the output of the function sum using the previously defined variables "a" and "b" as arguments. +// When this line of code is executed, the computer will perform the function "sum(a,b)" and store the result in c. +// This is only valid if the return type of the function "sum" matches the type of the variable "c." ===Declaring vs. Defining=== This is a very unintuitive aspect of C that often confuses new users. Declaring a variable or function tells the compiler that a function may exist. Defining a variable or function assigns it a value or procedure, respectively. Compare the two examples below: -int a; // The variable "a" has been declared, but not defined. -a = 2; // Now the variable has been defined. +int a; // The variable "a" has been declared, but not defined. +a = 2; // Now the variable has been defined. -int a = 2; //The variable "a" has been both declared and defined. +int a = 2; // The variable "a" has been both declared and defined. * You cannot define a variable without declaring it first. * Before a variable can be used, it must be defined. @@ -129,13 +128,13 @@ You can also add a few modifiers in front of the variable type to be more specif * volatile tells the compiler that this variable's value can changed by the hardware. This is commonly used for hardware registers such as those that track the mouse cursor's location, a scanline counter, etc. The value will always be read from its original memory location, ensuring that its value is always up-to-date. Examples: -unsigned int x; -volatile int HorizontalScroll; +unsigned int x; +volatile int HorizontalScroll; Functions are declared in a similar fashion to variables, except a function's "type" is the type of the value it returns. -int foo(int bar); +int foo(int bar); // The function foo was declared. It takes an integer as an argument and returns an integer. -// What it actually does is currently unknown but can be defined later. +// What it actually does is currently unknown but can be defined later. ==Citation== *[[wp:C_%28programming_language%29|Wikipedia:C (programming language)]] diff --git a/Lang/C3/Command-line-arguments b/Lang/C3/Command-line-arguments new file mode 120000 index 0000000000..6dc09a6fa5 --- /dev/null +++ b/Lang/C3/Command-line-arguments @@ -0,0 +1 @@ +../../Task/Command-line-arguments/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-Continue b/Lang/C3/Loops-Continue new file mode 120000 index 0000000000..f66d22e3d8 --- /dev/null +++ b/Lang/C3/Loops-Continue @@ -0,0 +1 @@ +../../Task/Loops-Continue/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-Do-while b/Lang/C3/Loops-Do-while new file mode 120000 index 0000000000..993e10f705 --- /dev/null +++ b/Lang/C3/Loops-Do-while @@ -0,0 +1 @@ +../../Task/Loops-Do-while/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-Downward-for b/Lang/C3/Loops-Downward-for new file mode 120000 index 0000000000..446607d46f --- /dev/null +++ b/Lang/C3/Loops-Downward-for @@ -0,0 +1 @@ +../../Task/Loops-Downward-for/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-For b/Lang/C3/Loops-For new file mode 120000 index 0000000000..21cda2f4ec --- /dev/null +++ b/Lang/C3/Loops-For @@ -0,0 +1 @@ +../../Task/Loops-For/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-For-with-a-specified-step b/Lang/C3/Loops-For-with-a-specified-step new file mode 120000 index 0000000000..6ee66b7714 --- /dev/null +++ b/Lang/C3/Loops-For-with-a-specified-step @@ -0,0 +1 @@ +../../Task/Loops-For-with-a-specified-step/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-Foreach b/Lang/C3/Loops-Foreach new file mode 120000 index 0000000000..bf5ed82064 --- /dev/null +++ b/Lang/C3/Loops-Foreach @@ -0,0 +1 @@ +../../Task/Loops-Foreach/C3 \ No newline at end of file diff --git a/Lang/C3/Loops-Infinite b/Lang/C3/Loops-Infinite new file mode 120000 index 0000000000..6741d32d81 --- /dev/null +++ b/Lang/C3/Loops-Infinite @@ -0,0 +1 @@ +../../Task/Loops-Infinite/C3 \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Abundant-deficient-and-perfect-number-classifications b/Lang/Chipmunk-Basic/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..bcff1e67d9 --- /dev/null +++ b/Lang/Chipmunk-Basic/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Ackermann-function b/Lang/Chipmunk-Basic/Ackermann-function new file mode 120000 index 0000000000..ab65fb3b6b --- /dev/null +++ b/Lang/Chipmunk-Basic/Ackermann-function @@ -0,0 +1 @@ +../../Task/Ackermann-function/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Amicable-pairs b/Lang/Chipmunk-Basic/Amicable-pairs new file mode 120000 index 0000000000..09bede8926 --- /dev/null +++ b/Lang/Chipmunk-Basic/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Case-sensitivity-of-identifiers b/Lang/Chipmunk-Basic/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..d391f1e8e2 --- /dev/null +++ b/Lang/Chipmunk-Basic/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Look-and-say-sequence b/Lang/Chipmunk-Basic/Look-and-say-sequence new file mode 120000 index 0000000000..67f3a129f9 --- /dev/null +++ b/Lang/Chipmunk-Basic/Look-and-say-sequence @@ -0,0 +1 @@ +../../Task/Look-and-say-sequence/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Pseudo-random-numbers-Middle-square-method b/Lang/Chipmunk-Basic/Pseudo-random-numbers-Middle-square-method new file mode 120000 index 0000000000..c970e2efcf --- /dev/null +++ b/Lang/Chipmunk-Basic/Pseudo-random-numbers-Middle-square-method @@ -0,0 +1 @@ +../../Task/Pseudo-random-numbers-Middle-square-method/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Chipmunk-Basic/Sort-disjoint-sublist b/Lang/Chipmunk-Basic/Sort-disjoint-sublist new file mode 120000 index 0000000000..8cc8a9f39a --- /dev/null +++ b/Lang/Chipmunk-Basic/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/Chipmunk-Basic \ No newline at end of file diff --git a/Lang/Commodore-BASIC/Execute-Brain- b/Lang/Commodore-BASIC/Execute-Brain- new file mode 120000 index 0000000000..125f41dcc4 --- /dev/null +++ b/Lang/Commodore-BASIC/Execute-Brain- @@ -0,0 +1 @@ +../../Task/Execute-Brain-/Commodore-BASIC \ No newline at end of file diff --git a/Lang/Cowgol/Case-sensitivity-of-identifiers b/Lang/Cowgol/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..08822efb13 --- /dev/null +++ b/Lang/Cowgol/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Cowgol \ No newline at end of file diff --git a/Lang/Dart/Case-sensitivity-of-identifiers b/Lang/Dart/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..d90aafa8e4 --- /dev/null +++ b/Lang/Dart/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Dart \ No newline at end of file diff --git a/Lang/Dart/Pick-random-element b/Lang/Dart/Pick-random-element new file mode 120000 index 0000000000..1c6ed4225d --- /dev/null +++ b/Lang/Dart/Pick-random-element @@ -0,0 +1 @@ +../../Task/Pick-random-element/Dart \ No newline at end of file diff --git a/Lang/Dart/Yin-and-yang b/Lang/Dart/Yin-and-yang new file mode 120000 index 0000000000..2e5b73348b --- /dev/null +++ b/Lang/Dart/Yin-and-yang @@ -0,0 +1 @@ +../../Task/Yin-and-yang/Dart \ No newline at end of file diff --git a/Lang/Draco/Case-sensitivity-of-identifiers b/Lang/Draco/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..a2d3247bb9 --- /dev/null +++ b/Lang/Draco/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Draco \ No newline at end of file diff --git a/Lang/FreeBASIC/Sieve-of-Pritchard b/Lang/FreeBASIC/Sieve-of-Pritchard new file mode 120000 index 0000000000..07e6560a9f --- /dev/null +++ b/Lang/FreeBASIC/Sieve-of-Pritchard @@ -0,0 +1 @@ +../../Task/Sieve-of-Pritchard/FreeBASIC \ No newline at end of file diff --git a/Lang/FutureBasic/Abundant-deficient-and-perfect-number-classifications b/Lang/FutureBasic/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..6a668d664a --- /dev/null +++ b/Lang/FutureBasic/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Amicable-pairs b/Lang/FutureBasic/Amicable-pairs new file mode 120000 index 0000000000..1a74c35cac --- /dev/null +++ b/Lang/FutureBasic/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Ascending-primes b/Lang/FutureBasic/Ascending-primes new file mode 120000 index 0000000000..15062a8daf --- /dev/null +++ b/Lang/FutureBasic/Ascending-primes @@ -0,0 +1 @@ +../../Task/Ascending-primes/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Bell-numbers b/Lang/FutureBasic/Bell-numbers new file mode 120000 index 0000000000..546ef198a6 --- /dev/null +++ b/Lang/FutureBasic/Bell-numbers @@ -0,0 +1 @@ +../../Task/Bell-numbers/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Compare-a-list-of-strings b/Lang/FutureBasic/Compare-a-list-of-strings new file mode 120000 index 0000000000..317363661f --- /dev/null +++ b/Lang/FutureBasic/Compare-a-list-of-strings @@ -0,0 +1 @@ +../../Task/Compare-a-list-of-strings/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Create-a-two-dimensional-array-at-runtime b/Lang/FutureBasic/Create-a-two-dimensional-array-at-runtime new file mode 120000 index 0000000000..d06d9b79d2 --- /dev/null +++ b/Lang/FutureBasic/Create-a-two-dimensional-array-at-runtime @@ -0,0 +1 @@ +../../Task/Create-a-two-dimensional-array-at-runtime/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Descending-primes b/Lang/FutureBasic/Descending-primes new file mode 120000 index 0000000000..d04177f03a --- /dev/null +++ b/Lang/FutureBasic/Descending-primes @@ -0,0 +1 @@ +../../Task/Descending-primes/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Duffinian-numbers b/Lang/FutureBasic/Duffinian-numbers new file mode 120000 index 0000000000..b905e2f7a5 --- /dev/null +++ b/Lang/FutureBasic/Duffinian-numbers @@ -0,0 +1 @@ +../../Task/Duffinian-numbers/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Emirp-primes b/Lang/FutureBasic/Emirp-primes new file mode 120000 index 0000000000..f749b7bd72 --- /dev/null +++ b/Lang/FutureBasic/Emirp-primes @@ -0,0 +1 @@ +../../Task/Emirp-primes/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Extensible-prime-generator b/Lang/FutureBasic/Extensible-prime-generator new file mode 120000 index 0000000000..e56eea61b0 --- /dev/null +++ b/Lang/FutureBasic/Extensible-prime-generator @@ -0,0 +1 @@ +../../Task/Extensible-prime-generator/FutureBasic \ No newline at end of file diff --git a/Lang/FutureBasic/Write-entire-file b/Lang/FutureBasic/Write-entire-file new file mode 120000 index 0000000000..d476ed3e37 --- /dev/null +++ b/Lang/FutureBasic/Write-entire-file @@ -0,0 +1 @@ +../../Task/Write-entire-file/FutureBasic \ No newline at end of file diff --git a/Lang/GW-BASIC/Case-sensitivity-of-identifiers b/Lang/GW-BASIC/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..605ddebd53 --- /dev/null +++ b/Lang/GW-BASIC/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/GW-BASIC \ No newline at end of file diff --git a/Lang/GW-BASIC/Sort-disjoint-sublist b/Lang/GW-BASIC/Sort-disjoint-sublist new file mode 120000 index 0000000000..548b0397b6 --- /dev/null +++ b/Lang/GW-BASIC/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/GW-BASIC \ No newline at end of file diff --git a/Lang/Gambas/Abundant-deficient-and-perfect-number-classifications b/Lang/Gambas/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..783553e468 --- /dev/null +++ b/Lang/Gambas/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/Gambas \ No newline at end of file diff --git a/Lang/Gambas/Amicable-pairs b/Lang/Gambas/Amicable-pairs new file mode 120000 index 0000000000..bbeae57d95 --- /dev/null +++ b/Lang/Gambas/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/Gambas \ No newline at end of file diff --git a/Lang/Gambas/Wagstaff-primes b/Lang/Gambas/Wagstaff-primes new file mode 120000 index 0000000000..4a1effb1f9 --- /dev/null +++ b/Lang/Gambas/Wagstaff-primes @@ -0,0 +1 @@ +../../Task/Wagstaff-primes/Gambas \ No newline at end of file diff --git a/Lang/Insitux/00-LANG.txt b/Lang/Insitux/00-LANG.txt index d688ce93c7..4ebf558e15 100644 --- a/Lang/Insitux/00-LANG.txt +++ b/Lang/Insitux/00-LANG.txt @@ -1,3 +1,7 @@ -{{stub}}{{language|Insitux -|site=https://insitux.github.io}} +{{stub}} +{{language|Insitux +|site=https://insitux.github.io +|hopl=no +|tags=insitux}} + {{language programming paradigm|functional}} \ No newline at end of file diff --git a/Lang/Insitux/ABC-problem b/Lang/Insitux/ABC-problem new file mode 120000 index 0000000000..ce818aba57 --- /dev/null +++ b/Lang/Insitux/ABC-problem @@ -0,0 +1 @@ +../../Task/ABC-problem/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Amb b/Lang/Insitux/Amb new file mode 120000 index 0000000000..5547b80e95 --- /dev/null +++ b/Lang/Insitux/Amb @@ -0,0 +1 @@ +../../Task/Amb/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Attractive-numbers b/Lang/Insitux/Attractive-numbers new file mode 120000 index 0000000000..421abcd3ac --- /dev/null +++ b/Lang/Insitux/Attractive-numbers @@ -0,0 +1 @@ +../../Task/Attractive-numbers/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Comments b/Lang/Insitux/Comments new file mode 120000 index 0000000000..4d0aff25eb --- /dev/null +++ b/Lang/Insitux/Comments @@ -0,0 +1 @@ +../../Task/Comments/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Flatten-a-list b/Lang/Insitux/Flatten-a-list new file mode 120000 index 0000000000..69e68cf9c1 --- /dev/null +++ b/Lang/Insitux/Flatten-a-list @@ -0,0 +1 @@ +../../Task/Flatten-a-list/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Generate-lower-case-ASCII-alphabet b/Lang/Insitux/Generate-lower-case-ASCII-alphabet new file mode 120000 index 0000000000..2b2679b13e --- /dev/null +++ b/Lang/Insitux/Generate-lower-case-ASCII-alphabet @@ -0,0 +1 @@ +../../Task/Generate-lower-case-ASCII-alphabet/Insitux \ No newline at end of file diff --git a/Lang/Insitux/Letter-frequency b/Lang/Insitux/Letter-frequency new file mode 120000 index 0000000000..ccb2a1ad87 --- /dev/null +++ b/Lang/Insitux/Letter-frequency @@ -0,0 +1 @@ +../../Task/Letter-frequency/Insitux \ No newline at end of file diff --git a/Lang/Java/First-class-environments b/Lang/Java/First-class-environments new file mode 120000 index 0000000000..b5dc4adb0f --- /dev/null +++ b/Lang/Java/First-class-environments @@ -0,0 +1 @@ +../../Task/First-class-environments/Java \ No newline at end of file diff --git a/Lang/Java/First-class-functions-Use-numbers-analogously b/Lang/Java/First-class-functions-Use-numbers-analogously new file mode 120000 index 0000000000..e10875e4fb --- /dev/null +++ b/Lang/Java/First-class-functions-Use-numbers-analogously @@ -0,0 +1 @@ +../../Task/First-class-functions-Use-numbers-analogously/Java \ No newline at end of file diff --git a/Lang/Java/Fortunate-numbers b/Lang/Java/Fortunate-numbers new file mode 120000 index 0000000000..ae067e82d8 --- /dev/null +++ b/Lang/Java/Fortunate-numbers @@ -0,0 +1 @@ +../../Task/Fortunate-numbers/Java \ No newline at end of file diff --git a/Lang/Java/Goldbachs-comet b/Lang/Java/Goldbachs-comet new file mode 120000 index 0000000000..9b26f2f8ae --- /dev/null +++ b/Lang/Java/Goldbachs-comet @@ -0,0 +1 @@ +../../Task/Goldbachs-comet/Java \ No newline at end of file diff --git a/Lang/Java/Gotchas b/Lang/Java/Gotchas new file mode 120000 index 0000000000..be1af0f8fc --- /dev/null +++ b/Lang/Java/Gotchas @@ -0,0 +1 @@ +../../Task/Gotchas/Java \ No newline at end of file diff --git a/Lang/Java/HTTPS-Authenticated b/Lang/Java/HTTPS-Authenticated new file mode 120000 index 0000000000..4646789662 --- /dev/null +++ b/Lang/Java/HTTPS-Authenticated @@ -0,0 +1 @@ +../../Task/HTTPS-Authenticated/Java \ No newline at end of file diff --git a/Lang/Java/HTTPS-Client-authenticated b/Lang/Java/HTTPS-Client-authenticated new file mode 120000 index 0000000000..83204b27f1 --- /dev/null +++ b/Lang/Java/HTTPS-Client-authenticated @@ -0,0 +1 @@ +../../Task/HTTPS-Client-authenticated/Java \ No newline at end of file diff --git a/Lang/Java/Halt-and-catch-fire b/Lang/Java/Halt-and-catch-fire new file mode 120000 index 0000000000..6093944de6 --- /dev/null +++ b/Lang/Java/Halt-and-catch-fire @@ -0,0 +1 @@ +../../Task/Halt-and-catch-fire/Java \ No newline at end of file diff --git a/Lang/Java/Hex-words b/Lang/Java/Hex-words new file mode 120000 index 0000000000..59a4a917cd --- /dev/null +++ b/Lang/Java/Hex-words @@ -0,0 +1 @@ +../../Task/Hex-words/Java \ No newline at end of file diff --git a/Lang/Java/Home-primes b/Lang/Java/Home-primes new file mode 120000 index 0000000000..ede7e76d8d --- /dev/null +++ b/Lang/Java/Home-primes @@ -0,0 +1 @@ +../../Task/Home-primes/Java \ No newline at end of file diff --git a/Lang/Java/Jordan-P-lya-numbers b/Lang/Java/Jordan-P-lya-numbers new file mode 120000 index 0000000000..0384a4ab5c --- /dev/null +++ b/Lang/Java/Jordan-P-lya-numbers @@ -0,0 +1 @@ +../../Task/Jordan-P-lya-numbers/Java \ No newline at end of file diff --git a/Lang/Lua/Bifid-cipher b/Lang/Lua/Bifid-cipher new file mode 120000 index 0000000000..bbe70b6b3d --- /dev/null +++ b/Lang/Lua/Bifid-cipher @@ -0,0 +1 @@ +../../Task/Bifid-cipher/Lua \ No newline at end of file diff --git a/Lang/Lua/Euclid-Mullin-sequence b/Lang/Lua/Euclid-Mullin-sequence new file mode 120000 index 0000000000..d53e68d78b --- /dev/null +++ b/Lang/Lua/Euclid-Mullin-sequence @@ -0,0 +1 @@ +../../Task/Euclid-Mullin-sequence/Lua \ No newline at end of file diff --git a/Lang/Lua/Hex-words b/Lang/Lua/Hex-words new file mode 120000 index 0000000000..da350854b2 --- /dev/null +++ b/Lang/Lua/Hex-words @@ -0,0 +1 @@ +../../Task/Hex-words/Lua \ No newline at end of file diff --git a/Lang/Lua/Hofstadter-Q-sequence b/Lang/Lua/Hofstadter-Q-sequence new file mode 120000 index 0000000000..e7ce3958ea --- /dev/null +++ b/Lang/Lua/Hofstadter-Q-sequence @@ -0,0 +1 @@ +../../Task/Hofstadter-Q-sequence/Lua \ No newline at end of file diff --git a/Lang/Lua/Long-year b/Lang/Lua/Long-year new file mode 120000 index 0000000000..b7e7982781 --- /dev/null +++ b/Lang/Lua/Long-year @@ -0,0 +1 @@ +../../Task/Long-year/Lua \ No newline at end of file diff --git a/Lang/MACRO-11/Binary-search b/Lang/MACRO-11/Binary-search new file mode 120000 index 0000000000..f39a506cb9 --- /dev/null +++ b/Lang/MACRO-11/Binary-search @@ -0,0 +1 @@ +../../Task/Binary-search/MACRO-11 \ No newline at end of file diff --git a/Lang/MSX-Basic/Case-sensitivity-of-identifiers b/Lang/MSX-Basic/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..dbb971fabf --- /dev/null +++ b/Lang/MSX-Basic/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/MSX-Basic \ No newline at end of file diff --git a/Lang/MSX-Basic/Mandelbrot-set b/Lang/MSX-Basic/Mandelbrot-set new file mode 120000 index 0000000000..b87ec4375f --- /dev/null +++ b/Lang/MSX-Basic/Mandelbrot-set @@ -0,0 +1 @@ +../../Task/Mandelbrot-set/MSX-Basic \ No newline at end of file diff --git a/Lang/MiniScript/Amicable-pairs b/Lang/MiniScript/Amicable-pairs new file mode 120000 index 0000000000..1c34c212eb --- /dev/null +++ b/Lang/MiniScript/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/MiniScript \ No newline at end of file diff --git a/Lang/MiniScript/Euclid-Mullin-sequence b/Lang/MiniScript/Euclid-Mullin-sequence new file mode 120000 index 0000000000..2e46c6660a --- /dev/null +++ b/Lang/MiniScript/Euclid-Mullin-sequence @@ -0,0 +1 @@ +../../Task/Euclid-Mullin-sequence/MiniScript \ No newline at end of file diff --git a/Lang/Minimal-BASIC/Case-sensitivity-of-identifiers b/Lang/Minimal-BASIC/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..7873d4b976 --- /dev/null +++ b/Lang/Minimal-BASIC/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Minimal-BASIC \ No newline at end of file diff --git a/Lang/Minimal-BASIC/Sort-disjoint-sublist b/Lang/Minimal-BASIC/Sort-disjoint-sublist new file mode 120000 index 0000000000..94210be584 --- /dev/null +++ b/Lang/Minimal-BASIC/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/Minimal-BASIC \ No newline at end of file diff --git a/Lang/Modula-2/Binary-search b/Lang/Modula-2/Binary-search new file mode 120000 index 0000000000..be8e19aba4 --- /dev/null +++ b/Lang/Modula-2/Binary-search @@ -0,0 +1 @@ +../../Task/Binary-search/Modula-2 \ No newline at end of file diff --git a/Lang/Modula-2/Prime-decomposition b/Lang/Modula-2/Prime-decomposition new file mode 120000 index 0000000000..c4e4d4ce06 --- /dev/null +++ b/Lang/Modula-2/Prime-decomposition @@ -0,0 +1 @@ +../../Task/Prime-decomposition/Modula-2 \ No newline at end of file diff --git a/Lang/N-t-roff/Case-sensitivity-of-identifiers b/Lang/N-t-roff/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..81291d4c50 --- /dev/null +++ b/Lang/N-t-roff/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/N-t-roff \ No newline at end of file diff --git a/Lang/N-t-roff/Loops-Downward-for b/Lang/N-t-roff/Loops-Downward-for new file mode 120000 index 0000000000..2efb5862b1 --- /dev/null +++ b/Lang/N-t-roff/Loops-Downward-for @@ -0,0 +1 @@ +../../Task/Loops-Downward-for/N-t-roff \ No newline at end of file diff --git a/Lang/N-t-roff/Loops-For-with-a-specified-step b/Lang/N-t-roff/Loops-For-with-a-specified-step new file mode 120000 index 0000000000..705a9d8396 --- /dev/null +++ b/Lang/N-t-roff/Loops-For-with-a-specified-step @@ -0,0 +1 @@ +../../Task/Loops-For-with-a-specified-step/N-t-roff \ No newline at end of file diff --git a/Lang/N-t-roff/Multiplication-tables b/Lang/N-t-roff/Multiplication-tables new file mode 120000 index 0000000000..741133e643 --- /dev/null +++ b/Lang/N-t-roff/Multiplication-tables @@ -0,0 +1 @@ +../../Task/Multiplication-tables/N-t-roff \ No newline at end of file diff --git a/Lang/Perl/Radical-of-an-integer b/Lang/Perl/Radical-of-an-integer new file mode 120000 index 0000000000..41c493e8a5 --- /dev/null +++ b/Lang/Perl/Radical-of-an-integer @@ -0,0 +1 @@ +../../Task/Radical-of-an-integer/Perl \ No newline at end of file diff --git a/Lang/PicoLisp/Abelian-sandpile-model b/Lang/PicoLisp/Abelian-sandpile-model new file mode 120000 index 0000000000..bbc68b2024 --- /dev/null +++ b/Lang/PicoLisp/Abelian-sandpile-model @@ -0,0 +1 @@ +../../Task/Abelian-sandpile-model/PicoLisp \ No newline at end of file diff --git a/Lang/Plain-English/00-LANG.txt b/Lang/Plain-English/00-LANG.txt index 466f3ace11..b92c6008a7 100644 --- a/Lang/Plain-English/00-LANG.txt +++ b/Lang/Plain-English/00-LANG.txt @@ -22,8 +22,198 @@ Plain English can be run from within its Integrated Development Environment (IDE) (see "Complete IDE download" below) or compiled to a self-contained Microsoft Windows .exe file. +Here is a list of what you must understand from the start: + +'''Fully Implemented in Itself:''' It is a single executable, with one or more human readable libraries (also written in Plain English Programming Language) which produces a new stand alone .exe with your new program in it. +It is NOT a compiler only that takes in source and produces compiled code. +It is NOT an IDE only, that shells out to a compiler. +It is both. +There is NO complete source code in another language; the system was bootstrapped in a Pascal-like language (which is no longer available) and was later re-written entirely in Plain English. +It is "Machine Code" Low Level: The bootstrap is very basic, only able to copy itself and add raw machine code in Intel hex format, make calls to the operating system, e.g. + +Call "kernel32.dll" "SetFilePointer" with the file and 0 and 0 and 2 [file_end] returning a result number. + +and call other DLLs e.g. + +Call "hawk.dll" "Servo_SetServos" with 1 and the front knob's setting and the side knob's setting and 0 and 0 and 0 and 0 and 0 and 0 returning a number. + +and it can do a few other things. + +'''It is "English" High Level:''' From those humble beginnings, springs a language that can do things like: + + +To run: +Start up. +Clear the screen. +Use medium letters. Use the fat pen. +Pick a really dark color. +Loop. +Start in the center of the screen. +Turn left 1/32 of the way. +Turn right. Move 2 inches. Turn left. +Write "HELLO WORLD". +Refresh the screen. +Lighten the current color about 20 percent. +Add 1 to a count. If the count is 32, break. +Repeat. +Wait for the escape key. +Shut down. + + +Note that standard English punctuation, word types, and sentence structure are all used. +There is a trend to make each sentence is own paragraph, but that is not required. + +'''Compact:''' The entire download is less than a megabyte in size. +It's a complete development environment, including a unique interface, a simplified file manager, an elegant text editor, a handy hexadecimal dumper, a native-code-generating compiler/linker, a library of general-purpose types, variables and routines, and even a wysiwyg page layout facility (that we used to produce the documentation). +It is written entirely in Plain English. +The source code (about 25,000 sentences) is included in the download. +All the commands are in the alphabetic menus along the top of the IDE. E.g. to close a folder, after clicking on a drive letter and folder, click "C" and then "Close", or use the Alt- hot-keys like Alt-C. + +'''Types''' +Primitive types like number, etc.. are supported, as well as more complex types like "thing" which is a sort of object or list, and any number of user-defined types. Note however that "number" is a 32 bit integer and is /directly/ mapped to the CPU. E.g. addition is literally this in the language: + + +To add a number to another number: +Intel $8B85080000008B008B9D0C0000000103. + +And yes, that is 80x86 machine code in Intel hex format. It decompiles to + + +mov eax, [ebp+8] ; $8B8508000000 -> load the current stack address + 8 into the accumulator +mov eax, [eax] ; $8B00 -> load memory pointed to by accumulator into accumulator +mov ebx, [ebp+12] ; $8B9D0C000000-> load the current stack address + 12 into working register +add [ebx],eax ; $0103 -> add accumulator to memory pointed to by working register + + +So the language has stacked pointers (all parameters are passed by reference) to the two numbers via a number to another number and then it calls this code which gets the first number, and adds it to the second. Hopefully this example shows how high level and low level Plain English is at the same time. + +"The whole system is built on just two, compiler-defined types: BYTE and RECORD. All the other types are constructed from these, and are defined in the "Noodle" library {a file, loaded by the compiler}. The idea was to put as much as possible in the library, and as little as possible in the compiler. The compiler is aware of a few other types -- like NUMBER, STRING, SUBSTRING, THING -- mostly for memory management purposes, but all the other the type definitions are built up from BYTE and RECORD in the library." These are extended to support BYTE, WYRD, POINTER, FLAG, and RECORD. + +Subset types give new names to existing types: e.g. + +A count is a number. +A name is a string. + + +Constants or "literals" are also possible: + + +The copyright byte is a byte equal to 169. + + +As are conversion types: + + +A foot is 12 inches. +An hour is 60 minutes. + + +'''Variables''' +Once a type has been declared, we can allocate a global, outside a routine: + + +The great foo is a number. + + +then values may be assigned, inside a routine + + +Put 0 into the great foo + + +or be passed by address... + + +Increment the great foo. + + +as a parameter to a routine. + + +To increment a number: +Add 1 to the number. + + +Note that variables can have multi-word names including spaces. + +Local variables, with scope in their own routine only, are defined so simply they can be hard to see. Basically, you assign a value using an indefinite article (A, AN, ANOTHER, or SOME) in a statement. For example: +Put 101 into some other course number. +The local variable name there is "other course number" but "other course" also works as a "nickname". The variable's type is number. e.g. +Increment the other course. +will match To increment a number: + +"All parameters passed to Plain English routines are passed by reference, though parameters passed to DLLs use the C convention (the order is reversed and "simple" types are passed by value)." + +'''Routines''' +Routines are defined by headers which terminate in a colon, followed by the body of the routine. Multiple headers can be provided in front of one routine, separated by semicolons: + + +To add a number to a count; +To increment a number by a count: + + +The language parses these into Monikettes: (1) add (2) [number] (3) in/into/to (4) [count] which, taken together make up the routines Moniker: add [number] in/into/to [count] + +Matching procedure definitions to procedure calls is done in stages. + +1. Higher-level types are reduced to compatible lower-level types, as necessary; and +2. Certain less-essential words are considered equivalent. + +For example, the compiler will match this imperative sentence: Write the first name using the blue pen. with this routine header To write a string with a color: even though the source types "name" and "pen" are different (but compatible) with the target types "string" and "color", and even though the source preposition "using" is different than the target preposition "with". + +Unless, of course, a more exact match is available, such as: +To write a name from/given/with/using a pen: +To write a name from/given/with/using a color: +To write a string from/given/with/using a pen: + +Type reductions proceed, recursively, from left to right, until a match is found (or all combinations have failed, which results in a compile-time error). + +'''Decider:''' A type of routine which helps TO DECIDE IF something: by always returning SAY YES or SAY NO. The something will usually include ARE, BE, CAN, COULD, DO, DOES, IS, MAY, SHOULD, WAS, WILL, or WOULD. e.g. + + +To decide if a number is greater than another number: +If the first number is greater than the second number, say yes. +Say no. + + +'''Function:''' A routine that extracts, calculates, or otherwise derives a value from a passed parameter. Function headers take this form: + + +TO PUT something's something INTO a temporary variable: + + +Unlike procedures (which are called via imperative sentences) and deciders (which are implicitly called in the condition part of IF statements), functions are not usually called directly. Instead, the "something's something" is used as if it was a field in a record. Like a "box's center", which you won't find in the "box" record, because it is calculated by a function on demand. + +'''Statements''' +From the instruction manual (see link below): + +(1) I really only understand five kinds of sentences: +(a) type definitions, which always start with A, AN, or SOME; +(b) global variable definitions, which always start with THE; +(c) routine headers, which always start with TO, which can contain: +(d) conditional statements, which always start with IF; and +(e) imperative statements, which start with anything else. + +(2) I treat as a name anything after A, AN, ANOTHER, SOME, or THE, up to: + +(a) any simple verb, like IS, ARE, CAN, or DO, or +(b) any conjunction, like AND or OR, or +(c) any preposition, like OVER, UNDER, AROUND, or THRU, or +(d) any literal, like 123 or "Hello, World!", or +(e) any punctuation mark. + +(3) I consider almost all other words to be just words, except for: + +(a) infix operators: PLUS, MINUS, TIMES, DIVIDED BY and THEN; +(b) special definition words: CALLED and EQUAL; and +(c) reserved imperatives: LOOP, BREAK, EXIT, REPEAT, and SAY. + The noodle built into Plain English is simply not useful enough by itself, and therefore libraries were created to assist in writing Rosetta Code tasks in Plain English. +See also: +https://github.com/Folds/english A work in progress to normalize Plain English into a more standard compiler. For documentation on the language in general, see the instructions.pdf file in the documentation folder. The author objects (see the issues) +https://forums.parallax.com/discussion/163792/plain-english-programming a long rambling and unproductive (but educational, so productive in that sense) discussion of Plain English with it's author and proponents of a bare metal processor. + {| class="wikitable" ! No. !! Library name !! No. !! Library name |- diff --git a/Lang/QBasic/Amicable-pairs b/Lang/QBasic/Amicable-pairs new file mode 120000 index 0000000000..77165f1cab --- /dev/null +++ b/Lang/QBasic/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/QBasic \ No newline at end of file diff --git a/Lang/QBasic/Case-sensitivity-of-identifiers b/Lang/QBasic/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..03aa9234fc --- /dev/null +++ b/Lang/QBasic/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/QBasic \ No newline at end of file diff --git a/Lang/Quite-BASIC/Case-sensitivity-of-identifiers b/Lang/Quite-BASIC/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..92e87b90d5 --- /dev/null +++ b/Lang/Quite-BASIC/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/Quite-BASIC \ No newline at end of file diff --git a/Lang/RPL/00-LANG.txt b/Lang/RPL/00-LANG.txt index 9ab139edb3..f59bf80730 100644 --- a/Lang/RPL/00-LANG.txt +++ b/Lang/RPL/00-LANG.txt @@ -14,9 +14,9 @@ '''RPL''' (an acronym for '''Reverse Polish Lisp''') is the onboard calculator language for the HP-28 and [[wp:HP 48 series|HP 48]] lines of graphing calculators. It is a stack language (not a [[Lisp]]-like language, as its name implies), tightly integrated with the calculator system, with many instructions similar to Forth. -It can natively handle unsigned integers (named ''binary integers''), floating-point numbers (named ''real numbers''), complex numbers, vectors and matrices (named ''arrays''), lists and algebraic expressions. +It can natively handle unsigned integers (named ''binary integers''), floating-point numbers (named ''real numbers''), complex numbers, vectors and matrices (named ''arrays''), lists, character strings, and algebraic expressions. -There are actually two languages with the name RPL: '''User RPL''' and '''System RPL'''. System RPL is used in implementing the operating system, and User RPL is the language users use to write programs on the calculator. +There are actually two languages with the name RPL: '''User RPL''' and '''System RPL'''. System RPL is used in implementing the operating system, and User RPL is the language users use to write programs on the calculator. System RPL is highly hardware-dependent, whilst User RPL is upwardly compatible. The language [[RPL/2]] is a recreation of this language for POSIX machines. diff --git a/Lang/RPL/Middle-three-digits b/Lang/RPL/Middle-three-digits deleted file mode 120000 index f380427577..0000000000 --- a/Lang/RPL/Middle-three-digits +++ /dev/null @@ -1 +0,0 @@ -../../Task/Middle-three-digits/RPL \ No newline at end of file diff --git a/Lang/Ring/Euclid-Mullin-sequence b/Lang/Ring/Euclid-Mullin-sequence new file mode 120000 index 0000000000..293e012001 --- /dev/null +++ b/Lang/Ring/Euclid-Mullin-sequence @@ -0,0 +1 @@ +../../Task/Euclid-Mullin-sequence/Ring \ No newline at end of file diff --git a/Lang/Ruby/Euclid-Mullin-sequence b/Lang/Ruby/Euclid-Mullin-sequence new file mode 120000 index 0000000000..ca4347495c --- /dev/null +++ b/Lang/Ruby/Euclid-Mullin-sequence @@ -0,0 +1 @@ +../../Task/Euclid-Mullin-sequence/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Next-highest-int-from-digits b/Lang/Ruby/Next-highest-int-from-digits new file mode 120000 index 0000000000..2bfcb2d306 --- /dev/null +++ b/Lang/Ruby/Next-highest-int-from-digits @@ -0,0 +1 @@ +../../Task/Next-highest-int-from-digits/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Pell-numbers b/Lang/Ruby/Pell-numbers new file mode 120000 index 0000000000..2c393e793e --- /dev/null +++ b/Lang/Ruby/Pell-numbers @@ -0,0 +1 @@ +../../Task/Pell-numbers/Ruby \ No newline at end of file diff --git a/Lang/Ruby/Terminal-control-Cursor-movement b/Lang/Ruby/Terminal-control-Cursor-movement new file mode 120000 index 0000000000..aa0fa5243e --- /dev/null +++ b/Lang/Ruby/Terminal-control-Cursor-movement @@ -0,0 +1 @@ +../../Task/Terminal-control-Cursor-movement/Ruby \ No newline at end of file diff --git a/Lang/Run-BASIC/Abundant-deficient-and-perfect-number-classifications b/Lang/Run-BASIC/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..bd8d7b581d --- /dev/null +++ b/Lang/Run-BASIC/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/Run-BASIC \ No newline at end of file diff --git a/Lang/Rust/Home-primes b/Lang/Rust/Home-primes new file mode 120000 index 0000000000..1768c89c81 --- /dev/null +++ b/Lang/Rust/Home-primes @@ -0,0 +1 @@ +../../Task/Home-primes/Rust \ No newline at end of file diff --git a/Lang/TRS-80-BASIC/00-LANG.txt b/Lang/TRS-80-BASIC/00-LANG.txt new file mode 100644 index 0000000000..d63f7cfbc5 --- /dev/null +++ b/Lang/TRS-80-BASIC/00-LANG.txt @@ -0,0 +1,8 @@ +{{language|TRS-80 BASIC|exec=interpreted}} +{{implementation|BASIC}} + +'''TRS-80 BASIC''' is the collective term for the dialects of [[BASIC]] created for the [[wp:TRS-80|TRS-80]] series of computers. The original version that shipped in the Model I ROM, [[wp:Level I BASIC|Level I BASIC]], was an extension of [[Tiny BASIC]] developed internally at Tandy. Later versions – Level II BASIC, TRSDOS Disk BASIC, Level III BASIC, and ColorBASIC – were developed by Microsoft. + +==See Also== +* [http://www.trs-80.org Matthew Reeds' TRS-80.org] +* ''[[Tasks not implemented in TRS-80 BASIC|Tasks not implemented in TRS-80 BASIC]]'' \ No newline at end of file diff --git a/Lang/TRS-80-BASIC/00-META.yaml b/Lang/TRS-80-BASIC/00-META.yaml new file mode 100644 index 0000000000..fe50ad52e4 --- /dev/null +++ b/Lang/TRS-80-BASIC/00-META.yaml @@ -0,0 +1,2 @@ +--- +from: http://rosettacode.org/wiki/Category:TRS-80_BASIC diff --git a/Lang/TRS-80-BASIC/Execute-Brain- b/Lang/TRS-80-BASIC/Execute-Brain- new file mode 120000 index 0000000000..49a15d686f --- /dev/null +++ b/Lang/TRS-80-BASIC/Execute-Brain- @@ -0,0 +1 @@ +../../Task/Execute-Brain-/TRS-80-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Abundant-deficient-and-perfect-number-classifications b/Lang/True-BASIC/Abundant-deficient-and-perfect-number-classifications new file mode 120000 index 0000000000..c866a2c2df --- /dev/null +++ b/Lang/True-BASIC/Abundant-deficient-and-perfect-number-classifications @@ -0,0 +1 @@ +../../Task/Abundant-deficient-and-perfect-number-classifications/True-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Ackermann-function b/Lang/True-BASIC/Ackermann-function new file mode 120000 index 0000000000..ab23f9cd58 --- /dev/null +++ b/Lang/True-BASIC/Ackermann-function @@ -0,0 +1 @@ +../../Task/Ackermann-function/True-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Amicable-pairs b/Lang/True-BASIC/Amicable-pairs new file mode 120000 index 0000000000..5ac8d397ef --- /dev/null +++ b/Lang/True-BASIC/Amicable-pairs @@ -0,0 +1 @@ +../../Task/Amicable-pairs/True-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Look-and-say-sequence b/Lang/True-BASIC/Look-and-say-sequence new file mode 120000 index 0000000000..c8d257d6b9 --- /dev/null +++ b/Lang/True-BASIC/Look-and-say-sequence @@ -0,0 +1 @@ +../../Task/Look-and-say-sequence/True-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Mandelbrot-set b/Lang/True-BASIC/Mandelbrot-set new file mode 120000 index 0000000000..03d305bffa --- /dev/null +++ b/Lang/True-BASIC/Mandelbrot-set @@ -0,0 +1 @@ +../../Task/Mandelbrot-set/True-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Sieve-of-Pritchard b/Lang/True-BASIC/Sieve-of-Pritchard new file mode 120000 index 0000000000..57343d8e65 --- /dev/null +++ b/Lang/True-BASIC/Sieve-of-Pritchard @@ -0,0 +1 @@ +../../Task/Sieve-of-Pritchard/True-BASIC \ No newline at end of file diff --git a/Lang/True-BASIC/Sort-disjoint-sublist b/Lang/True-BASIC/Sort-disjoint-sublist new file mode 120000 index 0000000000..aa9918bae2 --- /dev/null +++ b/Lang/True-BASIC/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/True-BASIC \ No newline at end of file diff --git a/Lang/XBasic/Case-sensitivity-of-identifiers b/Lang/XBasic/Case-sensitivity-of-identifiers new file mode 120000 index 0000000000..d17d87991e --- /dev/null +++ b/Lang/XBasic/Case-sensitivity-of-identifiers @@ -0,0 +1 @@ +../../Task/Case-sensitivity-of-identifiers/XBasic \ No newline at end of file diff --git a/Lang/Yabasic/Middle-three-digits b/Lang/Yabasic/Middle-three-digits new file mode 120000 index 0000000000..083f219dc4 --- /dev/null +++ b/Lang/Yabasic/Middle-three-digits @@ -0,0 +1 @@ +../../Task/Middle-three-digits/Yabasic \ No newline at end of file diff --git a/Lang/Yabasic/Sieve-of-Pritchard b/Lang/Yabasic/Sieve-of-Pritchard new file mode 120000 index 0000000000..32653b1621 --- /dev/null +++ b/Lang/Yabasic/Sieve-of-Pritchard @@ -0,0 +1 @@ +../../Task/Sieve-of-Pritchard/Yabasic \ No newline at end of file diff --git a/Lang/Yabasic/Sort-disjoint-sublist b/Lang/Yabasic/Sort-disjoint-sublist new file mode 120000 index 0000000000..1df414fdd6 --- /dev/null +++ b/Lang/Yabasic/Sort-disjoint-sublist @@ -0,0 +1 @@ +../../Task/Sort-disjoint-sublist/Yabasic \ No newline at end of file diff --git a/Lang/Zig/Huffman-coding b/Lang/Zig/Huffman-coding new file mode 120000 index 0000000000..f46d9d32ac --- /dev/null +++ b/Lang/Zig/Huffman-coding @@ -0,0 +1 @@ +../../Task/Huffman-coding/Zig \ No newline at end of file diff --git a/Lang/Zig/Run-length-encoding b/Lang/Zig/Run-length-encoding new file mode 120000 index 0000000000..4dfb41f482 --- /dev/null +++ b/Lang/Zig/Run-length-encoding @@ -0,0 +1 @@ +../../Task/Run-length-encoding/Zig \ No newline at end of file diff --git a/Task/ABC-problem/Insitux/abc-problem.insitux b/Task/ABC-problem/Insitux/abc-problem.insitux new file mode 100644 index 0000000000..d0c393dfba --- /dev/null +++ b/Task/ABC-problem/Insitux/abc-problem.insitux @@ -0,0 +1,8 @@ +(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 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 diff --git a/Task/Abelian-sandpile-model/PicoLisp/abelian-sandpile-model.l b/Task/Abelian-sandpile-model/PicoLisp/abelian-sandpile-model.l new file mode 100644 index 0000000000..98704f385a --- /dev/null +++ b/Task/Abelian-sandpile-model/PicoLisp/abelian-sandpile-model.l @@ -0,0 +1,27 @@ +(load "@lib/simul.l") +(symbols 'simul 'pico) +(de sandpile (A B) + (let + (Grid (grid A A) + Size (/ (inc A) 2) + Center (get Grid Size Size) + Done T ) + (for G Grid + (for This G + (=: V 0) ) ) + (with Center + (=: V B) + (while Done + (off Done) + (for G Grid + (for This G + (when (>= (: V) 4) + (=: V (- (: V) 4)) + (on Done) + (mapc + '((Dir) + (with (Dir This) (=: V (inc (: V)))) ) + '(north south west east) ) ) ) ) ) ) + (disp Grid 0 + '((This) (if (: V) (pack " " @ " ") " ")) ) ) ) +(sandpile 10 64) diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/BASIC256/abundant-deficient-and-perfect-number-classifications.basic b/Task/Abundant-deficient-and-perfect-number-classifications/BASIC256/abundant-deficient-and-perfect-number-classifications.basic new file mode 100644 index 0000000000..7bc0793e77 --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/BASIC256/abundant-deficient-and-perfect-number-classifications.basic @@ -0,0 +1,31 @@ +deficient = 0 +perfect = 0 +abundant = 0 + +for n = 1 to 20000 + sum = SumProperDivisors(n) + begin case + case sum < n + deficient += 1 + case sum = n + perfect += 1 + else + abundant += 1 + end case +next + +print "The classification of the numbers from 1 to 20,000 is as follows :" +print +print "Deficient = "; deficient +print "Perfect = "; perfect +print "Abundant = "; abundant +end + +function SumProperDivisors(number) + if number < 2 then return 0 + sum = 0 + for i = 1 to number \ 2 + if number mod i = 0 then sum += i + next i + return sum +end function diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/Chipmunk-Basic/abundant-deficient-and-perfect-number-classifications.basic b/Task/Abundant-deficient-and-perfect-number-classifications/Chipmunk-Basic/abundant-deficient-and-perfect-number-classifications.basic new file mode 100644 index 0000000000..cfaf64fd2f --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/Chipmunk-Basic/abundant-deficient-and-perfect-number-classifications.basic @@ -0,0 +1,30 @@ +100 cls +110 defic = 0 +120 perfe = 0 +130 abund = 0 +140 for n = 1 to 20000 +150 sump = SumProperDivisors(n) +160 if sump < n then +170 defic = defic+1 +180 else +190 if sump = n then +200 perfe = perfe+1 +210 else +220 if sump > n then abund = abund+1 +230 endif +240 endif +250 next +260 print "The classification of the numbers from 1 to 20,000 is as follows :" +270 print +280 print "Deficient = ";defic +290 print "Perfect = ";perfe +300 print "Abundant = ";abund +310 end +320 function SumProperDivisors(number) +330 if number < 2 then SumProperDivisors = 0 +340 sum = 0 +350 for i = 1 to number/2 +360 if number mod i = 0 then sum = sum+i +370 next i +380 SumProperDivisors = sum +390 end function diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/FutureBasic/abundant-deficient-and-perfect-number-classifications.basic b/Task/Abundant-deficient-and-perfect-number-classifications/FutureBasic/abundant-deficient-and-perfect-number-classifications.basic new file mode 100644 index 0000000000..8ff06122e2 --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/FutureBasic/abundant-deficient-and-perfect-number-classifications.basic @@ -0,0 +1,30 @@ +local fn SumProperDivisors( number as long ) as long + long i, result, sum = 0 + + if number < 2 then exit fn = 0 + for i = 1 to number / 2 + if number mod i == 0 then sum += i + next + result = sum +end fn = result + +void local fn NumberCategories( limit as long ) + long i, sum, deficient = 0, perfect = 0, abundant = 0 + + for i = 1 to limit + sum = fn SumProperDivisors(i) + if sum < i then deficient++ : continue + if sum == i then perfect++ : continue + abundant++ + next + printf @"\nClassification of integers from 1 to %ld is:\n", limit + printf @"Deficient = %ld\nPerfect = %ld\nAbundant = %ld", deficient, perfect, abundant + printf @"-----------------\nTotal = %ld\n", deficient + perfect + abundant +end fn + +CFTimeInterval t +t = fn CACurrentMediaTime +fn NumberCategories( 20000 ) +printf @"Compute time: %.3f ms",(fn CACurrentMediaTime-t)*1000 + +HandleEvents diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/Gambas/abundant-deficient-and-perfect-number-classifications.gambas b/Task/Abundant-deficient-and-perfect-number-classifications/Gambas/abundant-deficient-and-perfect-number-classifications.gambas new file mode 100644 index 0000000000..583c60ce28 --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/Gambas/abundant-deficient-and-perfect-number-classifications.gambas @@ -0,0 +1,32 @@ +Public Sub Main() + + Dim sum As Integer, deficient As Integer, perfect As Integer, abundant As Integer + + For n As Integer = 1 To 20000 + sum = SumProperDivisors(n) + If sum < n Then + deficient += 1 + Else If sum = n Then + perfect += 1 + Else + abundant += 1 + Endif + Next + + Print "The classification of the numbers from 1 to 20,000 is as follows : \n" + Print "Deficient = "; deficient + Print "Perfect = "; perfect + Print "Abundant = "; abundant + +End + +Function SumProperDivisors(number As Integer) As Integer + + If number < 2 Then Return 0 + Dim sum As Integer = 0 + For i As Integer = 1 To number \ 2 + If number Mod i = 0 Then sum += i + Next + Return sum + +End Function diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/Run-BASIC/abundant-deficient-and-perfect-number-classifications.basic b/Task/Abundant-deficient-and-perfect-number-classifications/Run-BASIC/abundant-deficient-and-perfect-number-classifications.basic new file mode 100644 index 0000000000..e3d389113b --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/Run-BASIC/abundant-deficient-and-perfect-number-classifications.basic @@ -0,0 +1,36 @@ +function sumProperDivisors(num) + if num > 1 then + sum = 1 + root = sqr(num) + for i = 2 to root + if num mod i = 0 then + sum = sum + i + if (i*i) <> num then sum = sum + num / i + end if + next i + end if + sumProperDivisors = sum +end function + +deficient = 0 +perfect = 0 +abundant = 0 + +print "The classification of the numbers from 1 to 20,000 is as follows :" + +for n = 1 to 20000 + sump = sumProperDivisors(n) + if sump < n then + deficient = deficient +1 + else + if sump = n then + perfect = perfect +1 + else + if sump > n then abundant = abundant +1 + end if + end if +next n + +print "Deficient = "; deficient +print "Perfect = "; perfect +print "Abundant = "; abundant diff --git a/Task/Abundant-deficient-and-perfect-number-classifications/True-BASIC/abundant-deficient-and-perfect-number-classifications.basic b/Task/Abundant-deficient-and-perfect-number-classifications/True-BASIC/abundant-deficient-and-perfect-number-classifications.basic new file mode 100644 index 0000000000..adceccfdb7 --- /dev/null +++ b/Task/Abundant-deficient-and-perfect-number-classifications/True-BASIC/abundant-deficient-and-perfect-number-classifications.basic @@ -0,0 +1,32 @@ +LET lm = 20000 +DIM s(0) +MAT REDIM s(lm) + +FOR i = 1 TO lm + LET s(i) = -32767 +NEXT i +FOR i = 1 TO lm/2 + FOR j = i+i TO lm STEP i + LET s(j) = s(j) +i + NEXT j +NEXT i + +FOR i = 1 TO lm + LET x = i - 32767 + IF s(i) < x THEN + LET d = d +1 + ELSE + IF s(i) = x THEN + LET p = p +1 + ELSE + LET a = a +1 + END IF + END IF +NEXT i + +PRINT "The classification of the numbers from 1 to 20,000 is as follows :" +PRINT +PRINT "Deficient ="; d +PRINT "Perfect ="; p +PRINT "Abundant ="; a +END diff --git a/Task/Ackermann-function/Chipmunk-Basic/ackermann-function.basic b/Task/Ackermann-function/Chipmunk-Basic/ackermann-function.basic new file mode 100644 index 0000000000..66115a245d --- /dev/null +++ b/Task/Ackermann-function/Chipmunk-Basic/ackermann-function.basic @@ -0,0 +1,14 @@ +100 for m = 0 to 4 +110 print using "###";m; +120 for n = 0 to 6 +130 if m = 4 and n = 1 then goto 160 +140 print using "######";ack(m,n); +150 next n +160 print +170 next m +180 end +190 sub ack(m,n) +200 if m = 0 then ack = n+1 +210 if m > 0 and n = 0 then ack = ack(m-1,1) +220 if m > 0 and n > 0 then ack = ack(m-1,ack(m,n-1)) +230 end sub diff --git a/Task/Ackermann-function/True-BASIC/ackermann-function.basic b/Task/Ackermann-function/True-BASIC/ackermann-function.basic new file mode 100644 index 0000000000..90d23fa95d --- /dev/null +++ b/Task/Ackermann-function/True-BASIC/ackermann-function.basic @@ -0,0 +1,18 @@ +FUNCTION ack(m, n) + IF m = 0 THEN LET ack = n+1 + IF m > 0 AND n = 0 THEN LET ack = ack(m-1, 1) + IF m > 0 AND n > 0 THEN LET ack = ack(m-1, ack(m, n-1)) +END FUNCTION + +FOR m = 0 TO 4 + PRINT USING "###": m; + FOR n = 0 TO 8 + ! A(4, 1) OR higher will RUN OUT of stack memory (default 1M) + ! change n = 1 TO n = 2 TO calculate A(4, 2), increase stack! + IF m = 4 AND n = 1 THEN EXIT FOR + PRINT USING "######": ack(m, n); + NEXT n + PRINT +NEXT m + +END diff --git a/Task/Add-a-variable-to-a-class-instance-at-runtime/Elena/add-a-variable-to-a-class-instance-at-runtime.elena b/Task/Add-a-variable-to-a-class-instance-at-runtime/Elena/add-a-variable-to-a-class-instance-at-runtime.elena index ebd5235ea9..9634046d11 100644 --- a/Task/Add-a-variable-to-a-class-instance-at-runtime/Elena/add-a-variable-to-a-class-instance-at-runtime.elena +++ b/Task/Add-a-variable-to-a-class-instance-at-runtime/Elena/add-a-variable-to-a-class-instance-at-runtime.elena @@ -2,24 +2,24 @@ import extensions; class Extender : BaseExtender { - prop object foo; + object foo : prop; - constructor(object) - { - theObject := object - } + constructor(object) + { + this object := object + } } public program() { - var object := 234; + var object := 234; - // extending an object with a field - object := new Extender(object); + // extending an object with a field + object := new Extender(object); - object.foo := "bar"; + object.foo := "bar"; - console.printLine(object,".foo=",object.foo); + console.printLine(object,".foo=",object.foo); - console.readChar() + console.readChar() } diff --git a/Task/Amb/Elena/amb.elena b/Task/Amb/Elena/amb.elena index 6f4acf4436..ba034b044f 100644 --- a/Task/Amb/Elena/amb.elena +++ b/Task/Amb/Elena/amb.elena @@ -2,6 +2,8 @@ import system'routines; import extensions; import extensions'routines; +// --- Joinable -- + joinable(former,later) = (former[former.Length - 1] == later[0]); dispatcher = new @@ -27,25 +29,27 @@ dispatcher = new } }; +// --- AmbValueCollection --- + class AmbValueCollection { - object theCombinator; + object _combinator; constructor new(params object[] args) { - theCombinator := SequentialEnumerator.new(params args) + _combinator := SequentialEnumerator.new(params args) } seek(cond) { - theCombinator.reset(); + _combinator.reset(); - theCombinator.seekEach:(v => dispatcher.eval(v,cond)) + _combinator.seekEach:(v => dispatcher.eval(v,cond)) } do(f) { - var result := theCombinator.get(); + var result := *_combinator; if (nil != result) { dispatcher.eval(result,f) @@ -57,12 +61,16 @@ class AmbValueCollection } } +// --- ambOperator --- + singleton ambOperator { for(params object[] args) = AmbValueCollection.new(params args); } +// --- Program --- + public program() { try diff --git a/Task/Amb/Insitux/amb.insitux b/Task/Amb/Insitux/amb.insitux new file mode 100644 index 0000000000..4924e8859d --- /dev/null +++ b/Task/Amb/Insitux/amb.insitux @@ -0,0 +1,10 @@ +(function amb op res + (filter #(= res (.. .. op args)) + (.. for vec (skip 2 args)))) + +(var safe= @(= (0 args))) +(var predicate (comp vec (map (juxt 0 -1)) flatten (skip 1) (partition 2) (map (.. safe=)) (.. and))) + +(amb predicate true ["the" "that" "a"] ["frog" "elephant" "thing"] ["walked" "treaded" "grows"] ["slowly" "quickly"]) + +;returns [["that" "thing" "grows" "slowly"]] diff --git a/Task/Amicable-pairs/ALGOL-60/amicable-pairs.alg b/Task/Amicable-pairs/ALGOL-60/amicable-pairs.alg index d8e838f4b2..406fdf00ef 100644 --- a/Task/Amicable-pairs/ALGOL-60/amicable-pairs.alg +++ b/Task/Amicable-pairs/ALGOL-60/amicable-pairs.alg @@ -2,7 +2,7 @@ begin comment - return n mod m; integer procedure mod(n, m); - value n, q; integer n, m; + value n, m; integer n, m; begin mod := n - m * entier(n / m); end; diff --git a/Task/Amicable-pairs/ALGOL-68/amicable-pairs.alg b/Task/Amicable-pairs/ALGOL-68/amicable-pairs.alg index ea22fb7653..5272734526 100644 --- a/Task/Amicable-pairs/ALGOL-68/amicable-pairs.alg +++ b/Task/Amicable-pairs/ALGOL-68/amicable-pairs.alg @@ -7,11 +7,12 @@ BEGIN # find amicable pairs p1, p2 where each is equal to the other's proper div OD OD; # find the amicable pairs up to 20 000 # - FOR p1 TO UPB pd sum DO - FOR p2 FROM p1 + 1 TO UPB pd sum DO - IF pd sum[ p1 ] = p2 AND pd sum[ p2 ] = p1 THEN - print( ( whole( p1, -6 ), " and ", whole( p2, -6 ), " are an amicable pair", newline ) ) + FOR p1 TO UPB pd sum - 1 DO + INT pd sum p1 = pd sum[ p1 ]; + IF pd sum p1 > p1 AND pd sum p1 <= UPB pd sum THEN + IF pd sum[ pd sum p1 ] = p1 THEN + print( ( whole( p1, -6 ), " and ", whole( pd sum p1, -6 ), " are an amicable pair", newline ) ) FI - OD + FI OD END diff --git a/Task/Amicable-pairs/ALGOL-W/amicable-pairs.alg b/Task/Amicable-pairs/ALGOL-W/amicable-pairs.alg new file mode 100644 index 0000000000..9ee2f5d274 --- /dev/null +++ b/Task/Amicable-pairs/ALGOL-W/amicable-pairs.alg @@ -0,0 +1,23 @@ +begin % find amicable pairs p1, p2 where each is equal to the other's % + % proper divisor sum % + + integer MAX_NUMBER; + MAX_NUMBER := 20000; + + begin + integer array pdSum( 1 :: MAX_NUMBER ); % table of proper divisors % + for i := 1 until MAX_NUMBER do pdSum( i ) := 1; + for i := 2 until MAX_NUMBER do begin + for j := i + i step i until MAX_NUMBER do pdSum( j ) := pdSum( j ) + i + end for_i ; + + % find the amicable pairs up to 20 000 % + for p1 := 1 until MAX_NUMBER - 1 do begin + integer pdSumP1; + pdSumP1 := pdSum( p1 ); + if pdSumP1 > p1 and pdSumP1 <= MAX_NUMBER and pdSum( pdSumP1 ) = p1 then begin + write( i_w := 5, s_w := 0, p1, " and ", pdSumP1, " are an amicable pair" ) + end if_pdSumP1_gt_p1_and_le_MAX_NUMBER + end for_p1 + end +end. diff --git a/Task/Amicable-pairs/Chipmunk-Basic/amicable-pairs.basic b/Task/Amicable-pairs/Chipmunk-Basic/amicable-pairs.basic new file mode 100644 index 0000000000..d70be3c2bb --- /dev/null +++ b/Task/Amicable-pairs/Chipmunk-Basic/amicable-pairs.basic @@ -0,0 +1,20 @@ +100 cls : rem 10 HOME for Applesoft BASIC +110 print "The pairs of amicable numbers below 20,000 are :" +120 print +130 size = 18500 +140 for n = 1 to size +150 m = amicable(n) +160 if m > n and amicable(m) = n then +170 print using "#####";n; +180 print " and "; +190 print using "#####";m +200 endif +210 next +220 end +230 function amicable(nr) +240 suma = 1 +250 for d = 2 to sqr(nr) +260 if nr mod d = 0 then suma = suma+d+nr/d +270 next +280 amicable = suma +290 end function diff --git a/Task/Amicable-pairs/FutureBasic/amicable-pairs.basic b/Task/Amicable-pairs/FutureBasic/amicable-pairs.basic new file mode 100644 index 0000000000..fedcfddf2d --- /dev/null +++ b/Task/Amicable-pairs/FutureBasic/amicable-pairs.basic @@ -0,0 +1,29 @@ +local fn Sigma( n as long ) as long + long i, root, sum = 1 + + if n == 1 then exit fn = 0 + root = sqr(n) + for i = 2 to root + if ( n mod i == 0 ) then sum += i + n/i + next + if root * root == n then sum -= root +end fn = sum + +void local fn CalculateAmicablePairs( limit as long ) + long i, m + + printf @"\nAmicable pairs through %ld are:\n", limit + for i = 2 to limit + m = fn Sigma(i) + if ( m > i ) + if ( fn Sigma(m) == i ) then printf @"%6ld and %ld", i, m + end if + next +end fn + +CFTimeInterval t +t = fn CACurrentMediaTime +fn CalculateAmicablePairs( 20000 ) +printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*1000 + +HandleEvents diff --git a/Task/Amicable-pairs/Gambas/amicable-pairs.gambas b/Task/Amicable-pairs/Gambas/amicable-pairs.gambas new file mode 100644 index 0000000000..9a6c13c28d --- /dev/null +++ b/Task/Amicable-pairs/Gambas/amicable-pairs.gambas @@ -0,0 +1,33 @@ +Public sum[19999] As Integer + +Public Sub Main() + + Dim n As Integer, f As Integer + + For n = 0 To 19998 + sum[n] = SumProperDivisors(n) + Next + + Print "The pairs of amicable numbers below 20,000 are :\n" + + For n = 0 To 19998 + ' f = SumProperDivisors(n) + f = sum[n] + If f <= n Or f < 1 Or f > 19999 Then Continue + If f = sum[n] And n = sum[f] Then + Print Format$(Str$(n), "#####"); " And "; Format$(Str$(sum[n]), "#####") + End If + Next + +End + +Function SumProperDivisors(number As Integer) As Integer + + If number < 2 Then Return 0 + Dim sum As Integer = 0 + For i As Integer = 1 To number \ 2 + If number Mod i = 0 Then sum += i + Next + Return sum + +End Function diff --git a/Task/Amicable-pairs/Lua/amicable-pairs.lua b/Task/Amicable-pairs/Lua/amicable-pairs-1.lua similarity index 100% rename from Task/Amicable-pairs/Lua/amicable-pairs.lua rename to Task/Amicable-pairs/Lua/amicable-pairs-1.lua diff --git a/Task/Amicable-pairs/Lua/amicable-pairs-2.lua b/Task/Amicable-pairs/Lua/amicable-pairs-2.lua new file mode 100644 index 0000000000..6bdb20f739 --- /dev/null +++ b/Task/Amicable-pairs/Lua/amicable-pairs-2.lua @@ -0,0 +1,15 @@ +MAX_NUMBER = 20000 +sumDivs = {} -- table of proper divisors +for i = 1, MAX_NUMBER do sumDivs[ i ] = 1 end +for i = 2, MAX_NUMBER do + for j = i + i, MAX_NUMBER, i do + sumDivs[ j ] = sumDivs[ j ] + i + end +end + +for n = 2, MAX_NUMBER do + m = sumDivs[n] + if m > n then + if sumDivs[m] == n then print(n, m) end + end +end diff --git a/Task/Amicable-pairs/MiniScript/amicable-pairs.mini b/Task/Amicable-pairs/MiniScript/amicable-pairs.mini new file mode 100644 index 0000000000..a749aced55 --- /dev/null +++ b/Task/Amicable-pairs/MiniScript/amicable-pairs.mini @@ -0,0 +1,17 @@ +// find amicable pairs p1, p2 where each is equal to the other's proper divisor sum + +MAX_NUMBER = 20000 +pdSum = [1] * ( MAX_NUMBER + 1 ) // table of proper divisors +for i in range( 2, MAX_NUMBER ) + for j in range( i + i, MAX_NUMBER, i ) + pdSum[ j ] += i + end for +end for +// find the amicable pairs up to 20 000 +ap = [] +for p1 in range( 1, MAX_NUMBER - 1 ) + pdSumP1 = pdSum[ p1 ] + if pdSumP1 > p1 and pdSumP1 <= MAX_NUMBER and pdSum[ pdSumP1 ] == p1 then + print str( p1 ) + " and " + str( pdSumP1 ) + " are an amicable pair" + end if +end for diff --git a/Task/Amicable-pairs/PL-I-80/amicable-pairs.pli b/Task/Amicable-pairs/PL-I-80/amicable-pairs-1.pli similarity index 100% rename from Task/Amicable-pairs/PL-I-80/amicable-pairs.pli rename to Task/Amicable-pairs/PL-I-80/amicable-pairs-1.pli diff --git a/Task/Amicable-pairs/PL-I-80/amicable-pairs-2.pli b/Task/Amicable-pairs/PL-I-80/amicable-pairs-2.pli new file mode 100644 index 0000000000..c8263a3816 --- /dev/null +++ b/Task/Amicable-pairs/PL-I-80/amicable-pairs-2.pli @@ -0,0 +1,34 @@ +amicable: procedure options (main); + + %replace + search_limit by 20000; + + dcl sumf( 1 : search_limit ) fixed bin; + dcl (a, b, found) fixed bin; + + put skip list ('Searching for amicable pairs up to '); + put edit (search_limit) (f(5)); + + do a = 1 to search_limit; sumf( a ) = 1; end; + do a = 2 to search_limit; + do b = a + a to search_limit by a; + sumf( b ) = sumf( b ) + a; + end; + end; + + found = 0; + do a = 2 to search_limit; + b = sumf(a); + if (b > a) then + do; + if (sumf(b) = a) then + do; + found = found + 1; + put skip edit (a,b) (f(7)); + end; + end; + end; + put skip list (found, ' pairs were found'); + stop; + +end amicable; diff --git a/Task/Amicable-pairs/PL-M/amicable-pairs.plm b/Task/Amicable-pairs/PL-M/amicable-pairs.plm index 8176ff9bce..a28c71637b 100644 --- a/Task/Amicable-pairs/PL-M/amicable-pairs.plm +++ b/Task/Amicable-pairs/PL-M/amicable-pairs.plm @@ -30,8 +30,9 @@ END; /* TEST EACH PAIR */ DO I=2 TO 20$000; - DO J=I+1 TO 20$000; - IF DIV$SUM(I)=J AND DIV$SUM(J)=I THEN DO; + J = DIVSUM(I); + IF J > I AND J <= 20$000 THEN DO; + IF DIV$SUM(J) = I THEN DO; CALL PRINT$NUMBER(I); CALL PRINT(.', $'); CALL PRINT$NUMBER(J); diff --git a/Task/Amicable-pairs/QBasic/amicable-pairs.basic b/Task/Amicable-pairs/QBasic/amicable-pairs.basic new file mode 100644 index 0000000000..461ddf459e --- /dev/null +++ b/Task/Amicable-pairs/QBasic/amicable-pairs.basic @@ -0,0 +1,19 @@ +FUNCTION amicable (nr) + suma = 1 + FOR d = 2 TO SQR(nr) + IF nr MOD d = 0 THEN suma = suma + d + nr / d + NEXT + amicable = suma +END FUNCTION + +PRINT "The pairs of amicable numbers below 20,000 are :" +PRINT + +size = 18500 +FOR n = 1 TO size + m = amicable(n) + IF m > n AND amicable(m) = n THEN + PRINT USING "##### and #####"; n; m + END IF +NEXT +END diff --git a/Task/Amicable-pairs/True-BASIC/amicable-pairs.basic b/Task/Amicable-pairs/True-BASIC/amicable-pairs.basic new file mode 100644 index 0000000000..48e8b18ffe --- /dev/null +++ b/Task/Amicable-pairs/True-BASIC/amicable-pairs.basic @@ -0,0 +1,19 @@ +FUNCTION amicable(nr) + LET suma = 1 + FOR d = 2 TO SQR(nr) + IF REMAINDER(nr, d) = 0 THEN + LET suma = suma + d + nr / d + END IF + NEXT d + LET amicable = suma +END FUNCTION + +PRINT "The pairs of amicable numbers below 20,000 are :" +PRINT + +LET size = 18500 +FOR n = 1 TO size + LET m = amicable(n) + IF m > n AND amicable(m) = n THEN PRINT USING "##### and #####": n, m +NEXT n +END diff --git a/Task/Arithmetic-Rational/C++/arithmetic-rational.cpp b/Task/Arithmetic-Rational/C++/arithmetic-rational-1.cpp similarity index 100% rename from Task/Arithmetic-Rational/C++/arithmetic-rational.cpp rename to Task/Arithmetic-Rational/C++/arithmetic-rational-1.cpp diff --git a/Task/Arithmetic-Rational/C++/arithmetic-rational-2.cpp b/Task/Arithmetic-Rational/C++/arithmetic-rational-2.cpp new file mode 100644 index 0000000000..012ffb0a4f --- /dev/null +++ b/Task/Arithmetic-Rational/C++/arithmetic-rational-2.cpp @@ -0,0 +1,129 @@ +#include +#include +#include +#include +#include + +class Rational { +public: + /// Constructors /// + Rational() : numer(0), denom(1) {} + + Rational(const int64_t number) : numer(number), denom(1) {} + + Rational(const int64_t& numerator, const int64_t& denominator) : numer(numerator), denom(denominator) { + if ( numer == 0 ) { + denom = 1; + } else if ( denom == 0 ) { + throw std::invalid_argument("Denominator cannot be zero: " + denom); + } else if ( denom < 0 ) { + numer = -numer; + denom = -denom; + } + + int64_t divisor = std::gcd(numerator, denom); + numer = numer / divisor; + denom = denom / divisor; + } + + Rational(const Rational& other) : numer(other.numer), denom(other.denom) {} + + /// Operators /// + Rational& operator=(const Rational& other) { + if ( *this != other ) { numer = other.numer; denom = other.denom; } + return *this; + } + + bool operator!=(const Rational& other) const { return ! ( *this == other ); } + + bool operator==(const Rational& other) const { + if ( numer == other.numer && denom == other.denom ) { return true; } + return false; + } + + Rational& operator+=(const Rational& other) { + *this = Rational(numer* other.denom + other.numer * denom, denom * other.denom); + return *this; + } + + Rational operator+(const Rational& other) const { return Rational(*this) += other; } + + Rational& operator-=(const Rational& other) { + Rational temp(other); + temp.numer = -temp.numer; + return *this += temp; + } + Rational operator-(const Rational& other) const { return Rational(*this) -= other; } + + Rational& operator*=(const Rational& other) { + *this = Rational(numer * other.numer, denom * other.denom); + return *this; + } + + Rational operator*(const Rational& other) const { return Rational(*this) *= other; }; + + Rational& operator/=(const Rational other) { + Rational temp(other.denom, other.numer); + *this *= temp; + return *this; + } + + Rational operator/(const Rational& other) const { return Rational(*this) /= other; }; + + bool operator<(const Rational& other) const { return numer * other.denom < denom * other.numer; } + + bool operator<=(const Rational& other) const { return ! ( other < *this ); } + + bool operator>(const Rational& other) const { return other < *this; } + + bool operator>=(const Rational& other) const { return ! ( *this < other ); } + + Rational operator-() const { return Rational(-numer, denom); } + + Rational& operator++() { numer += denom; return *this; } + + Rational operator++(int) { Rational temp = *this; ++*this; return temp; } + + Rational& operator--() { numer -= denom; return *this; } + + Rational operator--(int) { Rational temp = *this; --*this; return temp; } + + friend std::ostream& operator<<(std::ostream& outStream, const Rational& other) { + outStream << other.numer << "/" << other.denom; + return outStream; + } + + /// Methods /// + Rational reciprocal() const { return Rational(denom, numer); } + + Rational positive() const { return Rational(abs(numer), denom); } + + int64_t to_integer() const { return numer / denom; } + + double to_double() const { return (double) numer / denom; } + + int64_t hash() const { return std::hash{}(numer) ^ std::hash{}(denom); } + +private: + int64_t numer; + int64_t denom; +}; + +int main() { + std::cout << "Perfect numbers less than 2^19:" << std::endl; + const int32_t limit = 1 << 19; + for ( int32_t candidate = 2; candidate < limit; ++candidate ) { + Rational sum = Rational(1, candidate); + int32_t square_root = (int32_t) sqrt(candidate); + for ( int32_t factor = 2; factor <= square_root; ++factor ) { + if ( candidate % factor == 0 ) { + sum += Rational(1, factor); + sum += Rational(1, candidate / factor); + } + } + + if ( sum == Rational(1) ) { + std::cout << candidate << std::endl; + } + } +} diff --git a/Task/Ascending-primes/FutureBasic/ascending-primes.basic b/Task/Ascending-primes/FutureBasic/ascending-primes.basic new file mode 100644 index 0000000000..3563debb55 --- /dev/null +++ b/Task/Ascending-primes/FutureBasic/ascending-primes.basic @@ -0,0 +1,47 @@ +local fn IsPrime( n as NSUInteger ) as BOOL + BOOL isPrime = YES + NSUInteger i + + if n < 2 then exit fn = NO + if n = 2 then exit fn = YES + if n mod 2 == 0 then exit fn = NO + for i = 3 to int(n^.5) step 2 + if n mod i == 0 then exit fn = NO + next +end fn = isPrime + +void local fn AscendingPrimes( limit as long ) + long i, n, mask, num, count = 0 + + for i = 0 to limit -1 + n = 0 : mask = i : num = 1 + while ( mask ) + if mask & 1 then n = n * 10 + num + mask = mask >> 1 + num++ + wend + mda(i) = n + next + + mda_sort @"compare:" + + for i = 1 to mda_count (0) - 1 + n = mda_integer(i) + if ( fn IsPrime( n ) ) + printf @"%10ld\b", n + count++ + if count mod 10 == 0 then print + end if + next + printf @"\n\tThere are %ld ascending primes.", count +end fn + +window 1, @"Ascending Primes", ( 0, 0, 780, 230 ) +print + +CFTimeInterval t +t = fn CACurrentMediaTime +fn AscendingPrimes( 512 ) +printf @"\n\tCompute time: %.3f ms\n",(fn CACurrentMediaTime-t)*1000 + +HandleEvents diff --git a/Task/Attractive-numbers/Insitux/attractive-numbers.insitux b/Task/Attractive-numbers/Insitux/attractive-numbers.insitux new file mode 100644 index 0000000000..21ef93d5fb --- /dev/null +++ b/Task/Attractive-numbers/Insitux/attractive-numbers.insitux @@ -0,0 +1,16 @@ +(function primes n + (let find-range (range 2 (inc n)) + check-nums (range 2 (-> n ceil sqrt inc)) + skip-each-after #(skip-each % (skip %1 %2)) + muls (xmap #(drop 0 (skip-each-after (dec %1) % find-range)) check-nums)) + (remove (flatten muls) find-range)) +(function distinct-factor n + (filter @(div? n) (primes n))) +(function factor n + (map (fn t (find (div? n) (map @(** t) (range (round (sqrt n)) 0)))) (distinct-factor n))) +(function decomposed-factors n + (map (fn dist t (repeat dist (/ (logn t) (logn dist)))) (distinct-factor n) (factor n))) +(var prime? @((primes %))) + +(var attract-num? (comp decomposed-factors flatten len prime?)) +(filter attract-num? (range 121)) diff --git a/Task/Bell-numbers/FutureBasic/bell-numbers.basic b/Task/Bell-numbers/FutureBasic/bell-numbers.basic new file mode 100644 index 0000000000..73073c6be5 --- /dev/null +++ b/Task/Bell-numbers/FutureBasic/bell-numbers.basic @@ -0,0 +1,18 @@ +local fn BellNumbers( limit as long ) + long j, n = 1 + + mda(0) = 1 + printf @"%2llu. %19llu", n, mda_integer(0) + while ( n < limit ) + mda(n) = mda(0) + for j = n to 1 step -1 + mda(j - 1) = mda_integer(j - 1) + mda_integer(j) + next + n++ + printf @"%2llu. %19llu", n, mda_integer(0) + wend +end fn + +fn BellNumbers( 25 ) + +HandleEvents diff --git a/Task/Best-shuffle/AArch64-Assembly/best-shuffle.aarch64 b/Task/Best-shuffle/AArch64-Assembly/best-shuffle.aarch64 new file mode 100644 index 0000000000..fd3ec95d83 --- /dev/null +++ b/Task/Best-shuffle/AArch64-Assembly/best-shuffle.aarch64 @@ -0,0 +1,195 @@ +/* ARM assembly AARCH64 Raspberry PI 3B */ +/* program shuffleperf64.s */ +/************************************/ +/* Constantes */ +/************************************/ +/* for this file see task include a file in language AArch64 assembly*/ +.include "../includeConstantesARM64.inc" + +/************************************/ +/* Initialized data */ +/************************************/ +.data +szMessString: .asciz "String :\n" +szString1: .asciz "abracadabra" +.equ LGSTRING1, . - szString1 - 1 +szString2: .asciz "seesaw" +.equ LGSTRING2, . - szString2 - 1 +szString3: .asciz "elk" +.equ LGSTRING3, . - szString3 - 1 +szString4: .asciz "grrrrrr" +.equ LGSTRING4, . - szString4 - 1 +szString5: .asciz "up" +.equ LGSTRING5, . - szString5 - 1 +szString6: .asciz "a" +.equ LGSTRING6, . - szString6 - 1 +szCarriageReturn: .asciz "\n" +szMessStart: .asciz "Program 64 bits start.\n" +.align 4 +qGraine: .quad 123456789 +/************************************/ +/* UnInitialized data */ +/************************************/ +.bss +sZoneConv: .skip 24 +sBuffer: .skip 80 +/************************************/ +/* code section */ +/************************************/ +.text +.global main +main: + ldr x0,qAdrszMessStart + bl affichageMess + ldr x0,qAdrszString1 // string address + mov x1,#LGSTRING1 // string length + ldr x2,qAdrsBuffer // result address + bl testshuffle // call test + ldr x0,qAdrszString2 + mov x1,#LGSTRING2 + ldr x2,qAdrsBuffer + bl testshuffle + ldr x0,qAdrszString3 + mov x1,#LGSTRING3 + ldr x2,qAdrsBuffer + bl testshuffle + ldr x0,qAdrszString4 + mov x1,#LGSTRING4 + ldr x2,qAdrsBuffer + bl testshuffle + ldr x0,qAdrszString5 + mov x1,#LGSTRING5 + ldr x2,qAdrsBuffer + bl testshuffle + ldr x0,qAdrszString6 + mov x1,#LGSTRING6 + ldr x2,qAdrsBuffer + bl testshuffle +100: // standard end of the program + mov x0, #0 // return code + mov x8, #EXIT // request to exit program + svc 0 // perform system call +qAdrszMessString: .quad szMessString +qAdrsBuffer: .quad sBuffer +qAdrszString1: .quad szString1 +qAdrszString2: .quad szString2 +qAdrszString3: .quad szString3 +qAdrszString4: .quad szString4 +qAdrszString5: .quad szString5 +qAdrszString6: .quad szString6 +qAdrszCarriageReturn: .quad szCarriageReturn +qAdrszMessStart: .quad szMessStart +/******************************************************************/ +/* test shuffle strings */ +/******************************************************************/ +/* x0 contains the address of the string */ +/* x1 contains string length */ +/* x2 contains result area */ +testshuffle: + stp x1,lr,[sp,-16]! // register save + stp x2,x3,[sp,-16]! + stp x4,x5,[sp,-16]! + stp x6,x7,[sp,-16]! + mov x3,x0 // display string + bl affichageMess + ldr x0,qAdrszCarriageReturn + bl affichageMess + mov x0,x3 + bl shufflestrings + mov x0,x2 // display result string + bl affichageMess + ldr x0,qAdrszCarriageReturn + bl affichageMess + mov x4,#0 // string index + mov x0,#0 // score + 1: // compute score loop + ldrb w6,[x3,x4] + ldrb w5,[x2,x4] + cmp x6,x5 + add x6,x0,1 + csel x0,x6,x0,eq // equal -> increment score + add x4,x4,#1 + cmp x4,x1 + blt 1b + ldr x1,qAdrsZoneConv + bl conversion10 // conversion score in decimal + ldr x0,qAdrsZoneConv + bl affichageMess + ldr x0,qAdrszCarriageReturn + bl affichageMess + ldr x0,qAdrszCarriageReturn + bl affichageMess +100: + ldp x6,x7,[sp],16 + ldp x4,x5,[sp],16 + ldp x2,x3,[sp],16 + ldp x1,lr,[sp],16 + ret +qAdrsZoneConv: .quad sZoneConv +/******************************************************************/ +/* shuffle strings algorithme Fisher-Yates */ +/******************************************************************/ +/* x0 contains the address of the string */ +/* x1 contains string length */ +/* x2 contains address result string */ +shufflestrings: + stp x1,lr,[sp,-16]! // TODO: save à completer + stp x2,x3,[sp,-16]! + stp x4,x5,[sp,-16]! + mov x3,#0 +1: // loop copy string in result + ldrb w4,[x0,x3] + strb w4,[x2,x3] + add x3,x3,#1 + cmp x3,x1 + ble 1b + sub x1,x1,#1 // last element +2: + mov x0,x1 + bl genereraleas // call random + ldrb w4,[x2,x1] // load byte string index loop + ldrb w3,[x2,x0] // load byte string random index + strb w3,[x2,x1] // and exchange + strb w4,[x2,x0] + subs x1,x1,#1 + cmp x1,#1 + bge 2b + +100: + ldp x4,x5,[sp],16 + ldp x2,x3,[sp],16 + ldp x1,lr,[sp],16 + ret + +/***************************************************/ +/* Generation random number */ +/***************************************************/ +/* x0 contains limit */ +genereraleas: + stp x1,lr,[sp,-16]! // save registers + stp x2,x3,[sp,-16]! // save registers + ldr x1,qAdrqGraine + ldr x2,[x1] + ldr x3,qNbDep1 + mul x2,x3,x2 + ldr x3,qNbDep2 + add x2,x2,x3 + str x2,[x1] // maj de la graine pour l appel suivant + cmp x0,#0 + beq 100f + udiv x3,x2,x0 + msub x0,x3,x0,x2 // résult = remainder + +100: // end function + ldp x2,x3,[sp],16 // restaur 2 registers + ldp x1,lr,[sp],16 // restaur 2 registers + ret // return to address lr x30 +qAdrqGraine: .quad qGraine +qNbDep1: .quad 0x0019660d +qNbDep2: .quad 0x3c6ef35f + +/***************************************************/ +/* ROUTINES INCLUDE */ +/***************************************************/ +/* for this file see task include a file in language AArch64 assembly*/ +.include "../includeARM64.inc" diff --git a/Task/Best-shuffle/ARM-Assembly/best-shuffle.arm b/Task/Best-shuffle/ARM-Assembly/best-shuffle.arm new file mode 100644 index 0000000000..7df228ed68 --- /dev/null +++ b/Task/Best-shuffle/ARM-Assembly/best-shuffle.arm @@ -0,0 +1,176 @@ +/* ARM assembly Raspberry PI */ +/* program shuffleperf.s */ +/************************************/ +/* Constantes */ +/************************************/ +/* for this file see task include a file in language ARM assembly*/ +.include "../constantes.inc" + +/************************************/ +/* Initialized data */ +/************************************/ +.data +szMessString: .asciz "String :\n" +szString1: .asciz "abracadabra" +.equ LGSTRING1, . - szString1 - 1 +szString2: .asciz "seesaw" +.equ LGSTRING2, . - szString2 - 1 +szString3: .asciz "elk" +.equ LGSTRING3, . - szString3 - 1 +szString4: .asciz "grrrrrr" +.equ LGSTRING4, . - szString4 - 1 +szString5: .asciz "up" +.equ LGSTRING5, . - szString5 - 1 +szString6: .asciz "a" +.equ LGSTRING6, . - szString6 - 1 +szCarriageReturn: .asciz "\n" +.align 4 +iGraine: .int 1234567 +/************************************/ +/* UnInitialized data */ +/************************************/ +.bss +sZoneConv: .skip 24 +sBuffer: .skip 80 +/************************************/ +/* code section */ +/************************************/ +.text +.global main +main: + ldr r0,iAdrszString1 @ string address + mov r1,#LGSTRING1 @ string length + ldr r2,iAdrsBuffer @ result address + bl testshuffle @ call test + ldr r0,iAdrszString2 + mov r1,#LGSTRING2 + ldr r2,iAdrsBuffer + bl testshuffle + ldr r0,iAdrszString3 + mov r1,#LGSTRING3 + ldr r2,iAdrsBuffer + bl testshuffle + ldr r0,iAdrszString4 + mov r1,#LGSTRING4 + ldr r2,iAdrsBuffer + bl testshuffle + ldr r0,iAdrszString5 + mov r1,#LGSTRING5 + ldr r2,iAdrsBuffer + bl testshuffle + ldr r0,iAdrszString6 + mov r1,#LGSTRING6 + ldr r2,iAdrsBuffer + bl testshuffle +100: @ standard end of the program + mov r0, #0 @ return code + mov r7, #EXIT @ request to exit program + svc 0 @ perform system call +iAdrszMessString: .int szMessString +iAdrsBuffer: .int sBuffer +iAdrszString1: .int szString1 +iAdrszString2: .int szString2 +iAdrszString3: .int szString3 +iAdrszString4: .int szString4 +iAdrszString5: .int szString5 +iAdrszString6: .int szString6 +iAdrszCarriageReturn: .int szCarriageReturn +/******************************************************************/ +/* test shuffle strings */ +/******************************************************************/ +/* r0 contains the address of the string */ +/* r1 contains string length */ +/* r2 contains result area */ +testshuffle: + push {r1-r6,lr} @ save registers + mov r3,r0 @ display string + bl affichageMess + ldr r0,iAdrszCarriageReturn + bl affichageMess + mov r0,r3 + bl shufflestrings + mov r0,r2 @ display result string + bl affichageMess + ldr r0,iAdrszCarriageReturn + bl affichageMess + mov r4,#0 @ string index + mov r0,#0 @ score + 1: @ compute score loop + ldrb r6,[r3,r4] + ldrb r5,[r2,r4] + cmp r6,r5 + addeq r0,r0,#1 @ equal -> increment score + add r4,r4,#1 + cmp r4,r1 + blt 1b + ldr r1,iAdrsZoneConv + bl conversion10 @ conversion score in decimal + ldr r0,iAdrsZoneConv + bl affichageMess + ldr r0,iAdrszCarriageReturn + bl affichageMess + ldr r0,iAdrszCarriageReturn + bl affichageMess +100: + pop {r1-r6,pc} @ restaur registers +iAdrsZoneConv: .int sZoneConv +/******************************************************************/ +/* shuffle strings algorithme Fisher-Yates */ +/******************************************************************/ +/* r0 contains the address of the string */ +/* r1 contains string length */ +/* r2 contains address result string */ +shufflestrings: + push {r1-r4,lr} @ save registers + mov r3,#0 +1: @ loop copy string in result + ldrb r4,[r0,r3] + strb r4,[r2,r3] + add r3,r3,#1 + cmp r3,r1 + ble 1b + sub r1,r1,#1 @ last element +2: + mov r0,r1 @ limit random number + bl genereraleas @ call random + ldrb r4,[r2,r1] @ load byte string index loop + ldrb r3,[r2,r0] @ load byte string random index + strb r3,[r2,r1] @ and exchange + strb r4,[r2,r0] + subs r1,r1,#1 + cmp r1,#1 + bge 2b + +100: + pop {r1-r4,pc} @ restaur registers + +/***************************************************/ +/* Generation random number */ +/***************************************************/ +/* r0 contains limit */ +genereraleas: + push {r1-r4,lr} @ save registers + ldr r4,iAdriGraine + ldr r2,[r4] + ldr r3,iNbDep1 + mul r2,r3,r2 + ldr r3,iNbDep1 + add r2,r2,r3 + str r2,[r4] @ maj de la graine pour l appel suivant + cmp r0,#0 + beq 100f + mov r1,r0 @ divisor + mov r0,r2 @ dividende + bl division + mov r0,r3 @ résult = remainder + +100: @ end function + pop {r1-r4,pc} @ restaur registers +iAdriGraine: .int iGraine +iNbDep1: .int 0x343FD +iNbDep2: .int 0x269EC3 +/***************************************************/ +/* ROUTINES INCLUDE */ +/***************************************************/ +/* for this file see task include a file in language ARM assembly*/ +.include "../affichage.inc" diff --git a/Task/Bifid-cipher/Applesoft-BASIC/bifid-cipher.basic b/Task/Bifid-cipher/Applesoft-BASIC/bifid-cipher.basic new file mode 100644 index 0000000000..7aaa8bcb3f --- /dev/null +++ b/Task/Bifid-cipher/Applesoft-BASIC/bifid-cipher.basic @@ -0,0 +1,45 @@ + 100 A$ = "ATTACKATDAWN": GOSUB 160"REPORT + 110 K$ = "BGWKZQPNDSIOAXEFCLUMTHYVR" + 120 A$ = "FLEEATONCE": GOSUB 160"REPORT + 130 K$ = " .'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123" + 140 A$ = "THE INVASION WILL START ON THE FIRST OF JANUARY 2023.": GOSUB 160"REPORT + 150 END + + REM REPORT + 160 GOSUB 200"ENCRYPT + 165 PRINT M$M$"FOR "W" X "W" POLYBIUS:":M$ = CHR$ (13): FOR I = 1 TO W: PRINT , MID$ (K$,(I - 1) * W + 1,W): NEXT + 170 PRINT "ENCRYPTED: "E$ + 180 GOSUB 300"DECRYPT + 190 PRINT "DECRYPTED: "U$;: RETURN + + REM ENCRYPT A$ RETURNS E$ + 200 GOSUB 400:L = LEN (A$):E$ = "":U$ = "": IF NOT L THEN RETURN + 210 FOR I = 1 TO L + 220 C = ASC ( MID$ (A$,I,1)): IF X(C) AND Y(C) THEN U$ = U$ + CHR$ (C) + 230 NEXT I + 240 L = LEN (U$): IF NOT L THEN RETURN + 250 FOR I = 1 TO L:C = ASC ( MID$ (U$,I,1)):A(I) = X(C):A(I + L) = Y(C): NEXT I + 260 FOR I = 1 TO L * 2 STEP 2:E$ = E$ + MID$ (K$,(A(I) - 1) * W + A(I + 1),1): NEXT I + 270 RETURN + + REM DECRYPT E$ RETURNS U$ + 300 GOSUB 400:L = LEN (E$):U$ = "": IF NOT L THEN RETURN + 310 FOR I = 1 TO L:C = ASC ( MID$ (E$,I)):B(I * 2 - 1) = X(C):B(I * 2) = Y(C): NEXT I + 320 FOR I = 1 TO L:U$ = U$ + MID$ (K$,(B(I) - 1) * W + B(L + I),1): NEXT I + 330 RETURN + + REM POLYBIUS K$ RETURNS X(255),Y(255) + 400 IF K$ = P$ AND LEN (K$) THEN RETURN + 410 IF XY THEN FOR I = 0 TO 255:X(I) = 0:Y(I) = 0: NEXT I + 420 IF NOT XY THEN DIM X(255),Y(255),A(512),B(512):XY = 1 + 430 IF K$ = "" THEN FOR I = 1 TO 25:K$ = K$ + CHR$ (I + 64 + (I > 9)): NEXT I + 440 L = LEN (K$):W = INT ( SQR (L - 1) + 1):I = 1:N = 1:K = ASC ("0") + 450 FOR X = 1 TO W + 460 FOR Y = 1 TO W + 470 C$ = MID$ (K$,I,1): IF C$ = "" THEN FOR C = K TO 255: IF X(C) THEN NEXT C: STOP + 480 IF C$ = "" THEN C$ = CHR$ (C):K$ = K$ + C$:K = C + 1 + 490 C = ASC (C$):Y(C) = Y:X(C) = X:I = I + 1: IF C$ = "J" THEN N = 0 + 500 NEXT Y,X + 510 IF N THEN Y( ASC ("J")) = Y( ASC ("I")):X( ASC ("J")) = X( ASC ("I")) + 520 P$ = K$ + 530 RETURN diff --git a/Task/Bifid-cipher/Lua/bifid-cipher.lua b/Task/Bifid-cipher/Lua/bifid-cipher.lua new file mode 100644 index 0000000000..56a5daed9c --- /dev/null +++ b/Task/Bifid-cipher/Lua/bifid-cipher.lua @@ -0,0 +1,73 @@ +function transcipher (cipher, message, decipher) + local message = message:gsub("%s+", ""):upper() + local xStr, yStr, s, char = "", "", "" + for pos = 1, #message do + char = message:sub(pos, pos) + for x = 1, #cipher do + for y = 1, #cipher[x] do + if cipher[x][y] == char then + s = s .. x .. y + xStr = xStr .. x + yStr = yStr .. y + end + end + end + end + if decipher then + xStr, yStr = s:sub(1, #s/2), s:sub(#s/2 + 1, #s) + else + s = xStr .. yStr + end + local result, x, y = "" + local limit = decipher and #s/2 or #s + local step = decipher and 1 or 2 + for pos = 1, limit, step do + x = tonumber(s:sub(pos, pos)) + y = decipher and + tonumber(s:sub(pos + #s/2, pos + #s/2)) or + tonumber(s:sub(pos + 1, pos + 1)) + result = result .. cipher[x][y] + end + return result +end + +local RCbifid = { + {"A", "B", "C", "D", "E"}, + {"F", "G", "H", "I", "K"}, + {"L", "M", "N", "O", "P"}, + {"Q", "R", "S", "T", "U"}, + {"V", "W", "X", "Y", "Z"} +} + +local wikibifid = { + {"B", "G", "W", "K", "Z"}, + {"Q", "P", "N", "D", "S"}, + {"I", "O", "A", "X", "E"}, + {"F", "C", "L", "U", "M"}, + {"T", "H", "Y", "V", "R"} +} + +local mybifid = { + {"A", "B", "C", "D", "E", "F"}, + {"G", "H", "I", "J", "K", "L"}, + {"M", "N", "O", "P", "Q", "R"}, + {"S", "T", "U", "V", "W", "X"}, + {"Y", "Z", "1", "2", "3", "4"}, + {"5", "6", "7", "8", "9", "0"} +} + +local testCases = { + {RCbifid, "ATTACKATDAWN"}, + {wikibifid, "FLEEATONCE"}, + {wikibifid, "ATTACKATDAWN",}, + {mybifid, "The invasion will start on the first of January"} +} + +local msg +for task, case in pairs(testCases) do + print("\nTask " .. task) + msg = transcipher(case[1], case[2]) + print("Encoded message: " .. msg) + msg = transcipher(case[1], msg, true) + print("Decoded message: " .. msg) +end diff --git a/Task/Binary-search/MACRO-11/binary-search.macro11 b/Task/Binary-search/MACRO-11/binary-search.macro11 new file mode 100644 index 0000000000..60e85c8762 --- /dev/null +++ b/Task/Binary-search/MACRO-11/binary-search.macro11 @@ -0,0 +1,46 @@ + .TITLE BINRTA + .MCALL .TTYOUT,.PRINT,.EXIT + ; TEST CODE +BINRTA::CLR R5 +1$: MOV R5,R0 + ADD #'0,R0 + .TTYOUT + MOV R5,R0 + MOV #DATA,R1 + MOV #DATEND,R2 + JSR PC,BINSRC + BEQ 2$ + .PRINT #4$ + BR 3$ +2$: .PRINT #5$ +3$: INC R5 + CMP R5,#^D10 + BLT 1$ + .EXIT +4$: .ASCII / NOT/ +5$: .ASCIZ / FOUND/ + .EVEN + + ; TEST DATA +DATA: .WORD 1, 2, 3, 5, 7 +DATEND = . + 2 + + ; BINARY SEARCH + ; INPUT: R0 = VALUE, R1 = LOW PTR, R2 = HIGH PTR + ; OUTPUT: ZF SET IF VALUE FOUND; R1 = INSERTION POINT +BINSRC: BR 3$ +1$: MOV R1,R3 + ADD R2,R3 + ROR R3 + CMP (R3),R0 + BGE 2$ + ADD #2,R3 + MOV R3,R1 + BR 3$ +2$: SUB #2,R3 + MOV R3,R2 +3$: CMP R2,R1 + BGE 1$ + CMP (R1),R0 + RTS PC + .END BINRTA diff --git a/Task/Binary-search/Modula-2/binary-search.mod2 b/Task/Binary-search/Modula-2/binary-search.mod2 new file mode 100644 index 0000000000..b2723e360f --- /dev/null +++ b/Task/Binary-search/Modula-2/binary-search.mod2 @@ -0,0 +1,70 @@ +MODULE BinarySearch; + +FROM STextIO IMPORT + WriteLn, WriteString; +FROM SWholeIO IMPORT + WriteInt; + +TYPE + TArray = ARRAY [0 .. 9] OF INTEGER; + +CONST + A = TArray{-31, 0, 1, 2, 2, 4, 65, 83, 99, 782}; (* Sorted data *) + +VAR + X: INTEGER; + +PROCEDURE DoBinarySearch(A: ARRAY OF INTEGER; X: INTEGER): INTEGER; +VAR + L, H, M: INTEGER; +BEGIN + L := 0; H := HIGH(A); + WHILE L <= H DO + M := L + (H - L) / 2; + IF A[M] < X THEN + L := M + 1 + ELSIF A[M] > X THEN + H := M - 1 + ELSE + RETURN M + END + END; + RETURN -1 +END DoBinarySearch; + +PROCEDURE DoBinarySearchRec(A: ARRAY OF INTEGER; X, L, H: INTEGER): INTEGER; +VAR + M: INTEGER; +BEGIN + IF H < L THEN + RETURN -1 + END; + M := L + (H - L) / 2; + IF A[M] > X THEN + RETURN DoBinarySearchRec(A, X, L, M - 1) + ELSIF A[M] < X THEN + RETURN DoBinarySearchRec(A, X, M + 1, H) + ELSE + RETURN M + END +END DoBinarySearchRec; + +PROCEDURE WriteResult(X, IndX: INTEGER); +BEGIN + WriteInt(X, 1); + IF IndX >= 0 THEN + WriteString(" is at index "); + WriteInt(IndX, 1); + WriteString(".") + ELSE + WriteString(" is not found.") + END; + WriteLn +END WriteResult; + +BEGIN + X := 2; + WriteResult(X, DoBinarySearch(A, X)); + X := 5; + WriteResult(X, DoBinarySearchRec(A, X, 0, HIGH(A))); +END BinarySearch. diff --git a/Task/Case-sensitivity-of-identifiers/Applesoft-BASIC/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/Applesoft-BASIC/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..f91b185404 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Applesoft-BASIC/case-sensitivity-of-identifiers.basic @@ -0,0 +1 @@ +dog$ = "Benjamin":Dog$ = "Samba":DOG$ = "Bernie":III = 254 * (DOG$ = dog$ AND Dog$ = DOG$) + 1: PRINT MID$ ("There is just one dog",256 - III) MID$ ("The three dogs are",III)" named " MID$ (dog$ + ", " + Dog$ + " and ",III)DOG$"." diff --git a/Task/Case-sensitivity-of-identifiers/Chipmunk-Basic/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/Chipmunk-Basic/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..33a43f9953 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Chipmunk-Basic/case-sensitivity-of-identifiers.basic @@ -0,0 +1,5 @@ +10 dog$ = "Benjamin" +20 dog$ = "Smokey" +30 dog$ = "Samba" +40 dog$ = "Bernie" +50 print "There is just one dog, named ";dog$ diff --git a/Task/Case-sensitivity-of-identifiers/Cowgol/case-sensitivity-of-identifiers.cowgol b/Task/Case-sensitivity-of-identifiers/Cowgol/case-sensitivity-of-identifiers.cowgol new file mode 100644 index 0000000000..c2af2406d1 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Cowgol/case-sensitivity-of-identifiers.cowgol @@ -0,0 +1,13 @@ +include "cowgol.coh"; + +var dog := "Benjamin"; +var Dog := "Samba"; +var DOG := "Bernie"; + +print("There are three dogs named "); +print(dog); +print(", "); +print(Dog); +print(", and "); +print(DOG); +print(".\n"); diff --git a/Task/Case-sensitivity-of-identifiers/Dart/case-sensitivity-of-identifiers.dart b/Task/Case-sensitivity-of-identifiers/Dart/case-sensitivity-of-identifiers.dart new file mode 100644 index 0000000000..86cc1b7f16 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Dart/case-sensitivity-of-identifiers.dart @@ -0,0 +1,5 @@ +void main() { + String dog = "Benjamin", doG = "Smokey", Dog = "Samba", DOG = "Bernie"; + + print("The four dogs are named $dog, $doG, $Dog and $DOG"); +} diff --git a/Task/Case-sensitivity-of-identifiers/Draco/case-sensitivity-of-identifiers.draco b/Task/Case-sensitivity-of-identifiers/Draco/case-sensitivity-of-identifiers.draco new file mode 100644 index 0000000000..c91a462895 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Draco/case-sensitivity-of-identifiers.draco @@ -0,0 +1,8 @@ +proc main() void: + *char dog = "Benjamin", + Dog = "Samba", + DOG = "Bernie"; + + writeln("There are three dogs named ", + dog, ", ", Dog, ", and ", DOG, ".") +corp diff --git a/Task/Case-sensitivity-of-identifiers/GW-BASIC/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/GW-BASIC/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..33a43f9953 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/GW-BASIC/case-sensitivity-of-identifiers.basic @@ -0,0 +1,5 @@ +10 dog$ = "Benjamin" +20 dog$ = "Smokey" +30 dog$ = "Samba" +40 dog$ = "Bernie" +50 print "There is just one dog, named ";dog$ diff --git a/Task/Case-sensitivity-of-identifiers/MSX-Basic/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/MSX-Basic/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..33a43f9953 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/MSX-Basic/case-sensitivity-of-identifiers.basic @@ -0,0 +1,5 @@ +10 dog$ = "Benjamin" +20 dog$ = "Smokey" +30 dog$ = "Samba" +40 dog$ = "Bernie" +50 print "There is just one dog, named ";dog$ diff --git a/Task/Case-sensitivity-of-identifiers/Minimal-BASIC/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/Minimal-BASIC/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..6a764ba550 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Minimal-BASIC/case-sensitivity-of-identifiers.basic @@ -0,0 +1,4 @@ +10 let d$ = "Benjamin" +20 let D$ = "Samba" +30 print "There is just one dog, named "; d$ +40 end diff --git a/Task/Case-sensitivity-of-identifiers/N-t-roff/case-sensitivity-of-identifiers.ntroff b/Task/Case-sensitivity-of-identifiers/N-t-roff/case-sensitivity-of-identifiers.ntroff new file mode 100644 index 0000000000..3e984ae8e8 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/N-t-roff/case-sensitivity-of-identifiers.ntroff @@ -0,0 +1,4 @@ +.ds dog Benjamin +.ds Dog Samba +.ds DOG Bernie +The three dogs are named \*[dog], \*[Dog] and \*[DOG]. diff --git a/Task/Case-sensitivity-of-identifiers/BASIC/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/QBasic/case-sensitivity-of-identifiers.basic similarity index 100% rename from Task/Case-sensitivity-of-identifiers/BASIC/case-sensitivity-of-identifiers.basic rename to Task/Case-sensitivity-of-identifiers/QBasic/case-sensitivity-of-identifiers.basic diff --git a/Task/Case-sensitivity-of-identifiers/Quite-BASIC/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/Quite-BASIC/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..6a764ba550 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/Quite-BASIC/case-sensitivity-of-identifiers.basic @@ -0,0 +1,4 @@ +10 let d$ = "Benjamin" +20 let D$ = "Samba" +30 print "There is just one dog, named "; d$ +40 end diff --git a/Task/Case-sensitivity-of-identifiers/XBasic/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/XBasic/case-sensitivity-of-identifiers.basic new file mode 100644 index 0000000000..4ee1be6618 --- /dev/null +++ b/Task/Case-sensitivity-of-identifiers/XBasic/case-sensitivity-of-identifiers.basic @@ -0,0 +1,14 @@ +PROGRAM "Case-sensitivity" +VERSION "0.0000" + +DECLARE FUNCTION Entry () + +FUNCTION Entry () + dog$ = "Benjamin" + dog$ = "Smokey" + dog$ = "Samba" + dog$ = "Bernie" + + PRINT "There is just one dog, named "; dog$ +END FUNCTION +END PROGRAM diff --git a/Task/Case-sensitivity-of-identifiers/Yabasic/case-sensitivity-of-identifiers.basic b/Task/Case-sensitivity-of-identifiers/Yabasic/case-sensitivity-of-identifiers.basic index 2e3c195cdf..4cbeda196b 100644 --- a/Task/Case-sensitivity-of-identifiers/Yabasic/case-sensitivity-of-identifiers.basic +++ b/Task/Case-sensitivity-of-identifiers/Yabasic/case-sensitivity-of-identifiers.basic @@ -1,5 +1,6 @@ dog$ = "Benjamin" +doG$ = "Smokey" Dog$ = "Samba" DOG$ = "Bernie" -print "The three dogs are named ", dog$, ", ", Dog$, " and ", DOG$ +print "The four dogs are named ", dog$, ", ", doG$, ", ", Dog$, " and ", DOG$ end diff --git a/Task/Chaocipher/00-TASK.txt b/Task/Chaocipher/00-TASK.txt index 73b60b4213..8c2723b21f 100644 --- a/Task/Chaocipher/00-TASK.txt +++ b/Task/Chaocipher/00-TASK.txt @@ -5,5 +5,5 @@ The algorithm is described in [http://www.mountainvistasoft.com/chaocipher/Actua ;Task: -Code the algorithm in your language and to test that it works with the plaintext 'WELLDONEISBETTERTHANWELLSAID' used in the paper itself. +Code the algorithm in your language and test that it works with the plaintext 'WELLDONEISBETTERTHANWELLSAID' used in the paper itself.

diff --git a/Task/Command-line-arguments/C3/command-line-arguments.c3 b/Task/Command-line-arguments/C3/command-line-arguments.c3 new file mode 100644 index 0000000000..13a39760aa --- /dev/null +++ b/Task/Command-line-arguments/C3/command-line-arguments.c3 @@ -0,0 +1,10 @@ +import std::io; + +fn void main(String[] args) +{ + io::printfn("This program is named %s.", args[0]); + for (int i = 1; i < args.len; i++) + { + io::printfn("the argument #%d is %s\n", i, args[i]); + } +} diff --git a/Task/Comments/Insitux/comments.insitux b/Task/Comments/Insitux/comments.insitux new file mode 100644 index 0000000000..d201b5ca4e --- /dev/null +++ b/Task/Comments/Insitux/comments.insitux @@ -0,0 +1,10 @@ +;this is a comment; and using semicolons here is fine + +(+ 2 2) ;this is a comment + +"this string will be ignored if in the top scope +which can also stretch across +multiple lines" + +(do "if you're desperate, using do will make sure this string will not be returned also" + (+ 2 2)) diff --git a/Task/Compare-a-list-of-strings/FutureBasic/compare-a-list-of-strings.basic b/Task/Compare-a-list-of-strings/FutureBasic/compare-a-list-of-strings.basic new file mode 100644 index 0000000000..b17efcd910 --- /dev/null +++ b/Task/Compare-a-list-of-strings/FutureBasic/compare-a-list-of-strings.basic @@ -0,0 +1,44 @@ +local fn ListObjectsAreIdentical( array as CFArrayRef ) as BOOL + BOOL result = NO + + CFSetRef set = fn SetWithArray( array ) + result = ( fn SetCount( set ) <= 1 ) +end fn = result + +local fn ListIsInLexicalOrder( array as CFArrayRef ) as BOOL + BOOL result = NO + + CFArrayRef sortedArray = fn ArraySortedArrayUsingSelector( array, @"compare:" ) + result = fn ArrayIsEqual( array, sortedArray ) +end fn = result + +void local fn ListTest + long i + + CFArrayRef listA = @[@"aaa", @"aaa", @"aaa", @"aaa"] + CFArrayRef listB = @[@"aaa", @"aab", @"aba", @"baa"] + CFArrayRef listC = @[@"caa", @"aab", @"aca", @"abc"] + CFArrayRef lists = @[listA, listB, listC] + + for i = 0 to 2 + CFArrayRef temp = lists[i] + printf @"Input array elements: %@ %@ %@ %@", temp[0], temp[1], temp[2], temp[3] + if ( fn ListObjectsAreIdentical( temp ) ) + printf @"List elements are lexically equal." + else + printf @"List elements not lexically equal." + end if + if ( fn ListIsInLexicalOrder( temp ) == YES ) + printf @"List elements are in ascending order." + else + printf @"List elements not in ascending order." + end if + CFArrayRef sorted = fn ArraySortedArrayUsingSelector( temp, @"compare:" ) + printf @"List elements sorted in ascending order: %@ %@ %@ %@", sorted[0], sorted[1], sorted[2], sorted[3] + print + next +end fn + +fn ListTest + +HandleEvents diff --git a/Task/Create-a-two-dimensional-array-at-runtime/FutureBasic/create-a-two-dimensional-array-at-runtime.basic b/Task/Create-a-two-dimensional-array-at-runtime/FutureBasic/create-a-two-dimensional-array-at-runtime.basic new file mode 100644 index 0000000000..de856a008d --- /dev/null +++ b/Task/Create-a-two-dimensional-array-at-runtime/FutureBasic/create-a-two-dimensional-array-at-runtime.basic @@ -0,0 +1,12 @@ +CFStringRef iStr, jStr +long i, j + +iStr = input @"Enter one positive integer: " +jStr = input @"Enter other positive integer: " +i = fn StringIntegerValue(iStr) +j = fn StringIntegerValue(jStr) +mda (0, 0) = {i, j} +mda (i, j) = i * j +printf @"mda(%ld, %ld) = %ld", i, j, mda_integer (i, j) + +HandleEvents diff --git a/Task/Descending-primes/FutureBasic/descending-primes.basic b/Task/Descending-primes/FutureBasic/descending-primes.basic new file mode 100644 index 0000000000..101a6e6f0c --- /dev/null +++ b/Task/Descending-primes/FutureBasic/descending-primes.basic @@ -0,0 +1,47 @@ +local fn IsPrime( n as NSUInteger ) as BOOL + BOOL isPrime = YES + NSUInteger i + + if n < 2 then exit fn = NO + if n = 2 then exit fn = YES + if n mod 2 == 0 then exit fn = NO + for i = 3 to int(n^.5) step 2 + if n mod i == 0 then exit fn = NO + next +end fn = isPrime + +void local fn DesecendingPrimes( limit as long ) + long i, n, mask, num, count = 0 + + for i = 0 to limit -1 + n = 0 : mask = i : num = 9 + while ( mask ) + if mask & 1 then n = n * 10 + num + mask = mask >> 1 + num-- + wend + mda(i) = n + next + + mda_sort @"compare:" + + for i = 1 to mda_count (0) - 1 + n = mda_integer(i) + if ( fn IsPrime( n ) ) + printf @"%10ld\b", n + count++ + if count mod 10 == 0 then print + end if + next + printf @"\n\n\tThere are %ld descending primes.", count +end fn + +window 1, @"Desecending Primes", ( 0, 0, 780, 230 ) +print + +CFTimeInterval t +t = fn CACurrentMediaTime +fn DesecendingPrimes( 512 ) +printf @"\n\tCompute time: %.3f ms\n",(fn CACurrentMediaTime-t)*1000 + +HandleEvents diff --git a/Task/Determine-if-two-triangles-overlap/00-TASK.txt b/Task/Determine-if-two-triangles-overlap/00-TASK.txt index 9fda145720..a6214da926 100644 --- a/Task/Determine-if-two-triangles-overlap/00-TASK.txt +++ b/Task/Determine-if-two-triangles-overlap/00-TASK.txt @@ -16,3 +16,8 @@ Optionally, see what the result is when only a single corner is in contact (ther :::*   (0,0),(1,0),(0,1)   and   (1,0),(2,0),(1,1)

+;Related tasks +* [[Check_if_two_polygons_overlap|Check if two polygons overlap]] +* [[Check_if_a_polygon_overlaps_with_a_rectangle|Check if a polygon overlaps with a rectangle]] +

+ diff --git a/Task/Dining-philosophers/Python/dining-philosophers.py b/Task/Dining-philosophers/Python/dining-philosophers-1.py similarity index 100% rename from Task/Dining-philosophers/Python/dining-philosophers.py rename to Task/Dining-philosophers/Python/dining-philosophers-1.py diff --git a/Task/Dining-philosophers/Python/dining-philosophers-2.py b/Task/Dining-philosophers/Python/dining-philosophers-2.py new file mode 100644 index 0000000000..fc6c3932e7 --- /dev/null +++ b/Task/Dining-philosophers/Python/dining-philosophers-2.py @@ -0,0 +1,189 @@ +"""Dining philosophers with multiprocessing module.""" +import multiprocessing as mp +import random +import time + +# Dining philosophers. See also comments at the threading +# version. Improvements, modifications: +# Support variable number of philosophers. +# "More deterministic" randomization by prealocating the schedules. +# Use scaling to allow faster runs producing results that are +# essentially the same. +# Collect statistics on wait times. + +SCALE = 0.2 +THINK = (3, 13) +DINE = (1, 10) + +class Philosopher(mp.Process): + """Independently running philosopher processes.""" + def __init__(self, idx, name, run_flag, chopstick_left, chopstick_right, + stats, schedule_think, schedule_dine): + mp.Process.__init__(self) + self.idx = idx + self.name = name + self.run_flag = run_flag + self.chopstick_left = chopstick_left + self.chopstick_right = chopstick_right + self.stats = stats + self.schedule_think = schedule_think + self.schedule_dine = schedule_dine + self.counter = 0 + self.num_dined = 0 + self.hungry_time_total = 0.0 + self.hungry_time_max = 0.0 + + def run(self): + while self.run_flag.value and self.counter < len(self.schedule_think): + # Philosopher is thinking (but really is sleeping). + time.sleep(self.schedule_think[self.counter]*SCALE) + duration = -time.perf_counter() + print(f'{self.name} is hungry', flush=True) + self.get_chopsticks2() + duration += time.perf_counter() + self.hungry_time_total += duration + self.hungry_time_max = max(self.hungry_time_max, duration) + self.dining() + # Populate self.stats: + self.stats.put({'name': self.name, + 'num_dined': self.num_dined, + 'hungry_time_total': self.hungry_time_total, + 'hungry_time_max': self.hungry_time_max}) + + def get_chopsticks(self): + """Use swaps and do not hold on to chopsticks.""" + chopstick1, chopstick2 = self.chopstick_left, self.chopstick_right + + while True: + chopstick1.acquire(True) + locked = chopstick2.acquire(False) + if locked: + return + chopstick1.release() + print(f'{self.name} swaps chopsticks', flush=True) + chopstick1, chopstick2 = chopstick2, chopstick1 + + def get_chopsticks0(self): + """Naive greedy implementation to trigger deadlock.""" + self.chopstick_left.acquire(True) + time.sleep(0.1) + self.chopstick_right.acquire(True) + + def get_chopsticks1(self): + """Break the symmetry by having one philosopher to be left handed.""" + if self.idx == 0: + chopstick1, chopstick2 = self.chopstick_left, self.chopstick_right + else: + chopstick1, chopstick2 = self.chopstick_right, self.chopstick_left + chopstick1.acquire(True) + locked = chopstick2.acquire(False) + if not locked: + chopstick1.release() + chopstick2.acquire(True) + chopstick1.acquire(True) + + def get_chopsticks2(self): + """Break the symmetry by having the even numbered philosophers to be + left handed.""" + if self.idx == 0: + chopstick1, chopstick2 = self.chopstick_left, self.chopstick_right + else: + chopstick1, chopstick2 = self.chopstick_right, self.chopstick_left + chopstick1.acquire(True) + locked = chopstick2.acquire(False) + if not locked: + chopstick1.release() + chopstick2.acquire(True) + chopstick1.acquire(True) + + def dining(self): + """Dining with two chopsticks.""" + print(f'{self.name} starts eating', flush=True) + self.num_dined += 1 + time.sleep(self.schedule_dine[self.counter]*SCALE) + self.counter += 1 + print(f'{self.name} finishes eating and leaves to think.', flush=True) + self.chopstick_left.release() + self.chopstick_right.release() + +def performance_report(stats): + """Print some stats about the wait times.""" + print("Performance report:") + for queue in stats: + data = queue.get() + print(f"Philosopher {data['name']} dined {data['num_dined']} times. ") + print(f" Total wait : {data['hungry_time_total'] / SCALE}") + print(f" Max wait : {data['hungry_time_max'] / SCALE}") + if data['num_dined'] > 0: + print(f" Average wait: " + f"{data['hungry_time_total'] / data['num_dined']/SCALE}") + +def generate_philosophers(names, run_flag, chopsticks, stats, max_dine): + """Gebnerate a list of philosophers with random schedules.""" + num = len(names) + philosophers = [Philosopher(i, names[i], run_flag, + chopsticks[i % num], + chopsticks[(i+1) % num], + stats[i], + [random.uniform(THINK[0], THINK[1]) + for j in range(max_dine)], + [random.uniform(DINE[0], DINE[1]) + for j in range(max_dine)]) + for i in range(num)] + return philosophers + +def generate_philosophers0(names, run_flag, chopsticks, stats, + schedule_think, schedule_dine): + """Allows the use of a predetermined thinking and dining schedule. + This may aid in triggering a deadlock.""" + num = len(names) + philosophers = [Philosopher(i, names[i], run_flag, + chopsticks[i % num], + chopsticks[(i+1) % num], + stats[i], + schedule_think[i], + schedule_dine[i]) + for i in range(num)] + return philosophers + +def dining_philosophers(philosopher_names=(('Aristotle', 'Kant', + 'Buddha', 'Marx', 'Russel')), + num_sec=100, max_dine=100): + """Main routine.""" + num = len(philosopher_names) + chopsticks = [mp.Lock() for n in range(num)] + random.seed(507129) + run_flag = mp.Value('b', True) + stats = [mp.Queue() for n in range(num)] + + philosophers = generate_philosophers(philosopher_names, run_flag, + chopsticks, stats, max_dine) + + # Use the following when trying to trigger a deadlock in conjunction with + # get_chopsticks0(): + #philosophers = generate_philosophers0(philosopher_names, run_flag, + # chopsticks, stats, [3]*max_dine, + # [5]*max_dine) + + for phi in philosophers: + phi.start() + time.sleep(num_sec*SCALE) + run_flag.value = False + print("Now we're finishing.", flush=True) + # We want to allow the philosophers to finish their meal. In fact, + # we even allow them to still start eating if they are presently + # hungry. This means we may need to wait at most num*DINE[1]. + wait_time = num*DINE[1] + while wait_time >= 0 and sum(p.is_alive() for p in philosophers) > 0: + time.sleep(1) + wait_time -= 1.0 + if wait_time < 0: + for phi in philosophers: + if phi.is_alive(): + print(f"Ooops, {phi.name} has not finished!!") + phi.terminate() + return 1 + performance_report(stats) + +if __name__ == '__main__': + dining_philosophers() diff --git a/Task/Duffinian-numbers/FutureBasic/duffinian-numbers.basic b/Task/Duffinian-numbers/FutureBasic/duffinian-numbers.basic new file mode 100644 index 0000000000..e90088f53d --- /dev/null +++ b/Task/Duffinian-numbers/FutureBasic/duffinian-numbers.basic @@ -0,0 +1,70 @@ +local fn IsPrime( n as NSUInteger ) as BOOL + BOOL isPrime = YES + NSUInteger i + + if n < 2 then exit fn = NO + if n = 2 then exit fn = YES + if n mod 2 == 0 then exit fn = NO + for i = 3 to int(n^.5) step 2 + if n mod i == 0 then exit fn = NO + next +end fn = isPrime + +local fn GCD( a as long, b as long ) as long + long r + + if ( a == 0 ) then r = b else r = fn GCD( b mod a, a ) +end fn = r + +local fn SumDiv( num as NSUInteger ) as NSUInteger + NSUInteger div = 2, sum = 0, quot, result + + while (1) + quot = num / div + if ( div > quot ) then result = 0 : exit while + if ( num mod div == 0 ) + sum += div + if ( div != quot ) then sum += quot + end if + div++ + wend + result = sum + 1 +end fn = result + +local fn IsDuffinian( n as NSUInteger) as BOOL + BOOL result = NO + + if ( fn IsPrime(n) == NO and fn GCD( fn SumDiv(n), n ) == 1 ) then exit fn = YES +end fn = result + +local fn FindDuffinians + long c = 0, n = 4 + + print "First 50 Duffinian numbers:" + do + if ( fn IsDuffinian(n) ) + printf @"%4d \b", n + c++ + if ( c mod 10 == 0 ) then print + end if + n++ + until ( c >= 50 ) + + c = 0 : n = 4 + printf @"\n\nFirst 56 Duffinian triplets:" + do + if ( fn IsDuffinian(n) and fn IsDuffinian(n + 1) and fn IsDuffinian(n + 2) ) + printf @" [%6ld %6ld %6ld] \b", n, n+1, n+2 + c++ + if ( c mod 4 == 0 ) then print + end if + n++ + until ( c >= 56 ) +end fn + +CFTimeInterval t +t = fn CACurrentMediaTime +fn FindDuffinians +printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*1000 + +HandleEvents diff --git a/Task/Emirp-primes/FutureBasic/emirp-primes.basic b/Task/Emirp-primes/FutureBasic/emirp-primes.basic new file mode 100644 index 0000000000..d4205be86a --- /dev/null +++ b/Task/Emirp-primes/FutureBasic/emirp-primes.basic @@ -0,0 +1,60 @@ +local fn IsPrime( n as NSUInteger ) as BOOL + BOOL isPrime = YES + NSUInteger i + + if n < 2 then exit fn = NO + if n = 2 then exit fn = YES + if n mod 2 == 0 then exit fn = NO + for i = 3 to int(n^.5) step 2 + if n mod i == 0 then exit fn = NO + next +end fn = isPrime + + +local fn ReverseNumber( n as NSUInteger ) as NSUInteger + NSInteger sum = 0 + + if n < 10 then exit fn = n + while ( n > 0 ) + sum = 10 * sum + ( n mod 10 ) + n /= 10 + wend +end fn = sum + + +local fn IsEmirp( n as NSUInteger ) as BOOL + BOOL result = NO + NSUInteger r = fn ReverseNumber(n) + if r != n and fn IsPrime(n) and fn IsPrime(r) then result = YES +end fn = result + + +local fn GetEmirpPrimes + NSUInteger count = 0, i = 13 + + printf @"\nThe first 20 Emirp primes are:" + do + if fn IsEmirp(i) then printf @"%4lu\b", i : count++ + i += 2 + until ( count == 20 ) + + printf @"\n\nThe Emirp primes between 7700 and 8000 are:" + i = 7701 + while ( i < 8000 ) + if fn IsEmirp(i) then printf @"%5lu\b", i + i += 2 + wend + + i = 13 : count = 0 + while (1) + if fn IsEmirp(i) then count++ + if count = 10000 then exit while + i += 2 + wend + printf @"\n\nThe 10,000th Emirp prime is: %lu", i + +end fn + +fn GetEmirpPrimes + +HandleEvents diff --git a/Task/Euclid-Mullin-sequence/ALGOL-W/euclid-mullin-sequence.alg b/Task/Euclid-Mullin-sequence/ALGOL-W/euclid-mullin-sequence.alg new file mode 100644 index 0000000000..4614fbc786 --- /dev/null +++ b/Task/Euclid-Mullin-sequence/ALGOL-W/euclid-mullin-sequence.alg @@ -0,0 +1,22 @@ +begin % find elements of the Euclid-Mullin sequence: starting from 2, % + % the next element is the smallest prime factor of 1 + the product % + % of the previous elements % + integer product; + write( "2" ); + product := 2; + for i := 2 until 8 do begin + integer nextV, p; + logical found; + nextV := product + 1; + % find the first prime factor of nextV % + p := 3; + found := false; + while p * p <= nextV and not found do begin + found := nextV rem p = 0; + if not found then p := p + 2 + end while_p_squared_le_nextV_and_not_found ; + if found then nextV := p; + writeon( i_w := 1, s_w := 0, " ", nextV ); + product := product * nextV + end for_i +end. diff --git a/Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence.awk b/Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence-1.awk similarity index 100% rename from Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence.awk rename to Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence-1.awk diff --git a/Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence-2.awk b/Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence-2.awk new file mode 100644 index 0000000000..9396392f84 --- /dev/null +++ b/Task/Euclid-Mullin-sequence/AWK/euclid-mullin-sequence-2.awk @@ -0,0 +1,24 @@ +# find elements of the Euclid-Mullin sequence: starting from 2, +# the next element is the smallest prime factor of 1 + the product +# of the previous elements +BEGIN { + printf( "2" ); + product = 2; + for( i = 2; i <= 8; i ++ ) + { + nextV = product + 1; + # find the first prime factor of nextV + p = 3; + found = 0; + while( p * p <= nextV && ! ( found = nextV % p == 0 ) ) + { + p += 2; + } + if( found ) + { + nextV = p; + } + printf( " %d", nextV ); + product *= nextV + } +} diff --git a/Task/Euclid-Mullin-sequence/Go/euclid-mullin-sequence.go b/Task/Euclid-Mullin-sequence/Go/euclid-mullin-sequence.go index 695ab60ff7..328d2b9bb8 100644 --- a/Task/Euclid-Mullin-sequence/Go/euclid-mullin-sequence.go +++ b/Task/Euclid-Mullin-sequence/Go/euclid-mullin-sequence.go @@ -15,7 +15,7 @@ var ( five = big.NewInt(5) six = big.NewInt(6) ten = big.NewInt(10) - max = big.NewInt(100000) + k100 = big.NewInt(100000) ) func pollardRho(n, c *big.Int) *big.Int { @@ -51,7 +51,7 @@ func pollardRho(n, c *big.Int) *big.Int { return d } -func smallestPrimeFactorWheel(n *big.Int) *big.Int { +func smallestPrimeFactorWheel(n, max *big.Int) *big.Int { if n.ProbablyPrime(15) { return n } @@ -82,13 +82,13 @@ func smallestPrimeFactorWheel(n *big.Int) *big.Int { } func smallestPrimeFactor(n *big.Int) *big.Int { - s := smallestPrimeFactorWheel(n) + s := smallestPrimeFactorWheel(n, k100) if s != nil { return s } c := big.NewInt(1) s = new(big.Int).Set(n) - for n.Cmp(max) > 0 { + for { d := pollardRho(n, c) if d.Cmp(zero) == 0 { if c.Cmp(ten) == 0 { @@ -96,20 +96,21 @@ func smallestPrimeFactor(n *big.Int) *big.Int { } c.Add(c, one) } else { - // can't be sure PR will find the smallest prime factor first - if d.Cmp(s) < 0 { - s.Set(d) - } - n.Quo(n, d) - if n.ProbablyPrime(5) { - if n.Cmp(s) < 0 { - return n + // get the smallest prime factor of 'd' + factor := smallestPrimeFactorWheel(d, d) + // check whether n/d has a smaller prime factor + s = smallestPrimeFactorWheel(n.Quo(n, d), factor) + if s != nil { + if s.Cmp(factor) < 0 { + return s + } else { + return factor } - return s + } else { + return factor } } } - return s } func main() { diff --git a/Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-1.lua b/Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-1.lua new file mode 100644 index 0000000000..6213d7fddf --- /dev/null +++ b/Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-1.lua @@ -0,0 +1,20 @@ +-- find elements of the Euclid-Mullin sequence: starting from 2, +-- the next element is the smallest prime factor of 1 + the product +-- of the previous elements +do + io.write( "2" ) + local product = 2 + for i = 2, 8 do + local nextV = product + 1 + -- find the first prime factor of nextV + local p = 3 + local found = false + while p * p <= nextV and not found do + found = nextV % p == 0 + if not found then p = p + 2 end + end + if found then nextV = p end + io.write( " ", nextV ) + product = product * nextV + end +end diff --git a/Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-2.lua b/Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-2.lua new file mode 100644 index 0000000000..d352302ed7 --- /dev/null +++ b/Task/Euclid-Mullin-sequence/Lua/euclid-mullin-sequence-2.lua @@ -0,0 +1,24 @@ +function gcd(a,b) + while b~=0 do + a,b=b,a%b + end + return math.abs(a) +end +function pollard_rho(n) + local x, y, d = 2, 2, 1 + local g = function(x) return (x*x+1) % n end + while d == 1 do + x = g(x) + y = g(g(y)) + d = gcd(math.abs(x-y),n) + end + if d == n then return d end + return math.min(d, math.floor( n/d ) ) +end + +local ar, product = {2}, 2 +repeat + ar[ #ar + 1 ] = pollard_rho( product + 1 ) + product = product * ar[ #ar ] +until #ar >= 8 +print( table.concat(ar, " ") ) diff --git a/Task/Euclid-Mullin-sequence/MiniScript/euclid-mullin-sequence.mini b/Task/Euclid-Mullin-sequence/MiniScript/euclid-mullin-sequence.mini new file mode 100644 index 0000000000..37cc90325a --- /dev/null +++ b/Task/Euclid-Mullin-sequence/MiniScript/euclid-mullin-sequence.mini @@ -0,0 +1,19 @@ +// find elements of the Euclid-Mullin sequence: starting from 2, +// the next element is the smallest prime factor of 1 + the product +// of the previous elements +seq = [2] +product = 2 +for i in range( 2, 8 ) + nextV = product + 1 + // find the first prime factor of nextV + p = 3 + found = false + while p * p <= nextV and not found + found = nextV % p == 0 + if not found then p = p + 2 + end while + if found then nextV = p + seq.push( nextV ) + product = product * nextV +end for +print seq.join( " ") diff --git a/Task/Euclid-Mullin-sequence/Ring/euclid-mullin-sequence.ring b/Task/Euclid-Mullin-sequence/Ring/euclid-mullin-sequence.ring new file mode 100644 index 0000000000..5a4239f730 --- /dev/null +++ b/Task/Euclid-Mullin-sequence/Ring/euclid-mullin-sequence.ring @@ -0,0 +1,18 @@ +// find elements of the Euclid-Mullin sequence: starting from 2, +// the next element is the smallest prime factor of 1 + the product +// of the previous elements +see "2" +product = 2 +for i = 2 to 8 + nextV = product + 1 + // find the first prime factor of nextV + p = 3 + found = false + while p * p <= nextV and not found + found = ( nextV % p ) = 0 + if not found p = p + 2 ok + end + if found nextV = p ok + see " " + nextV + product = product * nextV +next diff --git a/Task/Euclid-Mullin-sequence/Ruby/euclid-mullin-sequence.rb b/Task/Euclid-Mullin-sequence/Ruby/euclid-mullin-sequence.rb new file mode 100644 index 0000000000..2351ffe3ee --- /dev/null +++ b/Task/Euclid-Mullin-sequence/Ruby/euclid-mullin-sequence.rb @@ -0,0 +1,15 @@ +def pollard_rho(n) + x, y, d = 2, 2, 1 + g = proc{|x|(x*x+1) % n} + while d == 1 do + x = g[x] + y = g[g[y]] + d = (x-y).abs.gcd(n) + end + return d if d == n + [d, n/d].compact.min +end + +ar = [2] +ar << pollard_rho(ar.inject(&:*)+1) until ar.size >= 16 +puts ar.join(", ") diff --git a/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-1.wren b/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-1.wren index 648d20f2bf..f4cb0f99b6 100644 --- a/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-1.wren +++ b/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-1.wren @@ -4,33 +4,9 @@ var zero = BigInt.zero var one = BigInt.one var two = BigInt.two var ten = BigInt.ten -var max = BigInt.new(100000) +var k100 = BigInt.new(100000) -var pollardRho = Fn.new { |n, c| - var g = Fn.new { |x, y| (x*x + c) % n } - var x = two - var y = two - var z = one - var d = max + one - var count = 0 - while (true) { - x = g.call(x, n) - y = g.call(g.call(y, n), n) - d = (x - y).abs % n - z = z * d - count = count + 1 - if (count == 100) { - d = BigInt.gcd(z, n) - if (d != one) break - z = one - count = 0 - } - } - if (d == n) return zero - return d -} - -var smallestPrimeFactorWheel = Fn.new { |n| +var smallestPrimeFactorWheel = Fn.new { |n, max| if (n.isProbablePrime(5)) return n if (n % 2 == zero) return BigInt.two if (n % 3 == zero) return BigInt.three @@ -47,23 +23,22 @@ var smallestPrimeFactorWheel = Fn.new { |n| } var smallestPrimeFactor = Fn.new { |n| - var s = smallestPrimeFactorWheel.call(n) + var s = smallestPrimeFactorWheel.call(n, k100) if (s) return s var c = one - s = n - while (n > max) { - var d = pollardRho.call(n, c) + while (true) { + var d = BigInt.pollardRho(n, 2, c) if (d == 0) { if (c == ten) Fiber.abort("Pollard Rho doesn't appear to be working.") c = c + one } else { - // can't be sure PR will find the smallest prime factor first - s = BigInt.min(s, d) - n = n / d - if (n.isProbablePrime(2)) return BigInt.min(s, n) + // get the smallest prime factor of 'd' + var factor = smallestPrimeFactorWheel.call(d, d) + // check whether n/d has a smaller prime factor + s = smallestPrimeFactorWheel.call(n/d, factor) + return s ? BigInt.min(s, factor) : factor } } - return s } var k = 16 diff --git a/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-2.wren b/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-2.wren index 69fded1753..3723ba66fe 100644 --- a/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-2.wren +++ b/Task/Euclid-Mullin-sequence/Wren/euclid-mullin-sequence-2.wren @@ -2,45 +2,38 @@ import "./gmp" for Mpz -var max = Mpz.from(100000) +var k100 = Mpz.from(100000) -var smallestPrimeFactorWheel = Fn.new { |n| +var smallestPrimeFactorTrial = Fn.new { |n, max| if (n.probPrime(15) > 0) return n - if (n.isEven) return Mpz.two - if (n.isDivisibleUi(3)) return Mpz.three - if (n.isDivisibleUi(5)) return Mpz.five - var k = Mpz.from(7) - var i = 0 - var inc = [4, 2, 4, 2, 4, 6, 2, 6] + var k = Mpz.one while (k * k <= n) { - if (n.isDivisible(k)) return k - k.add(inc[i]) + k.nextPrime if (k > max) return null - i = (i + 1) % 8 + if (n.isDivisible(k)) return k } } var smallestPrimeFactor = Fn.new { |n| - var s = smallestPrimeFactorWheel.call(n) + var s = smallestPrimeFactorTrial.call(n, k100) if (s) return s var c = Mpz.one - s = n.copy() - while (n > max) { + while (true) { var d = Mpz.pollardRho(n, 2, c) if (d.isZero) { if (c == 100) Fiber.abort("Pollard Rho doesn't appear to be working.") c.inc } else { - // can't be sure PR will find the smallest prime factor first - s.min(d) - n.div(d) - if (n.probPrime(5) > 0) return Mpz.min(s, n) + // get the smallest prime factor of 'd' + var factor = smallestPrimeFactorTrial.call(d, d) + // check whether n/d has a smaller prime factor + s = smallestPrimeFactorTrial.call(n/d, factor) + return s ? Mpz.min(s, factor) : factor } } - return s } -var k = 19 +var k = 27 System.print("First %(k) terms of the Euclid–Mullin sequence:") System.print(2) var prod = Mpz.two diff --git a/Task/Execute-Brain-/Commodore-BASIC/execute-brain-.basic b/Task/Execute-Brain-/Commodore-BASIC/execute-brain-.basic new file mode 100644 index 0000000000..a156f8bebb --- /dev/null +++ b/Task/Execute-Brain-/Commodore-BASIC/execute-brain-.basic @@ -0,0 +1,65 @@ +100 REM BRAINF*CK FOR COMMODORE BASIC +110 DB=0:REM SET TO 1 FOR DEBUGGING +120 P$="" +130 READ C$ +140 P$=P$+C$ +150 IF LEN(C$)<>0 THEN 130 +160 REM PAIR UP BRACKETS INTO B% +170 DIM B%(LEN(P$)) +180 REM TRACK OPEN BRACKETS IN O% +190 DIM O%(INT(LEN(P$)/2)):O=0 +200 FOR I=1 TO LEN(P$) +210 : I$=MID$(P$,I,1) +220 : IF I$="[" THEN O%(O)=I:O=O+1 +230 : IF I$<>"]" THEN 270 +240 : IF O=0 THEN PRINT "UNMATCHED BRACKET AT"I". ABORTING.":END +250 : O=O-1:M=O%(O) +260 : B%(I)=M:B%(M)=I +270 NEXT I +280 IF O THEN PRINT "UNMATCHED BRACKETS AT EOF. ABORTING.":END +290 REM SET MS TO NUMBER OF MEMORY CELLS NEEDED. +300 REM THE BF SPEC REQUIRES 30000, WHICH WILL WORK ON C64 OR 48K+ PET. +310 AN UNEXPANDED VIC-20 WILL HANDLE 1000, A C-16 9000. THE DEMO ONLY NEEDS 4. +320 MS=4:DIM M%(MS/2-1):MP=0 +330 REM FUNCTION TO READ BYTE AT CELL N +340 DEF FNMP(N)=INT(M%(INT(N/2)) / (1+255*(N AND 1))) AND 255 +350 FOR I=1 TO LEN(P$) +360 : IF MP<0 OR MP>=MS THEN PRINT "ERROR: MP OUT OF RANGE AT"I:END +370 : IF DB THEN PRINT "IP:"I"("I$") MP: "MP"("FNMP(MP)")" +380 : I$=MID$(P$,I,1) +390 : IF I$<>"[" THEN 420 +400 : IF FNMP(MP)=0 THEN I=B%(I) +410 : GOTO 530 +420 : IF I$<>"]" THEN 450 +430 : IF FNMP(MP) THEN I=B%(I) +440 : GOTO 530 +450 : IF I$="<" THEN MP=MP-1:GOTO 530 +460 : IF I$=">" THEN MP=MP+1:GOTO 530 +470 : IF I$="-" THEN V=FNMP(MP)-1:GOTO 560 +480 : IF I$="+" THEN V=FNMP(MP)+1:GOTO 560 +490 : IF I$="." THEN PRINTCHR$(FNMP(MP));:GOTO 530 +500 : IF I$<>"," THEN 530 +510 : GET K$:IF K$="" THEN 510 +520 : V=ASC(K$):GOTO 560 +530 NEXT I +540 END +550 REM UPDATE CELL AT MP WITH VALUE IN V +560 M=INT(MP/2):O=M%(M):V=V AND 255 +570 N0=(O AND -256)+V +580 N1=(V*256+(O AND 255)) +590 M%(M) = (MP AND 1)*N1 - ((MP AND 1)=0)*N0 +600 GOTO 530 +610 REM HELLO, WORLD PROGRAM +620 DATA "+++++++++[>++++++++<-]>." +630 DATA "---." +640 DATA "+++++++..+++." +650 DATA ">>++++[<+++++++++++>-]<." +660 DATA ">++++[<--->-]<." +670 DATA "<++++++++." +680 DATA "--------." +690 DATA "+++." +700 DATA "------." +710 DATA "--------." +720 DATA ">>[++][<+++++++>-]<+." +730 DATA ">++++++++++." +740 DATA "" diff --git a/Task/Execute-Brain-/TRS-80-BASIC/execute-brain-.basic b/Task/Execute-Brain-/TRS-80-BASIC/execute-brain-.basic new file mode 100644 index 0000000000..f5b2f25600 --- /dev/null +++ b/Task/Execute-Brain-/TRS-80-BASIC/execute-brain-.basic @@ -0,0 +1,73 @@ +100 REM BRAINF*CK FOR TRS-80 LEVEL II BASIC +103 DB=0:REM SET TO 1 FOR DEBUGGING +105 REM FIRST MAKE SURE WE HAVE ENOUGH STRING HEAP FOR PROGRAM +110 READ C$:C=LEN(C$):IF C>M THEN M=C +120 PS=PS+C +130 IF C THEN 110 +135 REM ALLOCATE THE HEAP +140 CLEAR 2*(PS+M) +145 REM RE-READ PROGRAM, REMEMBERING IT THIS TIME +150 RESTORE +160 P$="" +170 READ C$ +180 P$=P$+C$ +190 IF LEN(C$)<>0 THEN 170 +195 REM PAIR UP BRACKETS INTO B% +200 DIM B%(LEN(P$)) +205 REM TRACK OPEN BRACKETS IN O% +210 DIM O%(INT(LEN(P$)/2)):O=0 +220 FOR I=1 TO LEN(P$) +230 : I$=MID$(P$,I,1) +240 : IF I$="(" OR I$="[" THEN O%(O)=I:O=O+1 +250 : IF I$<>")" AND I$<>"]" THEN 290 +260 : IF O=0 THEN PRINT "UNMATCHED BRACKET AT"I". ABORTING.":END +270 : O=O-1:M=O%(O) +280 : B%(I)=M:B%(M)=I +290 NEXT I +300 IF O THEN PRINT "UNMATCHED BRACKETS AT EOF. ABORTING.":END +303 REM SET MS TO NUMBER OF MEMORY CELLS NEEDED +305 REM THE BF SPEC REQUIRES 30000, WHICH DOES WORK ON A SYSTEM WITH 48K RAM. +307 REM THE DEMO HELLO-WORLD PROGRAM ONLY REQUIRES 4 CELLS. +310 MS=4:DIM M%(MS/2-1):MP=0 +313 REM FUNCTION TO READ BYTE AT CELL N +315 DEF FNMP(N)=INT(M%(INT(N/2)) / (1+255*(N AND 1))) AND 255 +320 FOR I=1 TO LEN(P$) +323 : IF MP<0 OR MP>=MS THEN PRINT "ERROR: MP OUT OF RANGE AT"I:END +327 : IF DB THEN PRINT "IP:"I"("I$") MP:"MP"("FNMP(MP)")" +330 : I$=MID$(P$,I,1) +340 : IF I$<>"(" AND I$<>"[" THEN 370 +350 : IF FNMP(MP)=0 THEN I=B%(I) +360 : GOTO 480 +370 : IF I$<>")" AND I$<>"]" THEN 400 +380 : IF FNMP(MP) THEN I=B%(I) +390 : GOTO 480 +400 : IF I$="<" THEN MP=MP-1:GOTO 480 +410 : IF I$=">" THEN MP=MP+1:GOTO 480 +420 : IF I$="-" THEN V=FNMP(MP)-1:GOTO 500 +430 : IF I$="+" THEN V=FNMP(MP)+1:GOTO 500 +440 : IF I$="." THEN ?CHR$(FNMP(MP));:GOTO 480 +450 : IF I$<>"," THEN 480 +460 : K$=INKEY$:IF K$="" THEN 460 +470 : V=ASC(K$):GOTO 500 +480 NEXT I +490 END +495 REM UPDATE CELL AT MP WITH VALUE IN V +500 M=INT(MP/2):O=M%(M):V=V AND 255 +510 N0=(O AND -256)+V +520 N1=(V*256+(O AND 255)) +530 M%(M) = (MP AND 1)*N1 - ((MP AND 1)=0)*N0 +540 GOTO 480 +545 REM HELLO, WORLD PROGRAM +570 DATA "+++++++++[>++++++++<-]>." +580 DATA "<+++++[>+++++<-]>++++." +590 DATA "+++++++..+++." +600 DATA ">>++++[<+++++++++++>-]<." +610 DATA ">++++[<--->-]<." +620 DATA "<++++++++." +630 DATA "--------." +640 DATA "+++." +650 DATA "------." +660 DATA "--------." +670 DATA ">>[++][<+++++++>-]<+." +680 DATA ">++++++++++." +690 DATA "" diff --git a/Task/Extensible-prime-generator/FutureBasic/extensible-prime-generator.basic b/Task/Extensible-prime-generator/FutureBasic/extensible-prime-generator.basic new file mode 100644 index 0000000000..f9e460d1ef --- /dev/null +++ b/Task/Extensible-prime-generator/FutureBasic/extensible-prime-generator.basic @@ -0,0 +1,53 @@ +local fn IsPrime( n as NSUInteger ) as BOOL + BOOL isPrime = YES + NSUInteger i + + if n < 2 then exit fn = NO + if n = 2 then exit fn = YES + if n mod 2 == 0 then exit fn = NO + for i = 3 to int(n^.5) step 2 + if n mod i == 0 then exit fn = NO + next +end fn = isPrime + + +local fn ExtensiblePrimes + long c = 0, n = 2, count = 0, track = 0 + + printf @"The first 20 prime numbers are: " + while ( c < 20 ) + if ( fn IsPrime(n) ) + printf @"%ld \b", n + c++ + end if + n++ + wend + + printf @"\n\nPrimes between 100 and 150 include: " + for n = 100 to 150 + if ( fn IsPrime(n) ) then printf @"%ld \b", n + next + + printf @"\n\nPrimes beween 7,700 and 8,000 include: " + c = 0 + for n = 7700 to 8000 + if ( fn IsPrime(n) ) then c += fn IsPrime(n) : printf @"%ld \b", n : count++ : track++ + if count = 10 then print : count = 0 + next + printf @"There are %ld primes beween 7,700 and 8,000.", track + + printf @"\nThe 10,000th prime is: " + c = 0 : n = 1 + while ( c < 10000 ) + n++ + c += fn IsPrime(n) + wend + printf @"%ld", n +end fn + +CFTimeInterval t + +t = fn CACurrentMediaTime +fn ExtensiblePrimes +printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*100 +HandleEvents diff --git a/Task/Filter/AArch64-Assembly/filter.aarch64 b/Task/Filter/AArch64-Assembly/filter.aarch64 new file mode 100644 index 0000000000..7ac019980f --- /dev/null +++ b/Task/Filter/AArch64-Assembly/filter.aarch64 @@ -0,0 +1,142 @@ +/* ARM assembly AARCH64 Raspberry PI 3B */ +/* program filterdes64.s */ + +/************************************/ +/* Constantes */ +/************************************/ +/* for this file see task include a file in language AArch64 assembly*/ +.include "../includeConstantesARM64.inc" + +/************************************/ +/* Initialized data */ +/************************************/ +.data +szMessResult: .asciz "Start array : " +szMessResultFil: .asciz "Filter array : " +szMessResultdest: .asciz "Same array : " +szMessStart: .asciz "Program 64 bits start.\n" +szCarriageReturn: .asciz "\n" +szFiller: .asciz " " +.align 4 +arrayNumber: .quad 1,2,3,4,5,6,7,8,9,10 +.equ LGARRAY, (. - arrayNumber) / 8 +/************************************/ +/* UnInitialized data */ +/************************************/ +.bss +.align 4 +arrayNumberFil: .skip 8 * LGARRAY // result array +sZoneConv: .skip 24 +/************************************/ +/* code section */ +/************************************/ +.text +.global main +main: + ldr x0,qAdrszMessStart // display start message + bl affichageMess + ldr x0,qAdrszMessResult // display message + bl affichageMess + ldr x5,qAdrarrayNumber // start array address + mov x4,#0 // index + +1: + ldr x0,[x5,x4,lsl #3] // load a value + ldr x1,qAdrsZoneConv + bl conversion10 // décimal conversion + ldr x0,qAdrsZoneConv + bl affichageMess // display value + ldr x0,qAdrszFiller + bl affichageMess + add x4,x4,#1 // increment index + cmp x4,#LGARRAY // end array ? + blt 1b // no -> loop + ldr x0,qAdrszCarriageReturn + bl affichageMess + + ldr x6,qAdrarrayNumberFil // adrress result array + mov x4,#0 // index + mov x3,#0 // index result +2: + ldr x0,[x5,x4,lsl #3] // load a value + tst x0,#1 // odd ? + bne 3f + str x0,[x6,x3,lsl #3] // no -> store in result array + add x3,x3,#1 // and increment result index +3: + add x4,x4,#1 // increment array index + cmp x4,#LGARRAY // end ? + blt 2b // no -> loop + + ldr x0,qAdrszMessResultFil + bl affichageMess + mov x4,#0 // init index + +4: // display filter result array + ldr x0,[x6,x4,lsl #3] + ldr x1,qAdrsZoneConv + bl conversion10 + ldr x0,qAdrsZoneConv + bl affichageMess + ldr x0,qAdrszFiller + bl affichageMess + add x4,x4,#1 + cmp x4,x3 + blt 4b + ldr x0,qAdrszCarriageReturn + bl affichageMess + + // array destruction + mov x4,#0 // index + mov x3,#0 // index result +5: + ldr x0,[x5,x4,lsl #3] // load a value + tst x0,#1 // odd ? + bne 7f + cmp x3,x4 // index = no store + beq 6f + str x0,[x5,x3,lsl #3] // store in free item on same array +6: + add x3,x3,#1 // and increment result index +7: + add x4,x4,#1 // increment array index + cmp x4,#LGARRAY // end ? + blt 5b // no -> loop + + ldr x0,qAdrszMessResultdest + bl affichageMess + mov x4,#0 // init index + +8: // display array + ldr x0,[x5,x4,lsl #3] + ldr x1,qAdrsZoneConv + bl conversion10 + ldr x0,qAdrsZoneConv + bl affichageMess + ldr x0,qAdrszFiller + bl affichageMess + add x4,x4,#1 + cmp x4,x3 + blt 8b + ldr x0,qAdrszCarriageReturn + bl affichageMess + + +100: // standard end of the program + mov x0, #0 // return code + mov x8, #EXIT // request to exit program + svc 0 // perform the system call +qAdrszCarriageReturn: .quad szCarriageReturn +qAdrszMessStart: .quad szMessStart +qAdrarrayNumber: .quad arrayNumber +qAdrszMessResult: .quad szMessResult +qAdrarrayNumberFil: .quad arrayNumberFil +qAdrszMessResultFil: .quad szMessResultFil +qAdrszMessResultdest: .quad szMessResultdest +qAdrsZoneConv: .quad sZoneConv +qAdrszFiller: .quad szFiller +/***************************************************/ +/* ROUTINES INCLUDE */ +/***************************************************/ +/* for this file see task include a file in language AArch64 assembly*/ +.include "../includeARM64.inc" diff --git a/Task/Filter/ARM-Assembly/filter.arm b/Task/Filter/ARM-Assembly/filter.arm new file mode 100644 index 0000000000..68fa970a7b --- /dev/null +++ b/Task/Filter/ARM-Assembly/filter.arm @@ -0,0 +1,144 @@ +/* ARM assembly Raspberry PI */ +/* program filterdes.s */ + +/************************************/ +/* Constantes */ +/************************************/ +/* for constantes see task include a file in arm assembly */ +.include "../constantes.inc" + +/************************************/ +/* Initialized data */ +/************************************/ +.data +szMessResult: .asciz "Start array : " +szMessResultFil: .asciz "Filter array : " +szMessResultdest: .asciz "Same array : " +szMessStart: .asciz "Program 32 bits start.\n" +szCarriageReturn: .asciz "\n" +.align 4 +arrayNumber: .int 1,2,3,4,5,6,7,8,9,10 +.equ LGARRAY, (. - arrayNumber) / 4 +/************************************/ +/* UnInitialized data */ +/************************************/ +.bss +.align 4 +arrayNumberFil: .skip 4 * LGARRAY @ result array +sZoneConv: .skip 24 +/************************************/ +/* code section */ +/************************************/ +.text +.global main +main: + ldr r0,iAdrszMessStart @ display start message + bl affichageMess + ldr r0,iAdrszMessResult @ display message + bl affichageMess + ldr r5,iAdrarrayNumber @ start array address + mov r4,#0 @ index + +1: + ldr r0,[r5,r4,lsl #2] @ load a value + ldr r1,iAdrsZoneConv + bl conversion10 @ décimal conversion + add r1,r1,r0 @ compute address end number + add r1,#2 @ add two characters + mov r0,#0 @ for limit the size of display number + strb r0,[r1] @ to store a final zero + ldr r0,iAdrsZoneConv + bl affichageMess @ display value + add r4,r4,#1 @ increment index + cmp r4,#LGARRAY @ end array ? + blt 1b @ no -> loop + ldr r0,iAdrszCarriageReturn + bl affichageMess + + ldr r6,iAdrarrayNumberFil @ adrress result array + mov r4,#0 @ index + mov r3,#0 @ index result +2: + ldr r0,[r5,r4,lsl #2] @ load a value + tst r0,#1 @ odd ? + streq r0,[r6,r3,lsl #2] @ no -> store in result array + addeq r3,r3,#1 @ and increment result index + add r4,r4,#1 @ increment array index + cmp r4,#LGARRAY @ end ? + blt 2b @ no -> loop + + ldr r0,iAdrszMessResultFil + bl affichageMess + mov r4,#0 @ init index + +3: @ display filter result array + ldr r0,[r6,r4,lsl #2] + ldr r1,iAdrsZoneConv + bl conversion10 + add r1,r1,r0 + add r1,#2 + mov r0,#0 + strb r0,[r1] + ldr r0,iAdrsZoneConv + bl affichageMess + add r4,r4,#1 + cmp r4,r3 + blt 3b + ldr r0,iAdrszCarriageReturn + bl affichageMess + + @ array destruction + mov r4,#0 @ index + mov r3,#0 @ index result +4: + ldr r0,[r5,r4,lsl #2] @ load a value + tst r0,#1 @ even ? + bne 6f + cmp r3,r4 @ index = no store + beq 5f + str r0,[r5,r3,lsl #2] @ store in free item on same array +5: + add r3,r3,#1 @ and increment result index +6: + add r4,r4,#1 @ increment array index + cmp r4,#LGARRAY @ end ? + blt 4b @ no -> loop + + ldr r0,iAdrszMessResultdest + bl affichageMess + mov r4,#0 @ init index + +7: @ display array + ldr r0,[r5,r4,lsl #2] + ldr r1,iAdrsZoneConv + bl conversion10 + add r1,r1,r0 + add r1,#2 + mov r0,#0 + strb r0,[r1] + ldr r0,iAdrsZoneConv + bl affichageMess + add r4,r4,#1 + cmp r4,r3 + blt 7b + ldr r0,iAdrszCarriageReturn + bl affichageMess + + +100: @ standard end of the program + mov r0, #0 @ return code + mov r7, #EXIT @ request to exit program + svc 0 @ perform the system call +iAdrszCarriageReturn: .int szCarriageReturn +iAdrszMessStart: .int szMessStart +iAdrarrayNumber: .int arrayNumber +iAdrszMessResult: .int szMessResult +iAdrarrayNumberFil: .int arrayNumberFil +iAdrszMessResultFil: .int szMessResultFil +iAdrszMessResultdest: .int szMessResultdest +iAdrsZoneConv: .int sZoneConv +/***************************************************/ +/* ROUTINES INCLUDE */ +/***************************************************/ +/* for this file see task include a file in language ARM assembly*/ +.include "../affichage.inc" diff --git a/Task/First-class-environments/Java/first-class-environments.java b/Task/First-class-environments/Java/first-class-environments.java new file mode 100644 index 0000000000..f61d394c09 --- /dev/null +++ b/Task/First-class-environments/Java/first-class-environments.java @@ -0,0 +1,75 @@ +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public final class FirstClassEnvironments { + + public static void main(String[] aArgs) { + code(); + } + + private static void code() { + do { + for ( int job = 0; job < JOBS; job++ ) { + switchTo(job); + hailstone(); + } + System.out.println(); + } while ( ! allDone() ); + + System.out.println(System.lineSeparator() + "Counts:"); + for ( int job = 0; job < JOBS; job++ ) { + switchTo(job); + System.out.print(String.format("%4d", count)); + } + System.out.println(); + } + + private static boolean allDone() { + for ( int job = 0; job < JOBS; job++ ) { + switchTo(job); + if ( sequence > 1 ) { + return false; + } + } + return true; + } + + private static void hailstone() { + System.out.print(String.format("%4d", sequence)); + if ( sequence == 1 ) { + return; + } + + count += 1; + sequence = ( sequence % 2 == 1 ) ? 3 * sequence + 1 : sequence / 2; + } + + private static void switchTo(int aID) { + if ( aID != currentId ) { + environments.get(currentId).seq = sequence; + environments.get(currentId).count = count; + currentId = aID; + } + + sequence = environments.get(aID).seq; + count = environments.get(aID).count; + } + + private static class Environment { + + public Environment(int aSeq, int aCount) { + seq = aSeq; count = aCount; + } + + private int seq, count; + + } + + private static int sequence, count, currentId; + private static List environments = + IntStream.rangeClosed(1, 12).mapToObj( i -> new Environment(i, 0 ) ).collect(Collectors.toList()); + + private static final int JOBS = 12; + +} diff --git a/Task/First-class-functions-Use-numbers-analogously/Java/first-class-functions-use-numbers-analogously.java b/Task/First-class-functions-Use-numbers-analogously/Java/first-class-functions-use-numbers-analogously.java new file mode 100644 index 0000000000..7b381dee6e --- /dev/null +++ b/Task/First-class-functions-Use-numbers-analogously/Java/first-class-functions-use-numbers-analogously.java @@ -0,0 +1,24 @@ +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Function; + +public class FirstClassFunctionsUseNumbersAnalogously { + + public static void main(String[] args) { + final double x = 2.0, xi = 0.5, + y = 4.0, yi = 0.25, + z = x + y, zi = 1.0 / ( x + y ); + + List list = List.of( x, y, z ); + List inverseList = List.of( xi, yi, zi ); + + BiFunction> multiplier = (a, b) -> product -> a * b * product; + + for ( int i = 0; i < list.size(); i++ ) { + Function multiply = multiplier.apply(list.get(i), inverseList.get(i)); + final double argument = (double) ( i + 1 ); + System.out.println(multiply.apply(argument)); + } + } + +} diff --git a/Task/FizzBuzz/00-TASK.txt b/Task/FizzBuzz/00-TASK.txt index d219178474..13bc667a38 100644 --- a/Task/FizzBuzz/00-TASK.txt +++ b/Task/FizzBuzz/00-TASK.txt @@ -3,9 +3,9 @@ Write a program that prints the integers from   '''1'''   to   '' But: -:*   for multiples of three,   print   '''Fizz'''     (instead of the number) -:*   for multiples of five,   print   '''Buzz'''     (instead of the number) -:*   for multiples of both three and five,   print   '''FizzBuzz'''     (instead of the number) +:*   for multiples of three,   print   '''Fizz'''     instead of the number; +:*   for multiples of five,   print   '''Buzz'''     instead of the number; +:*   for multiples of both three and five,   print   '''FizzBuzz'''     instead of the number. The   ''FizzBuzz''   problem was presented as the lowest level of comprehension required to illustrate adequacy. diff --git a/Task/Flatten-a-list/Insitux/flatten-a-list.insitux b/Task/Flatten-a-list/Insitux/flatten-a-list.insitux new file mode 100644 index 0000000000..22daea6822 --- /dev/null +++ b/Task/Flatten-a-list/Insitux/flatten-a-list.insitux @@ -0,0 +1 @@ +(flatten [[1] 2 [[3 4] 5] [[[]]] [[[6]]] 7 8 []]) diff --git a/Task/Fortunate-numbers/C++/fortunate-numbers.cpp b/Task/Fortunate-numbers/C++/fortunate-numbers.cpp new file mode 100644 index 0000000000..ed355c01af --- /dev/null +++ b/Task/Fortunate-numbers/C++/fortunate-numbers.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +std::vector prime_numbers(const int32_t& limit) { + const int32_t half_limit = ( limit % 2 == 0 ) ? limit / 2 : 1 + limit / 2; + std::vector composite(half_limit, false); + for ( int32_t i = 1, p = 3; i < half_limit; p += 2, ++i ) { + if ( ! composite[i] ) { + for ( int32_t a = i + p; a < half_limit; a += p ) { + composite[a] = true; + } + } + } + + std::vector primes{2}; + for ( int32_t i = 1, p = 3; i < half_limit; p += 2, ++i ) { + if ( ! composite[i] ) { + primes.push_back(p); + } + } + return primes; +} + +bool contains(const std::vector& list, const int32_t& n) { + return std::find(list.begin(), list.end(), n) != list.end(); +} + +int main() { + std::vector primes = prime_numbers(250'000'000); + std::set fortunates; + int32_t primorial = 1; + int32_t index = 0; + + while ( fortunates.size() < 8 ) { + primorial *= primes[index++]; + int32_t candidate = 3; + while ( ! contains(primes, primorial + candidate) ) { + candidate += 2; + } + fortunates.emplace(candidate); + } + + std::cout << "The first 8 distinct fortunate numbers are:" << std::endl; + for ( const int32_t& fortunate : fortunates ) { + std::cout << fortunate << " "; + } +} diff --git a/Task/Fortunate-numbers/Java/fortunate-numbers.java b/Task/Fortunate-numbers/Java/fortunate-numbers.java new file mode 100644 index 0000000000..e2c379d81e --- /dev/null +++ b/Task/Fortunate-numbers/Java/fortunate-numbers.java @@ -0,0 +1,41 @@ +import java.math.BigInteger; +import java.util.BitSet; +import java.util.NavigableSet; +import java.util.TreeSet; + +public final class FortunateNumbers { + + public static void main(String[] aArgs) { + BitSet primes = primeSieve(400); + NavigableSet fortunates = new TreeSet(); + BigInteger primorial = BigInteger.ONE; + + for ( int prime = 2; prime >= 0; prime = primes.nextSetBit(prime + 1) ) { + primorial = primorial.multiply(BigInteger.valueOf(prime)); + int candidate = 3; + while ( ! primorial.add(BigInteger.valueOf(candidate)).isProbablePrime(CERTAINTY_LEVEL) ) { + candidate += 2; + } + fortunates.add(candidate); + } + + System.out.println("The first 50 distinct fortunate numbers are:"); + for ( int i = 0; i < 50; i++ ) { + System.out.print(String.format("%4d%s", fortunates.pollFirst(), ( i % 10 == 9 ? "\n" : "" ))); + } + } + + private static BitSet primeSieve(int aNumber) { + BitSet sieve = new BitSet(aNumber + 1); + sieve.set(2, aNumber + 1); + for ( int i = 2; i <= Math.sqrt(aNumber); i = sieve.nextSetBit(i + 1) ) { + for ( int j = i * i; j <= aNumber; j = j + i ) { + sieve.clear(j); + } + } + return sieve; + } + + private static final int CERTAINTY_LEVEL = 10; + +} diff --git a/Task/Generate-lower-case-ASCII-alphabet/Insitux/generate-lower-case-ascii-alphabet.insitux b/Task/Generate-lower-case-ASCII-alphabet/Insitux/generate-lower-case-ascii-alphabet.insitux new file mode 100644 index 0000000000..aaabaf480b --- /dev/null +++ b/Task/Generate-lower-case-ASCII-alphabet/Insitux/generate-lower-case-ascii-alphabet.insitux @@ -0,0 +1,4 @@ +(-> (map char-code "az") + (adj _ inc) + (.. range) + (map char-code)) diff --git a/Task/Goldbachs-comet/BASIC256/goldbachs-comet.basic b/Task/Goldbachs-comet/BASIC256/goldbachs-comet.basic new file mode 100644 index 0000000000..2083729dbf --- /dev/null +++ b/Task/Goldbachs-comet/BASIC256/goldbachs-comet.basic @@ -0,0 +1,30 @@ +#arraybase 1 +print "The first 100 G numbers are:" + +col = 1 +for n = 4 to 202 step 2 + print rjust(string(g(n)), 4); + if col mod 10 = 0 then print + col += 1 +next n + +print : print "G(1000000) = "; g(1000000) +end + +function isPrime(v) + if v <= 1 then return False + for i = 2 to int(sqrt(v)) + if v mod i = 0 then return False + next i + return True +end function + +function g(n) + cont = 0 + if n mod 2 = 0 then + for i = 2 to (1/2) * n + if isPrime(i) = 1 and isPrime(n - i) = 1 then cont += 1 + next i + end if + g = cont +end function diff --git a/Task/Goldbachs-comet/Java/goldbachs-comet.java b/Task/Goldbachs-comet/Java/goldbachs-comet.java new file mode 100644 index 0000000000..7826587d18 --- /dev/null +++ b/Task/Goldbachs-comet/Java/goldbachs-comet.java @@ -0,0 +1,76 @@ +import java.awt.Color; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.List; + +import javax.imageio.ImageIO; + +public final class GoldbachsComet { + + public static void main(String[] aArgs) { + initialisePrimes(2_000_000); + + System.out.println("The first 100 Goldbach numbers:"); + for ( int n = 2; n < 102; n++ ) { + System.out.print(String.format("%3d%s", goldbachFunction(2 * n), ( n % 10 == 1 ? "\n" : "" ))); + } + + System.out.println(); + System.out.println("The 1,000,000th Goldbach number = " + goldbachFunction(1_000_000)); + + createImage(); + } + + private static void createImage() { + final int width = 1040; + final int height = 860; + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics graphics = image.getGraphics(); + graphics.setColor(Color.WHITE); + graphics.fillRect(0, 0, width, height); + + List colours = List.of( Color.BLUE, Color.GREEN, Color.RED ); + for ( int n = 2; n < 2002; n++ ) { + graphics.setColor(colours.get(n % 3)); + graphics.fillOval(n / 2, height - 5 * goldbachFunction(2 * n), 10, 10); + } + + try { + ImageIO.write(image, "png", new File("GoldbachsCometJava.png")); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + + private static int goldbachFunction(int aNumber) { + if ( aNumber <= 2 || aNumber % 2 == 1 ) { + throw new AssertionError("Argument must be even and greater than 2: " + aNumber); + } + + int result = 0; + for ( int i = 1; i <= aNumber / 2; i++ ) { + if ( primes[i] && primes[aNumber - i] ) { + result += 1; + } + } + return result; + } + + private static void initialisePrimes(int aLimit) { + primes = new boolean[aLimit]; + for ( int i = 2; i < aLimit; i++ ) { + primes[i] = true; + } + + for ( int n = 2; n < Math.sqrt(aLimit); n++ ) { + for ( int k = n * n; k < aLimit; k += n ) { + primes[k] = false; + } + } + } + + private static boolean[] primes; + +} diff --git a/Task/Gotchas/Java/gotchas.java b/Task/Gotchas/Java/gotchas.java new file mode 100644 index 0000000000..d4b3c4f951 --- /dev/null +++ b/Task/Gotchas/Java/gotchas.java @@ -0,0 +1,47 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public final class Gotchas { + + public static void main(String[] aArgs) { + // Gotcha 1: An integer argument to a Collection, such as a List, sets the capacity of the Collection, + // but does not fill the Collection with elements. + List numbers = new ArrayList(100); + // The above list has the capacity to hold 100 elements, but is currently empty. + + // Setting the element with index 3 to a value of 42 will create a runtime exception, + // because the list has length 0, and this element does not yet exist. + numbers.set(3, 42); + // The gotcha is only revealed when a runtime exception is thrown. + System.out.println(numbers); + // java.lang.IndexOutOfBoundsException: Index 3 out of bounds for length 0 + + // Gotcha 2: Copying a Collection in a simple manner works, + // but means that changes to the original Collection are reflected in the copy, + // which is not normally the desired outcome. + Set letters = new HashSet(); + letters.add("a"); letters.add("b"); letters.add("c"); + + // Create a copy of the set. + Set copy = letters; + // The two sets are identical. + System.out.println(letters + " :: " + copy); + + // Add an element to the set 'letters'. + letters.add("d"); + // The same letter has been added to the set 'copy'. + // Both sets now contain the same 4 letters. + System.out.println(letters + " :: " + copy); + // In a program this can cause mysterious results which can be difficult to debug. + + // The correct way to copy a Collection is to use a copy constructor as shown below. + Set correctCopy = new HashSet(letters); + letters.add("e"); + + // The set 'correctCopy' only contains its original 4 letters. + System.out.println(letters + " :: " + correctCopy); + } + +} diff --git a/Task/Greatest-common-divisor/FutureBasic/greatest-common-divisor.basic b/Task/Greatest-common-divisor/FutureBasic/greatest-common-divisor.basic index 8b50cf0c2e..7bc6a13114 100644 --- a/Task/Greatest-common-divisor/FutureBasic/greatest-common-divisor.basic +++ b/Task/Greatest-common-divisor/FutureBasic/greatest-common-divisor.basic @@ -1,15 +1,56 @@ -window 1, @"Greatest Common Divisor", (0,0,480,270) +begin enum 1 // Object tags + _fldA + _ansA + _fldB + _ansB + _rand +end enum -local fn gcd( a as short, b as short ) as short - short result +void local fn BuildMacInterface //15-line GUI + window 1, @"Greatest Common Divisor", ( 0, 0, 380, 130 ), NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + textfield _fldA,,, ( 20, 89, 156, 21 ) + ControlSetAlignment( _fldA, NSTextAlignmentRight ) + ControlSetFormat( _fldA, @"0123456789", Yes, 18, 0 ) + textfield _fldB,,, ( 20, 57, 156, 24 ) + ControlSetAlignment( _fldB, NSTextAlignmentRight ) + ControlSetFormat( _fldB, @"0123456789", Yes, 18, 0 ) + textlabel _ansA, @"= ", ( 182, 91, 185, 16 ) + textlabel _ansB, @"= ", ( 182, 62, 185, 16 ) + button _rand,,,@"Random demo", ( 129, 13, 122, 32 ) + menu 1,,, @"File" : menu 1,0,, @"Close", @"w" : MenuItemSetAction(1,0,@"performClose:") + editmenu 2 + WindowMakeFirstResponder( 1, _fldA ) +end fn - if ( b != 0 ) - result = fn gcd( b, a mod b) - else - result = abs(a) - end if -end fn = result +local fn GCD( a as long, b as long ) as long //the requested function + while b + long c = a mod b + a = b : b = c + wend +end fn = a -print fn gcd( 6, 9 ) +void local fn DoDialog( ev as Long, tag as long ) //This makes it interactive + long a, b, c + select ev + case _textFieldDidchange //Find GCD of edit fields' contents + a = fn ControlIntegerValue( _fldA ) + b = fn ControlIntegerValue( _fldB ) + if a + b == 0 then textlabel _ansA, @"=" : textlabel _ansB, @"=" : exit fn + c = fn GCD( a, b ) + textlabel _ansA, fn stringwithformat(@"= %ld x %ld", c, a / c ) + textlabel _ansB, fn stringwithformat(@"= %ld x %ld", c, b / c ) + case _btnclick //Fill edit fields with random content, then process + select tag + case _rand + c = rnd(65536) + textfield _fldA,,str( c * rnd(65536) ) + textfield _fldB,,str( c * rnd(65536) ) + fn DoDialog( _textFieldDidchange, 0 ) + end select + case _windowWillClose : end + end select +end fn -HandleEvents +fn BuildMacInterface +on dialog fn doDialog +handleevents diff --git a/Task/HTTPS-Authenticated/Java/https-authenticated.java b/Task/HTTPS-Authenticated/Java/https-authenticated.java new file mode 100644 index 0000000000..4dcf27cde9 --- /dev/null +++ b/Task/HTTPS-Authenticated/Java/https-authenticated.java @@ -0,0 +1,39 @@ +import java.io.IOException; +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.net.http.HttpResponse.BodyHandlers; + +public final class HTTPSAuthenticated { + + public static void main(String[] aArgs) throws IOException, InterruptedException, URISyntaxException { + HttpClient client = HttpClient.newBuilder() + .authenticator( new MyAuthenticator() ) + .build(); + + HttpRequest request = HttpRequest.newBuilder() + .GET() + .uri( new URI("https://postman-echo.com/basic-auth") ) // This website requires authentication + .build(); + + HttpResponse response = client.send(request, BodyHandlers.ofString()); + + System.out.println("Status: " + response.statusCode()); + } + +} + +final class MyAuthenticator extends Authenticator { + + @Override + protected PasswordAuthentication getPasswordAuthentication() { + String username = "kingkong"; + String password = "test1234"; + return new PasswordAuthentication(username, password.toCharArray()); + } + +} diff --git a/Task/HTTPS-Client-authenticated/Java/https-client-authenticated.java b/Task/HTTPS-Client-authenticated/Java/https-client-authenticated.java new file mode 100644 index 0000000000..34206697ae --- /dev/null +++ b/Task/HTTPS-Client-authenticated/Java/https-client-authenticated.java @@ -0,0 +1,41 @@ +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.net.URI; +import java.net.URL; +import java.security.KeyStore; +import java.util.Scanner; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; + +public final class HTTPSClientAuthenticated { + + public static void main(String[] aArgs) throws Exception { + final String keyStorePath = "the/path/to/keystore"; // The key store contains the client's certificate + final String keyStorePassword = "my-password"; + + SSLContext sslContext = getSSLContext(keyStorePath, keyStorePassword); + URL url = new URI("https://somehost.com").toURL(); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.setSSLSocketFactory(sslContext.getSocketFactory()); + + // Obtain response from the url + BufferedInputStream response = (BufferedInputStream) connection.getInputStream(); + try ( Scanner scanner = new Scanner(response) ) { + String responseBody = scanner.useDelimiter("\\A").next(); + System.out.println(responseBody); + } + } + + private static SSLContext getSSLContext(String aPath, String aPassword) throws Exception { + KeyStore keyStore = KeyStore.getInstance("pkcs12"); + keyStore.load( new FileInputStream(aPath), aPassword.toCharArray()); + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("PKIX"); + keyManagerFactory.init(keyStore, aPassword.toCharArray()); + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(keyManagerFactory.getKeyManagers(), null, null); + return sslContext; + } + +} diff --git a/Task/Hailstone-sequence/AppleScript/hailstone-sequence-2.applescript b/Task/Hailstone-sequence/AppleScript/hailstone-sequence-2.applescript index 2c60a4ef18..5212c2123f 100644 --- a/Task/Hailstone-sequence/AppleScript/hailstone-sequence-2.applescript +++ b/Task/Hailstone-sequence/AppleScript/hailstone-sequence-2.applescript @@ -11,3 +11,4 @@ repeat with n from 2 to 99999 set end of nums to n end if end repeat +return {|number(s) giving longest sequence length|:nums, |length of sequence|:longestLength} diff --git a/Task/Halt-and-catch-fire/Java/halt-and-catch-fire.java b/Task/Halt-and-catch-fire/Java/halt-and-catch-fire.java new file mode 100644 index 0000000000..c0b69d67b3 --- /dev/null +++ b/Task/Halt-and-catch-fire/Java/halt-and-catch-fire.java @@ -0,0 +1,11 @@ +public final class HaltAndCatchFire { + + public static void main(String[] aArgs) { + // Any one of the lines below, when uncommented, will cause a program halt. + +// throw new AssertionError("Stop now!"); +// System.out.println(0/0); +// Runtime.getRuntime().exit(1); + } + +} diff --git a/Task/Hello-world-Text/C3/hello-world-text.c3 b/Task/Hello-world-Text/C3/hello-world-text.c3 index 2337a7a3ff..99cdec3636 100644 --- a/Task/Hello-world-Text/C3/hello-world-text.c3 +++ b/Task/Hello-world-Text/C3/hello-world-text.c3 @@ -1,7 +1,6 @@ import std::io; -fn int main() +fn void main() { - io::println("Hello, World!"); - return 0; + io::printn("Hello, World!"); } diff --git a/Task/Hex-words/APL/hex-words.apl b/Task/Hex-words/APL/hex-words.apl new file mode 100644 index 0000000000..27a204ccba --- /dev/null +++ b/Task/Hex-words/APL/hex-words.apl @@ -0,0 +1,20 @@ +∇HexWords;todec;digroot;displayrow;words;distinct4 +todec←16⊥9+'abcdef'∘⍳ +digroot←(+/10⊥⍣¯1⊢)⍣(10≥⊢) +displayrow←{⍵ n (digroot⊢n←todec ⍵)} + +words←((~∊)∘⎕TC⊆⊢)⊃⎕NGET'unixdict.txt' +words←(words∧.∊¨⊂⊂'abcdef')/words +words←(4≤≢¨words)/words +words←words[⍋digroot∘todec¨words] + +distinct4←(4≤≢∘∪¨words)/words +distinct4←distinct4[⍒todec¨distinct4] + +⎕←(⍕≢words),' hex words with at least 4 letters in unixdict.txt:' +⎕←↑displayrow¨words +⎕←'' + +⎕←(⍕≢distinct4),' hex words with at least 4 distinct letters:' +⎕←↑displayrow¨distinct4 +∇ diff --git a/Task/Hex-words/C++/hex-words.cpp b/Task/Hex-words/C++/hex-words.cpp new file mode 100644 index 0000000000..d978e6f2a1 --- /dev/null +++ b/Task/Hex-words/C++/hex-words.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +struct Item { + std::string word; + int32_t number; + int32_t digital_root; +}; + +void display(const std::vector& items) { + std::cout << " Word Decimal value Digital root" << std::endl; + std::cout << "----------------------------------------" << std::endl; + for ( const Item& item : items ) { + std::cout << std::setw(7) << item.word << std::setw(15) << item.number + << std::setw(12) << item.digital_root << std::endl; + } + std::cout << "\n" << "Total count: " << items.size() << "\n" << std::endl; +} + +int32_t digital_root(int32_t number) { + int32_t result = 0; + while ( number > 0 ) { + result += number % 10; + number /= 10; + } + return ( result <= 9 ) ? result : digital_root(result); +} + +bool contains_only(const std::string& word, const std::unordered_set& acceptable) { + return std::all_of(word.begin(), word.end(), + [acceptable](char ch) { return acceptable.find(ch) != acceptable.end(); }); +} + +int main() { + const std::unordered_set hex_digits{ 'a', 'b', 'c', 'd', 'e', 'f' }; + std::vector items; + + std::fstream file_stream; + file_stream.open("unixdict.txt"); + std::string word; + while ( file_stream >> word ) { + if ( word.length() >= 4 && contains_only(word, hex_digits)) { + const int32_t value = std::stoi(word, 0, 16); + int32_t root = digital_root(value); + items.push_back(Item(word, value, root)); + } + } + + auto compare = [](Item a, Item b) { + return ( a.digital_root == b.digital_root ) ? a.word < b.word : a.digital_root < b.digital_root; + }; + std::sort(items.begin(), items.end(), compare); + display(items); + + std::vector filtered_items; + for ( const Item& item : items ) { + if ( std::unordered_set(item.word.begin(), item.word.end()).size() >= 4 ) { + filtered_items.push_back(item); + } + } + + auto comp = [](Item a, Item b) { return a.number > b.number; }; + std::sort(filtered_items.begin(), filtered_items.end(), comp); + display(filtered_items); +} diff --git a/Task/Hex-words/Java/hex-words.java b/Task/Hex-words/Java/hex-words.java new file mode 100644 index 0000000000..4b60295ec1 --- /dev/null +++ b/Task/Hex-words/Java/hex-words.java @@ -0,0 +1,62 @@ +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public final class HexWords { + + public static void main(String[] aArgs) throws IOException { + Set hexDigits = Set.of( 'a', 'b', 'c', 'd', 'e', 'f' ); + + List items = Files.lines(Path.of("unixdict.txt")) + .filter( word -> word.length() >= 4 ) + .filter( word -> word.chars().allMatch( ch -> hexDigits.contains((char) ch) ) ) + .map( word -> { final int value = Integer.parseInt(word, 16); + return new Item(word, value, digitalRoot(value)); + } ) + .collect(Collectors.toList()); + + Collections.sort(items, Comparator.comparing(Item::getDigitalRoot).thenComparing(Item::getWord)); + display(items); + + List filteredItems = items.stream() + .filter( item -> item.aWord.chars().mapToObj( ch -> (char) ch ).collect(Collectors.toSet()).size() >= 4 ) + .collect(Collectors.toList()); + + Collections.sort(filteredItems, Comparator.comparing(Item::getNumber).reversed()); + display(filteredItems); + } + + private static int digitalRoot(int aNumber) { + int result = 0; + while ( aNumber > 0 ) { + result += aNumber % 10; + aNumber /= 10; + } + return ( result <= 9 ) ? result : digitalRoot(result); + } + + private static void display(List aItems) { + System.out.println(" Word Decimal value Digital root"); + System.out.println("----------------------------------------"); + for ( Item item : aItems ) { + System.out.println(String.format("%7s%15d%12d", item.aWord, item.aNumber, item.aDigitalRoot)); + } + System.out.println(System.lineSeparator() + "Total count: " + aItems.size() + System.lineSeparator()); + } + + private static record Item(String aWord, int aNumber, int aDigitalRoot) { + + public String getWord() { return aWord; } + + public int getNumber() { return aNumber; } + + public int getDigitalRoot() { return aDigitalRoot; } + + } + +} diff --git a/Task/Hex-words/Lua/hex-words.lua b/Task/Hex-words/Lua/hex-words.lua new file mode 100644 index 0000000000..754e81bca9 --- /dev/null +++ b/Task/Hex-words/Lua/hex-words.lua @@ -0,0 +1,89 @@ +-- Import http namespace from socket library +http = require("socket.http") + +-- Download the page at url and return as string +function getFromWeb (url) + local body, statusCode, headers, statusText = http.request(url) + if statusCode == 200 then + return body + else + error(statusText) + end +end + +-- Return a boolean to show whether word is a hexword +function isHexWord (word) + local hexLetters, ch = "abcdef" + for pos = 1, #word do + ch = word:sub(pos, pos) + if not string.find(hexLetters, ch) then return false end + end + return true +end + +-- Return the sum of the digits in num +function sumDigits (num) + local sum, nStr, digit = 0, tostring(num) + for pos = 1, #nStr do + digit = tonumber(nStr:sub(pos, pos)) + sum = sum + digit + end + return sum +end + +-- Return the digital root of x +function digitalRoot (x) + while x > 9 do + x = sumDigits(x) + end + return x +end + +-- Return a table from built from the lines of the string dct +-- Each table entry contains the digital root, word and base 10 conversion +function buildTable (dct) + local t, base10 = {} + for line in dct:gmatch("[^\n]+") do + if # line > 3 and isHexWord(line) then + base10 = (tonumber(line, 16)) + table.insert(t, {digitalRoot(base10), line, base10}) + end + end + table.sort(t, function (a,b) return a[1] < b[1] end) + return t +end + +-- Return a boolean to show whether str has at least 4 distinct characters +function fourDistinct (str) + local distinct, ch = "" + for pos = 1, #str do + ch = str:sub(pos, pos) + if not string.match(distinct, ch) then + distinct = distinct .. ch + end + end + return #distinct > 3 +end + +-- Unpack each entry in t and print to the screen +function showTable (t) + print("\n\nRoot\tWord\tBase 10") + print("====\t====\t=======") + for i, v in ipairs(t) do + print(unpack(v)) + end + print("\nTable length: " .. #t) +end + +-- Main procedure +local dict = getFromWeb("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") +local hexWords = buildTable(dict) +showTable(hexWords) +local hexWords2 = {} +for k, v in pairs(hexWords) do + if fourDistinct(v[2]) then + table.insert(hexWords2, v) + end +end +table.sort(hexWords2, function (a, b) return a[3] > b[3] end) +showTable(hexWords2) diff --git a/Task/History-variables/C++/history-variables.cpp b/Task/History-variables/C++/history-variables.cpp new file mode 100644 index 0000000000..1cb38271cd --- /dev/null +++ b/Task/History-variables/C++/history-variables.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +template +class with_history { +public: + with_history(const T& element) { + history.push_front(element); + } + + T get() { + return history.front(); + } + + void set(const T& element) { + history.push_front(element); + } + + std::deque get_history() { + return std::deque(history); + } + + T rollback() { + if ( history.size() > 1 ) { + history.pop_front(); + } + return history.front(); + } + +private: + std::deque history; +}; + +int main() { + with_history number(1.2345); + std::cout << "Current value of number: " << number.get() << std::endl; + + number.set(3.4567); + number.set(5.6789); + + std::cout << "Historical values of number: "; + for ( const double& value : number.get_history() ) { + std::cout << value << " "; + } + std::cout << std::endl << std::endl; + + with_history word("Goodbye"); + word.set("Farewell"); + word.set("Hello"); + + std::cout << word.get() << std::endl; + word.rollback(); + std::cout << word.get() << std::endl; + word.rollback(); + std::cout << word.get() << std::endl; + word.rollback(); + std::cout << word.get() << std::endl; + word.rollback(); +} diff --git a/Task/Hofstadter-Q-sequence/Lua/hofstadter-q-sequence.lua b/Task/Hofstadter-Q-sequence/Lua/hofstadter-q-sequence.lua new file mode 100644 index 0000000000..1e5530d33e --- /dev/null +++ b/Task/Hofstadter-Q-sequence/Lua/hofstadter-q-sequence.lua @@ -0,0 +1,28 @@ +function hofstadter (limit) + local Q = {1, 1} + for n = 3, limit do + Q[n] = Q[n - Q[n - 1]] + Q[n - Q[n - 2]] + end + return Q +end + +function countDescents (t) + local count = 0 + for i = 2, #t do + if t[i] < t[i - 1] then + count = count + 1 + end + end + return count +end + +local noError, hofSeq = pcall(hofstadter, 1e5) +if noError == false then + print("The sequence could not be calculated up to the specified limit.") + os.exit() +end +for i = 1, 10 do + io.write(hofSeq[i] .. " ") +end +print("\n" .. hofSeq[1000]) +print(countDescents(hofSeq)) diff --git a/Task/Holidays-related-to-Easter/C++/holidays-related-to-easter.cpp b/Task/Holidays-related-to-Easter/C++/holidays-related-to-easter.cpp new file mode 100644 index 0000000000..c8d9222004 --- /dev/null +++ b/Task/Holidays-related-to-Easter/C++/holidays-related-to-easter.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +std::chrono::year_month_day date_of_easter(const int32_t& year) { + const int32_t a = year % 19; + const int32_t b = year / 100; + const int32_t c = year % 100; + const int32_t d = b / 4; + const int32_t e = b % 4; + const int32_t f = ( b + 8 ) / 25; + const int32_t g = ( b - f + 1 ) / 3; + const int32_t h = ( 19 * a + b - d - g + 15 ) % 30; + const int32_t i = c / 4; + const int32_t k = c % 4; + const int32_t l = ( 32 + 2 * e + 2 * i - h - k ) % 7; + const int32_t m = ( a + 11 * h + 22 * l ) / 451; + const int32_t n = h + l - 7 * m + 114; + const unsigned int month = n / 31; + const unsigned int day = ( n % 31 ) + 1; + + return { std::chrono::year{year}, std::chrono::month{month}, std::chrono::day{day} }; +} + +void display(const int32_t& year, const std::vector& holiday_offsets) { + std::chrono::year_month_day easter = date_of_easter(year); + + std::cout << std::setw(4) << year; + for ( const int32_t& holiday_offset : holiday_offsets ) { + std::chrono::year_month_day date = std::chrono::sys_days(easter) + std::chrono::days{holiday_offset}; + std::cout << std::setw(7) << date.day() << std::setw(4) << date.month(); + } + std::cout << std::endl; +} + +int main() { + const std::vector holiday_offsets{ 0, 39, 49, 56, 60 }; + + std::cout << "Year Easter Ascension Pentecost Trinity Corpus Christi" << std::endl; + std::cout << " CE Sunday Thursday Sunday Sunday Thursday " << std::endl; + std::cout << "---- ------ --------- --------- ------- --------------" << std::endl; + for ( int32_t year = 400; year <= 2100; year += 100 ) { + display(year, holiday_offsets); + } + std::cout << std::endl; + + for ( int32_t year= 2010; year <= 2020; ++year ) { + display(year, holiday_offsets); + } +} diff --git a/Task/Home-primes/Java/home-primes.java b/Task/Home-primes/Java/home-primes.java new file mode 100644 index 0000000000..3333b65769 --- /dev/null +++ b/Task/Home-primes/Java/home-primes.java @@ -0,0 +1,117 @@ +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public final class HomePrimes { + + public static void main(String[] aArgs) { + listPrimes(PRIME_LIMIT); + + List values = List.of( 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 65 ); + for ( int value : values ) { + BigInteger number = BigInteger.valueOf(value); + List previousNumbers = Stream.of( number ).collect(Collectors.toList()); + boolean searching = true; + while ( searching ) { + number = concatenate(primeFactors(number)); + previousNumbers.add(number); + if ( number.isProbablePrime(CERTAINTY_LEVEL) ) { + final int lastIndex = previousNumbers.size() - 1; + for ( int k = lastIndex; k >= 1; k-- ) { + System.out.print("HP" + previousNumbers.get(lastIndex - k) + "(" + k + ") = "); + } + System.out.println(previousNumbers.get(lastIndex)); + searching = false; + } + } + } + } + + private static List primeFactors(BigInteger aNumber) { + List result = new ArrayList(); + + if ( aNumber.compareTo(BigInteger.valueOf(PRIME_LIMIT * PRIME_LIMIT)) <= 0 ) { + return smallPrimeFactors(aNumber); + } + + if ( aNumber.isProbablePrime(CERTAINTY_LEVEL) ) { + result.add(aNumber); + return result; + } + + BigInteger divisor = pollardRho(aNumber); + result.addAll(primeFactors(divisor)); + aNumber = aNumber.divide(divisor); + result.addAll(primeFactors(aNumber)); + Collections.sort(result); + return result; + } + + private static List smallPrimeFactors(BigInteger aNumber) { + int number = aNumber.intValueExact(); + List result = new ArrayList(); + + for ( int i = 0; i < primes.size() && number > 1; i++ ) { + while ( number % primes.get(i) == 0 ) { + result.add(BigInteger.valueOf(primes.get(i))); + number /= primes.get(i); + } + } + + if ( number > 1 ) { + result.add(BigInteger.valueOf(number)); + } + return result; + } + + private static BigInteger pollardRho(BigInteger aNumber) { + if ( ! aNumber.testBit(0) ) { + return BigInteger.TWO; + } + + final BigInteger constant = new BigInteger(aNumber.bitLength(), RANDOM); + BigInteger x = new BigInteger(aNumber.bitLength(), RANDOM); + BigInteger y = x; + BigInteger divisor = null; + + do { + x = x.multiply(x).add(constant).mod(aNumber); + y = y.multiply(y).add(constant).mod(aNumber); + y = y.multiply(y).add(constant).mod(aNumber); + divisor = x.subtract(y).gcd(aNumber); + } while ( divisor.compareTo(BigInteger.ONE) == 0 ); + return divisor; + } + + private static BigInteger concatenate(List aList) { + String number = aList.stream().map(String::valueOf).collect(Collectors.joining()); + return new BigInteger(number); + } + + public static void listPrimes(int aNumber) { + BitSet sieve = new BitSet(aNumber + 1); + sieve.set(2, aNumber + 1); + for ( int i = 2; i <= Math.sqrt(aNumber); i = sieve.nextSetBit(i + 1) ) { + for ( int j = i * i; j <= aNumber; j = j + i ) { + sieve.clear(j); + } + } + + primes = new ArrayList(sieve.cardinality()); + for ( int i = 2; i >= 0; i = sieve.nextSetBit(i + 1) ) { + primes.add(i); + } + } + + private static List primes; + + private static final int CERTAINTY_LEVEL = 20; + private static final int PRIME_LIMIT = 10_000; + private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current(); + +} diff --git a/Task/Home-primes/Rust/home-primes.rust b/Task/Home-primes/Rust/home-primes.rust new file mode 100644 index 0000000000..8471dbe040 --- /dev/null +++ b/Task/Home-primes/Rust/home-primes.rust @@ -0,0 +1,57 @@ +use std::str::FromStr; +use num_bigint::BigUint; +use num_prime::nt_funcs::{is_prime, factorize}; + +fn homechains(n: &BigUint) -> Vec { + let mut links = vec![BigUint::from_str("0").unwrap(); 0].to_vec(); + if is_prime(n, None).probably() { + links.push(n.clone()); + return links; + } + let mut s = String::from_str("").unwrap(); + let d = factorize(n.clone()); + for (p, e) in d { + let s2 = format!("{p}"); + for _ in 0..e { + s.push_str(&s2); + } + } + let k = BigUint::from_str(&s).unwrap(); + links.push(k.clone()); + links.append(&mut homechains(&k)); + return links; +} + +fn home_chains_print(num: u64, chains: &mut Vec) { + let mut clen = chains.len(); + if clen == 1 { + println!("HP{num} ─► {num}"); + } else { + if chains[clen - 1] == chains[clen - 2] { + chains.pop(); + clen -= 1; + } + print!("HP{num}({clen}) ─► "); + for (i, k) in chains.iter().enumerate() { + if clen - i > 1 { + print!("HP{k}({}) ─► ", clen - i - 1); + if (i + 1) % 5 == 0 { + println!(); + } + } else { + println!("{k}"); + } + } + } +} + + +fn main() { + for num in 2_u64..21 { + let m = BigUint::from_str(&format!("{num}")).unwrap(); + let mut chains = homechains(&m); + home_chains_print(num, &mut chains); + } + let mut chains = homechains(&BigUint::from_str("65").unwrap()); + home_chains_print(65_u64, &mut chains); +} diff --git a/Task/Huffman-coding/Zig/huffman-coding.zig b/Task/Huffman-coding/Zig/huffman-coding.zig new file mode 100644 index 0000000000..f02cfea97f --- /dev/null +++ b/Task/Huffman-coding/Zig/huffman-coding.zig @@ -0,0 +1,135 @@ +const std = @import("std"); + +const Node = struct { + frequency: usize, + kind: union(enum) { + internal: struct { + left: *Node, + right: *Node, + }, + leaf: u8, + }, + + fn initLeaf(frequency: usize, ch: u8) Node { + return .{ + .frequency = frequency, + .kind = .{ .leaf = ch }, + }; + } + + fn initInternal( + allocator: std.mem.Allocator, + left_child: Node, + right_child: Node, + ) !Node { + const left = try allocator.create(Node); + const right = try allocator.create(Node); + left.* = left_child; + right.* = right_child; + return .{ + .frequency = left_child.frequency + right_child.frequency, + .kind = .{ .internal = .{ .left = left, .right = right } }, + }; + } + + fn deinit(self: Node, allocator: std.mem.Allocator) void { + switch (self.kind) { + .internal => |inner| { + inner.left.deinit(allocator); + inner.right.deinit(allocator); + allocator.destroy(inner.left); + allocator.destroy(inner.right); + }, + .leaf => {}, + } + } + + fn compare(context: void, a: Node, b: Node) std.math.Order { + _ = context; + return std.math.order(a.frequency, b.frequency); + } +}; + +pub fn main() !void { + const text = "this is an example for huffman encoding"; + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer std.debug.assert(gpa.deinit() == .ok); + + const allocator = gpa.allocator(); + var frequencies = std.AutoHashMap(u8, usize).init(allocator); + defer frequencies.deinit(); + + for (text) |ch| { + const gop = try frequencies.getOrPut(ch); + if (gop.found_existing) { + gop.value_ptr.* += 1; + } else { + gop.value_ptr.* = 1; + } + } + + var prioritized_frequencies = + std.PriorityQueue(Node, void, Node.compare).init(allocator, {}); + defer prioritized_frequencies.deinit(); + + var freq_it = frequencies.iterator(); + while (freq_it.next()) |counted_char| { + try prioritized_frequencies.add(Node.initLeaf( + counted_char.value_ptr.*, + counted_char.key_ptr.*, + )); + } + + while (prioritized_frequencies.len > 1) { + try prioritized_frequencies.add(try Node.initInternal( + allocator, + prioritized_frequencies.remove(), + prioritized_frequencies.remove(), + )); + } + + const root = prioritized_frequencies.items[0]; + defer root.deinit(allocator); + + var codes = std.AutoArrayHashMap(u8, []const u8).init(allocator); + defer codes.deinit(); + + var arena = std.heap.ArenaAllocator.init(allocator); + defer arena.deinit(); + + try generateCodes(arena.allocator(), &root, &.{}, &codes); + + const stdout = std.io.getStdOut().writer(); + var code_it = codes.iterator(); + while (code_it.next()) |item| { + try stdout.print("{c}: {s}\n", .{ + item.key_ptr.*, + item.value_ptr.*, + }); + } +} + +fn generateCodes( + arena: std.mem.Allocator, + node: *const Node, + prefix: []const u8, + out_codes: *std.AutoArrayHashMap(u8, []const u8), +) !void { + switch (node.kind) { + .internal => |inner| { + const left_prefix = try arena.alloc(u8, prefix.len + 1); + std.mem.copy(u8, left_prefix, prefix); + left_prefix[prefix.len] = '0'; + try generateCodes(arena, inner.left, left_prefix, out_codes); + + const right_prefix = try arena.alloc(u8, prefix.len + 1); + std.mem.copy(u8, right_prefix, prefix); + right_prefix[prefix.len] = '1'; + try generateCodes(arena, inner.right, right_prefix, out_codes); + }, + .leaf => |ch| { + try out_codes.put(ch, prefix); + }, + } +} diff --git a/Task/Inheritance-Single/Python/inheritance-single-2.py b/Task/Inheritance-Single/Python/inheritance-single-2.py index 159dc7e558..ed7048d373 100644 --- a/Task/Inheritance-Single/Python/inheritance-single-2.py +++ b/Task/Inheritance-Single/Python/inheritance-single-2.py @@ -44,4 +44,4 @@ felix.kill().kill().kill() mr_winkle = Dog() buddy = Labrador() buddy.kill() -print "Felix has",felix.lives, "lives, ","Buddy is %salive!"%("" if buddy.alive else "not ") +print(f"Felix has {felix.lives} lives, Buddy is {'not' if buddy.alive else 'not'} alive!") diff --git a/Task/Interactive-programming-repl-/Java/interactive-programming-repl-.java b/Task/Interactive-programming-repl-/Java/interactive-programming-repl--1.java similarity index 100% rename from Task/Interactive-programming-repl-/Java/interactive-programming-repl-.java rename to Task/Interactive-programming-repl-/Java/interactive-programming-repl--1.java diff --git a/Task/Interactive-programming-repl-/Java/interactive-programming-repl--2.java b/Task/Interactive-programming-repl-/Java/interactive-programming-repl--2.java new file mode 100644 index 0000000000..0daec2a5f9 --- /dev/null +++ b/Task/Interactive-programming-repl-/Java/interactive-programming-repl--2.java @@ -0,0 +1,14 @@ +Java has an interactive REPL (Read-Evaluate-Print-Loop) console, jshell, that is included with the JDK. +The REPL is started by invoking: $JAVA_HOME/bin/jshell +Here is a sample session to accomplish the task. + + | Welcome to JShell -- Version 20 + | For an introduction type: /help + + jshell> String concat(String a, String b, String c) { return a + c + c + b; } + | created method concat(String, String, String) + + jshell> concat("Rosetta", "Code", ":") + $2 ==> "Rosetta::Code" + + jshell> diff --git a/Task/Isograms-and-heterograms/AppleScript/isograms-and-heterograms-4.applescript b/Task/Isograms-and-heterograms/AppleScript/isograms-and-heterograms-4.applescript new file mode 100644 index 0000000000..04078282e5 --- /dev/null +++ b/Task/Isograms-and-heterograms/AppleScript/isograms-and-heterograms-4.applescript @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include + +struct Isogram_pair { + std::string word; + int32_t value; +}; + +std::string to_lower_case(const std::string& text) { + std::string result = text; + std::transform(result.begin(), result.end(), result.begin(), + [](char ch){ return std::tolower(ch); }); + return result; +} + +int32_t isogram_value(const std::string& word) { + std::unordered_map char_counts; + for ( const char& ch : word ) { + if ( char_counts.find(ch) == char_counts.end() ) { + char_counts.emplace(ch, 1); + } else { + char_counts[ch]++; + } + } + + const int32_t count = char_counts[word[0]]; + const bool identical = std::all_of(char_counts.begin(), char_counts.end(), + [count](const std::pair pair){ return pair.second == count; }); + + return identical ? count : 0; +} + +int main() { + auto compare = [](Isogram_pair a, Isogram_pair b) { + return ( a.value == b.value ) ? + ( ( a.word.length() == b.word.length() ) ? a.word < b.word : a.word.length() > b.word.length() ) + : a.value > b.value; + }; + std::set isograms; + + std::fstream file_stream; + file_stream.open("../unixdict.txt"); + std::string word; + while ( file_stream >> word ) { + const int32_t value = isogram_value(to_lower_case(word)); + if ( value > 1 || ( word.length() > 10 && value == 1 ) ) { + isograms.insert(Isogram_pair(word, value)); + } + } + + std::cout << "n-isograms with n > 1:" << std::endl; + for ( const Isogram_pair& isogram_pair : isograms ) { + if ( isogram_pair.value > 1 ) { + std::cout << isogram_pair.word << std::endl; + } + } + + std::cout << "\n" << "Heterograms with more than 10 letters:" << std::endl; + for ( const Isogram_pair& isogram_pair : isograms ) { + if ( isogram_pair.value == 1 ) { + std::cout << isogram_pair.word << std::endl; + } + } +} diff --git a/Task/Jordan-P-lya-numbers/C++/jordan-p-lya-numbers.cpp b/Task/Jordan-P-lya-numbers/C++/jordan-p-lya-numbers.cpp new file mode 100644 index 0000000000..03f0f373d3 --- /dev/null +++ b/Task/Jordan-P-lya-numbers/C++/jordan-p-lya-numbers.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr int64_t LIMIT = pow(2, 53); + +std::set jordan_polya_set; +std::unordered_map> decompositions; + +std::string toString(const std::map& a_map) { + std::string result; + for ( const auto& [key, value] : a_map ) { + result = std::to_string(key) + "!" + ( value == 1 ? "" : "^" + std::to_string(value) ) + " * " + result; + } + return result.substr(0, result.length() - 3); +} + +std::vector set_to_vector(const std::set& a_set) { + std::vector result; + result.reserve(a_set.size()); + + for ( const int64_t& element : a_set ) { + result.emplace_back(element); + } + return result; +} + +void insert_or_update(std::map& map, const int32_t& entry) { + if ( map.find(entry) == map.end() ) { + map.emplace(entry, 1); + } else { + map[entry]++; + } +} + +void create_jordan_polya() { + jordan_polya_set.emplace(1); + decompositions[1] = std::map(); + int64_t factorial = 1; + + for ( int32_t multiplier = 2; multiplier <= 20; ++multiplier ) { + factorial *= multiplier; + for ( int64_t number : jordan_polya_set ) { + while ( number <= LIMIT / factorial ) { + int64_t original = number; + number *= factorial; + jordan_polya_set.emplace(number); + decompositions[number] = decompositions[original]; + insert_or_update(decompositions[number], multiplier); + } + } + } +} + +int main() { + create_jordan_polya(); + + std::vector jordan_polya = set_to_vector(jordan_polya_set); + + std::cout << "The first 50 Jordan-Polya numbers:" << std::endl; + for ( int64_t i = 0; i < 50; ++i ) { + std::cout << std::setw(5) << jordan_polya[i] << ( i % 10 == 9 ? "\n" : "" ); + } + + const std::vector::iterator hundred_million = + std::lower_bound(jordan_polya.begin(), jordan_polya.end(), 100'000'000); + std::cout << "\n" << "The largest Jordan-Polya number less than 100 million: " + << jordan_polya[(hundred_million - jordan_polya.begin() - 1)] << std::endl << std::endl; + + for ( int32_t i : { 800, 1050, 1800, 2800, 3800 } ) { + std::cout << "The " << i << "th Jordan-Polya number is: " << jordan_polya[i - 1] + << " = " << toString(decompositions[jordan_polya[i - 1]]) << std::endl; + } +} diff --git a/Task/Jordan-P-lya-numbers/Java/jordan-p-lya-numbers.java b/Task/Jordan-P-lya-numbers/Java/jordan-p-lya-numbers.java new file mode 100644 index 0000000000..fd37ad195d --- /dev/null +++ b/Task/Jordan-P-lya-numbers/Java/jordan-p-lya-numbers.java @@ -0,0 +1,67 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +public final class JordanPolyaNumbers { + + public static void main(String[] aArgs) { + createJordanPolya(); + + final long belowHundredMillion = jordanPolyaSet.floor(100_000_000L); + List jordanPolya = new ArrayList(jordanPolyaSet); + + System.out.println("The first 50 Jordan-Polya numbers:"); + for ( int i = 0; i < 50; i++ ) { + System.out.print(String.format("%5s%s", jordanPolya.get(i), ( i % 10 == 9 ? "\n" : "" ))); + } + System.out.println(); + + System.out.println("The largest Jordan-Polya number less than 100 million: " + belowHundredMillion); + System.out.println(); + + for ( int i : List.of( 800, 1050, 1800, 2800, 3800 ) ) { + System.out.println("The " + i + "th Jordan-Polya number is: " + jordanPolya.get(i - 1) + + " = " + toString(decompositions.get(jordanPolya.get(i - 1)))); + } + } + + private static void createJordanPolya() { + jordanPolyaSet.add(1L); + Set nextSet = new TreeSet(); + decompositions.put(1L, new TreeMap()); + long factorial = 1; + + for ( int multiplier = 2; multiplier <= 20; multiplier++ ) { + factorial *= multiplier; + for ( Iterator iterator = jordanPolyaSet.iterator(); iterator.hasNext(); ) { + long number = iterator.next(); + while ( number <= Long.MAX_VALUE / factorial ) { + long original = number; + number *= factorial; + nextSet.add(number); + decompositions.put(number, new TreeMap(decompositions.get(original))); + decompositions.get(number).merge(multiplier, 1, Integer::sum); + } + } + jordanPolyaSet.addAll(nextSet); + nextSet.clear(); + } + } + + private static String toString(Map aMap) { + String result = ""; + for ( int key : aMap.keySet() ) { + result = key + "!" + ( aMap.get(key) == 1 ? "" :"^" + aMap.get(key) ) + " * " + result; + } + return result.substring(0, result.length() - 3); + } + + private static TreeSet jordanPolyaSet = new TreeSet(); + private static Map> decompositions = new HashMap>(); + +} diff --git a/Task/Jordan-P-lya-numbers/Jq/jordan-p-lya-numbers.jq b/Task/Jordan-P-lya-numbers/Jq/jordan-p-lya-numbers.jq index 8000c48dba..e615c46f84 100644 --- a/Task/Jordan-P-lya-numbers/Jq/jordan-p-lya-numbers.jq +++ b/Task/Jordan-P-lya-numbers/Jq/jordan-p-lya-numbers.jq @@ -39,12 +39,12 @@ def JordanPolya($lim; $mx): | .mx = ($mx // $lim) | until(.k > .mx or .t > $lim; .t *= .k - | if .t <= $lim + | if .t <= $lim then reduce JordanPolya(($lim/.t)|floor; .t)[] as $rest (.; .v += [.t * $rest] ) | .k += 1 - else . - end) + else . + end) | .v | unique end; @@ -72,7 +72,7 @@ def Decompose($n; $start): .f += [$i] | .m = (.m / .factorial[$i]) | if .m == 1 then .emit = .f else . end) - | if .emit then ., break $out else . end) + | if .emit then ., break $out else . end) | if .emit then .emit elif .i == 2 then Decompose($n; .start-1) else empty diff --git a/Task/Letter-frequency/Insitux/letter-frequency.insitux b/Task/Letter-frequency/Insitux/letter-frequency.insitux new file mode 100644 index 0000000000..bfd48d5907 --- /dev/null +++ b/Task/Letter-frequency/Insitux/letter-frequency.insitux @@ -0,0 +1,8 @@ +(-> (read "README.md") + (filter letter?) + (map upper-case) + freqs + (sort-by 1) + reverse + (map (join " ")) + (join " ")) diff --git a/Task/Long-year/Lua/long-year.lua b/Task/Long-year/Lua/long-year.lua new file mode 100644 index 0000000000..1f66d82140 --- /dev/null +++ b/Task/Long-year/Lua/long-year.lua @@ -0,0 +1,12 @@ +function isLongYear (y) + local function p (y) + local f = math.floor + return (y + f(y/4) - f(y/100) + f(y/400)) % 7 + end + return p(y) == 4 or p(y - 1) == 3 +end + +print("Long years in the 21st century:") +for year = 2001, 2100 do + if isLongYear(year) then io.write(year .. " ") end +end diff --git a/Task/Long-year/S-BASIC/long-year.basic b/Task/Long-year/S-BASIC/long-year.basic index f03c0ac416..4f47a32362 100644 --- a/Task/Long-year/S-BASIC/long-year.basic +++ b/Task/Long-year/S-BASIC/long-year.basic @@ -25,8 +25,8 @@ end = z comment The simplest of several possible tests is that - any calendar year starting or ending on a - Thursday is "long", i.e., has 53 ISO weeks + any ISO year starting or ending on a + Thursday is "long", i.e., spans 53 weeks end function islongyear(yr = integer) = integer var thursday, result = integer diff --git a/Task/Look-and-say-sequence/Applesoft-BASIC/look-and-say-sequence.basic b/Task/Look-and-say-sequence/Applesoft-BASIC/look-and-say-sequence.basic new file mode 100644 index 0000000000..609a6448ea --- /dev/null +++ b/Task/Look-and-say-sequence/Applesoft-BASIC/look-and-say-sequence.basic @@ -0,0 +1,12 @@ +10 I$="1" +20 FOR Z=1 TO 15 +30 PRINT I$ +40 O$="" +50 FOR I=1 TO LEN(I$) +60 C=1 +70 IF MID$(I$,I,1)=MID$(I$,I+C,1) THEN C=C+1: GOTO 70 +80 O$=O$+CHR$(C+48)+MID$(I$,I,1) +90 I=I+C-1 +100 NEXT I +110 I$=O$ +120 NEXT Z diff --git a/Task/Look-and-say-sequence/Chipmunk-Basic/look-and-say-sequence.basic b/Task/Look-and-say-sequence/Chipmunk-Basic/look-and-say-sequence.basic new file mode 100644 index 0000000000..931b192623 --- /dev/null +++ b/Task/Look-and-say-sequence/Chipmunk-Basic/look-and-say-sequence.basic @@ -0,0 +1,23 @@ +100 cls +110 dim x$(2) +120 i = 0 ' índice de cadena de entrada +130 x$(i) = "1" +140 input "Indica cuantas repeticiones: ",r +150 print "Secuencia:" +160 print x$(i) +170 for n = 1 to r-1 +180 j = 1-i ' índice de cadena de salida +190 x$(j) = "" +200 k = 1 +210 while k <= len(x$(i)) +220 k0 = k+1 +230 while ((k0 <= len(x$(i))) and (mid$(x$(i),k,1) = mid$(x$(i),k0,1))) +240 k0 = k0+1 +250 wend +260 x$(j) = x$(j)+str$(k0-k)+mid$(x$(i),k,1) +270 k = k0 +280 wend +290 i = j +300 print x$(j) +310 next n +320 end diff --git a/Task/Look-and-say-sequence/Insitux/look-and-say-sequence.insitux b/Task/Look-and-say-sequence/Insitux/look-and-say-sequence.insitux index 3add58298c..cfea754c4a 100644 --- a/Task/Look-and-say-sequence/Insitux/look-and-say-sequence.insitux +++ b/Task/Look-and-say-sequence/Insitux/look-and-say-sequence.insitux @@ -1,7 +1,7 @@ (function look-and-say n x (return-when (empty? n) x) - (var digit (0 n) - [before after] ((juxt take-while skip-while) (= digit) n)) + (let digit (0 n) + [before after] (part-before (!= digit) n)) (recur after (strn x (len before) digit))) (var result "1") diff --git a/Task/Look-and-say-sequence/True-BASIC/look-and-say-sequence.basic b/Task/Look-and-say-sequence/True-BASIC/look-and-say-sequence.basic new file mode 100644 index 0000000000..49f990e193 --- /dev/null +++ b/Task/Look-and-say-sequence/True-BASIC/look-and-say-sequence.basic @@ -0,0 +1,15 @@ +LET i$ = "1" +FOR z = 1 TO 15 + PRINT i$ + LET o$ = "" + FOR i = 1 TO LEN(i$) + LET c = 1 + DO WHILE (i$)[i:i+1-1] = (i$)[i+c:i+c+1-1] + LET c = c+1 + LOOP + LET o$ = o$ & CHR$(c+48) & (i$)[i:i+1-1] + LET i = i+c-1 + NEXT i + LET i$ = o$ +NEXT z +END diff --git a/Task/Loops-Continue/C3/loops-continue.c3 b/Task/Loops-Continue/C3/loops-continue.c3 new file mode 100644 index 0000000000..5f96e599b7 --- /dev/null +++ b/Task/Loops-Continue/C3/loops-continue.c3 @@ -0,0 +1,10 @@ +for (int i = 1; i <= 10; i++) +{ + io::print(i); + if (i % 5 == 0) + { + io::printn(); + continue; + } + io::print(", "); +} diff --git a/Task/Loops-Do-while/C3/loops-do-while.c3 b/Task/Loops-Do-while/C3/loops-do-while.c3 new file mode 100644 index 0000000000..f6fdf699c2 --- /dev/null +++ b/Task/Loops-Do-while/C3/loops-do-while.c3 @@ -0,0 +1,6 @@ +int val; +do +{ + io::printn(++val); +} +while (val % 6 != 0); diff --git a/Task/Loops-Downward-for/C3/loops-downward-for.c3 b/Task/Loops-Downward-for/C3/loops-downward-for.c3 new file mode 100644 index 0000000000..d8616099d1 --- /dev/null +++ b/Task/Loops-Downward-for/C3/loops-downward-for.c3 @@ -0,0 +1,4 @@ +for (int i = 10; i >= 0; i--) +{ + io::printn(i); +} diff --git a/Task/Loops-Downward-for/N-t-roff/loops-downward-for.ntroff b/Task/Loops-Downward-for/N-t-roff/loops-downward-for.ntroff new file mode 100644 index 0000000000..403e8bfc88 --- /dev/null +++ b/Task/Loops-Downward-for/N-t-roff/loops-downward-for.ntroff @@ -0,0 +1,4 @@ +.nr a 11 1 +.while (\na > 0) \{\ +\n-a +.\} diff --git a/Task/Loops-Downward-for/S-BASIC/loops-downward-for.basic b/Task/Loops-Downward-for/S-BASIC/loops-downward-for.basic index 87204229a0..e86fe8c6d7 100644 --- a/Task/Loops-Downward-for/S-BASIC/loops-downward-for.basic +++ b/Task/Loops-Downward-for/S-BASIC/loops-downward-for.basic @@ -1,4 +1,4 @@ -var i = integer; +var i = integer for i = 10 to 1 step -1 print i; next i diff --git a/Task/Loops-For-with-a-specified-step/C3/loops-for-with-a-specified-step.c3 b/Task/Loops-For-with-a-specified-step/C3/loops-for-with-a-specified-step.c3 new file mode 100644 index 0000000000..a8baea7542 --- /dev/null +++ b/Task/Loops-For-with-a-specified-step/C3/loops-for-with-a-specified-step.c3 @@ -0,0 +1 @@ +for (int i = 1; i < 10; i += 2) io::printfn("%d", i); diff --git a/Task/Loops-For-with-a-specified-step/N-t-roff/loops-for-with-a-specified-step.ntroff b/Task/Loops-For-with-a-specified-step/N-t-roff/loops-for-with-a-specified-step.ntroff new file mode 100644 index 0000000000..ab092fda88 --- /dev/null +++ b/Task/Loops-For-with-a-specified-step/N-t-roff/loops-for-with-a-specified-step.ntroff @@ -0,0 +1,4 @@ +.nr a 0 3 +.while (\na < 19) \{\ +\n+a +.\} diff --git a/Task/Loops-For/C3/loops-for.c3 b/Task/Loops-For/C3/loops-for.c3 new file mode 100644 index 0000000000..aa81e9a066 --- /dev/null +++ b/Task/Loops-For/C3/loops-for.c3 @@ -0,0 +1,5 @@ +for (int i = 0; i < 5; i++) +{ + for (int j = 1; j <= i; j++) io::print("*"); + io::printn("*"); +} diff --git a/Task/Loops-Foreach/C3/loops-foreach.c3 b/Task/Loops-Foreach/C3/loops-foreach.c3 new file mode 100644 index 0000000000..a3a7f9cb90 --- /dev/null +++ b/Task/Loops-Foreach/C3/loops-foreach.c3 @@ -0,0 +1,2 @@ +String[] fruits = { "Apple", "Banana", "Strawberry" }; +foreach (fruit : fruits) io::printn(fruit); diff --git a/Task/Loops-Infinite/C3/loops-infinite-1.c3 b/Task/Loops-Infinite/C3/loops-infinite-1.c3 new file mode 100644 index 0000000000..20f4fe9a6a --- /dev/null +++ b/Task/Loops-Infinite/C3/loops-infinite-1.c3 @@ -0,0 +1 @@ +while(1) io::printn("SPAM"); diff --git a/Task/Loops-Infinite/C3/loops-infinite-2.c3 b/Task/Loops-Infinite/C3/loops-infinite-2.c3 new file mode 100644 index 0000000000..59a1325d5a --- /dev/null +++ b/Task/Loops-Infinite/C3/loops-infinite-2.c3 @@ -0,0 +1 @@ +for(;;) io::printn("SPAM"); diff --git a/Task/Loops-Infinite/C3/loops-infinite-3.c3 b/Task/Loops-Infinite/C3/loops-infinite-3.c3 new file mode 100644 index 0000000000..99c70f3788 --- /dev/null +++ b/Task/Loops-Infinite/C3/loops-infinite-3.c3 @@ -0,0 +1 @@ +do { io::printn("SPAM"); } while(1); diff --git a/Task/Loops-Infinite/C3/loops-infinite-4.c3 b/Task/Loops-Infinite/C3/loops-infinite-4.c3 new file mode 100644 index 0000000000..d36dfb9963 --- /dev/null +++ b/Task/Loops-Infinite/C3/loops-infinite-4.c3 @@ -0,0 +1,6 @@ +switch (1) +{ + case 1: + io::printn("SPAM"); + nextcase 1; +} diff --git a/Task/Loops-While/Bait/loops-while.bait b/Task/Loops-While/Bait/loops-while.bait new file mode 100644 index 0000000000..a818b3772c --- /dev/null +++ b/Task/Loops-While/Bait/loops-while.bait @@ -0,0 +1,7 @@ +fun main() { + mut i := 1024 + for i > 0 { + println(i) + i = i / 2 + } +} diff --git a/Task/Mandelbrot-set/Julia/mandelbrot-set-4.julia b/Task/Mandelbrot-set/Julia/mandelbrot-set-4.julia index 30bf757b41..efe3fe78ef 100644 --- a/Task/Mandelbrot-set/Julia/mandelbrot-set-4.julia +++ b/Task/Mandelbrot-set/Julia/mandelbrot-set-4.julia @@ -29,7 +29,13 @@ heatmap(T .^ 0.1, c=:balance) savefig("Mandelbrot_set_2.png") N = abs.(Z) .> 2 # exterior distance estimation -D[N] = 0.5 .* log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N]) +D[N] = log.(abs.(Z[N])) .* abs.(Z[N]) ./ abs.(dZ[N]) heatmap(D .^ 0.1, c=:balance) savefig("Mandelbrot_set_3.png") + +N, thickness = D .> 0, 0.01 # boundary detection and interpolation +D[N] = max.(1 .- D[N] ./ thickness, 0) + +heatmap(D .^ 2.0, c=:binary) +savefig("Mandelbrot_set_4.png") diff --git a/Task/Mandelbrot-set/Julia/mandelbrot-set-6.julia b/Task/Mandelbrot-set/Julia/mandelbrot-set-6.julia index 1f2373f04e..70cc90c56c 100644 --- a/Task/Mandelbrot-set/Julia/mandelbrot-set-6.julia +++ b/Task/Mandelbrot-set/Julia/mandelbrot-set-6.julia @@ -4,8 +4,8 @@ gr(aspect_ratio=:equal, axis=true, ticks=true, legend=false, dpi=200) d, h = 200, 1200 # pixel density (= image width) and image height n, r = 8000, 10000 # number of iterations and escape radius (r > 2) -a = -.743643887037158704752191506114774 # real coordinate of the zoom center -b = 0.131825904205311970493132056385139 # imaginary coordinate of the center +a = -.743643887037158704752191506114774 # try: a, b, n = -1.748764520194788535, 3e-13, 800 +b = 0.131825904205311970493132056385139 # https://mathr.co.uk/web/m-location-analysis.html x = range(0, 2, length=d+1) y = range(0, 2 * h / d, length=h+1) @@ -31,9 +31,9 @@ X, Y = real(C), imag(C) # zoom images (adjust circle size 50 and zoom level 20 R, c, z = 50 * (2 / d) * pi .* exp.(.- B), min(d, h) + 1, max(0, h - d) ÷ 20 gr(c=:nipy_spectral, axis=true, ticks=true, legend=false, markerstrokewidth=0) -p1 = scatter(X[1z+1:1z+c,1:d], Y[1z+1:1z+c,1:d], markersize=R[1:c].^0.5, marker_z=D[1z+1:1z+c,1:d].^0.5) -p2 = scatter(X[2z+1:2z+c,1:d], Y[2z+1:2z+c,1:d], markersize=R[1:c].^0.5, marker_z=D[2z+1:2z+c,1:d].^0.4) -p3 = scatter(X[3z+1:3z+c,1:d], Y[3z+1:3z+c,1:d], markersize=R[1:c].^0.5, marker_z=D[3z+1:3z+c,1:d].^0.3) -p4 = scatter(X[4z+1:4z+c,1:d], Y[4z+1:4z+c,1:d], markersize=R[1:c].^0.5, marker_z=D[4z+1:4z+c,1:d].^0.2) +p1 = scatter(X[1z+1:1z+c,1:d], Y[1z+1:1z+c,1:d], markersize=R[1:c].^.5, marker_z=D[1z+1:1z+c,1:d].^.5) +p2 = scatter(X[2z+1:2z+c,1:d], Y[2z+1:2z+c,1:d], markersize=R[1:c].^.5, marker_z=D[2z+1:2z+c,1:d].^.4) +p3 = scatter(X[3z+1:3z+c,1:d], Y[3z+1:3z+c,1:d], markersize=R[1:c].^.5, marker_z=D[3z+1:3z+c,1:d].^.3) +p4 = scatter(X[4z+1:4z+c,1:d], Y[4z+1:4z+c,1:d], markersize=R[1:c].^.5, marker_z=D[4z+1:4z+c,1:d].^.2) plot(p1, p2, p3, p4, layout=(2, 2)) savefig("Mercator_Mandelbrot_zoom.png") diff --git a/Task/Mandelbrot-set/MSX-Basic/mandelbrot-set.basic b/Task/Mandelbrot-set/MSX-Basic/mandelbrot-set.basic new file mode 100644 index 0000000000..cb42b88d50 --- /dev/null +++ b/Task/Mandelbrot-set/MSX-Basic/mandelbrot-set.basic @@ -0,0 +1,21 @@ +100 SCREEN 2 +110 CLS +120 x1 = 256 : y1 = 192 +130 i1 = -1 : i2 = 1 +140 r1 = -2 : r2 = 1 +150 s1 = (r2-r1)/x1 : s2 = (i2-i1)/y1 +160 FOR y = 0 TO y1 +170 i3 = i1+s2*y +180 FOR x = 0 TO x1 +190 r3 = r1+s1*x +200 z1 = r3 : z2 = i3 +210 FOR n = 0 TO 30 +220 a = z1*z1 : b = z2*z2 +230 IF a+b > 4 GOTO 270 +240 z2 = 2*z1*z2+i3 +250 z1 = a-b+r3 +260 NEXT n +270 PSET (x,y),n-16*INT(n/16) +280 NEXT x +290 NEXT y +300 GOTO 300 diff --git a/Task/Mandelbrot-set/Python/mandelbrot-set-5.py b/Task/Mandelbrot-set/Python/mandelbrot-set-5.py index f4024408ba..8a36ca94df 100644 --- a/Task/Mandelbrot-set/Python/mandelbrot-set-5.py +++ b/Task/Mandelbrot-set/Python/mandelbrot-set-5.py @@ -32,3 +32,9 @@ D[N] = np.log(abs(Z[N])) * abs(Z[N]) / abs(dZ[N]) plt.imshow(D ** 0.1, cmap=plt.cm.twilight_shifted, origin="lower") plt.savefig("Mandelbrot_set_3.png", dpi=200) + +N, thickness = D > 0, 0.01 # boundary detection and interpolation +D[N] = np.maximum(1 - D[N] / thickness, 0) + +plt.imshow(D ** 2.0, cmap=plt.cm.binary, origin="lower") +plt.savefig("Mandelbrot_set_4.png", dpi=200) diff --git a/Task/Mandelbrot-set/Python/mandelbrot-set-7.py b/Task/Mandelbrot-set/Python/mandelbrot-set-7.py index b471cfbc31..5c47bb5708 100644 --- a/Task/Mandelbrot-set/Python/mandelbrot-set-7.py +++ b/Task/Mandelbrot-set/Python/mandelbrot-set-7.py @@ -4,8 +4,8 @@ import matplotlib.pyplot as plt d, h = 200, 1200 # pixel density (= image width) and image height n, r = 8000, 10000 # number of iterations and escape radius (r > 2) -a = -.743643887037158704752191506114774 # real coordinate of the zoom center -b = 0.131825904205311970493132056385139 # imaginary coordinate of the center +a = -.743643887037158704752191506114774 # try: a, b, n = -1.748764520194788535, 3e-13, 800 +b = 0.131825904205311970493132056385139 # https://mathr.co.uk/web/m-location-analysis.html x = np.linspace(0, 2, num=d+1) y = np.linspace(0, 2 * h / d, num=h+1) @@ -30,8 +30,8 @@ X, Y = C.real, C.imag # zoom images (adjust circle size 100 and zoom level 20 a R, c, z = 100 * (2 / d) * np.pi * np.exp(- B), min(d, h) + 1, max(0, h - d) // 20 fig, ax = plt.subplots(2, 2, figsize=(12, 12)) -ax[0, 0].scatter(X[1*z:1*z+c,0:d], Y[1*z:1*z+c,0:d], s=R[0:c,0:d]**2.0, c=D[1*z:1*z+c,0:d]**0.5, cmap=plt.cm.nipy_spectral) -ax[0, 1].scatter(X[2*z:2*z+c,0:d], Y[2*z:2*z+c,0:d], s=R[0:c,0:d]**2.0, c=D[2*z:2*z+c,0:d]**0.4, cmap=plt.cm.nipy_spectral) -ax[1, 0].scatter(X[3*z:3*z+c,0:d], Y[3*z:3*z+c,0:d], s=R[0:c,0:d]**2.0, c=D[3*z:3*z+c,0:d]**0.3, cmap=plt.cm.nipy_spectral) -ax[1, 1].scatter(X[4*z:4*z+c,0:d], Y[4*z:4*z+c,0:d], s=R[0:c,0:d]**2.0, c=D[4*z:4*z+c,0:d]**0.2, cmap=plt.cm.nipy_spectral) +ax[0,0].scatter(X[1*z:1*z+c,0:d], Y[1*z:1*z+c,0:d], s=R[0:c,0:d]**2, c=D[1*z:1*z+c,0:d]**.5, cmap=plt.cm.nipy_spectral) +ax[0,1].scatter(X[2*z:2*z+c,0:d], Y[2*z:2*z+c,0:d], s=R[0:c,0:d]**2, c=D[2*z:2*z+c,0:d]**.4, cmap=plt.cm.nipy_spectral) +ax[1,0].scatter(X[3*z:3*z+c,0:d], Y[3*z:3*z+c,0:d], s=R[0:c,0:d]**2, c=D[3*z:3*z+c,0:d]**.3, cmap=plt.cm.nipy_spectral) +ax[1,1].scatter(X[4*z:4*z+c,0:d], Y[4*z:4*z+c,0:d], s=R[0:c,0:d]**2, c=D[4*z:4*z+c,0:d]**.2, cmap=plt.cm.nipy_spectral) plt.savefig("Mercator_Mandelbrot_zoom.png", dpi=100) diff --git a/Task/Mandelbrot-set/True-BASIC/mandelbrot-set.basic b/Task/Mandelbrot-set/True-BASIC/mandelbrot-set.basic new file mode 100644 index 0000000000..125cdf3f60 --- /dev/null +++ b/Task/Mandelbrot-set/True-BASIC/mandelbrot-set.basic @@ -0,0 +1,29 @@ +SET WINDOW 0, 256, 0, 192 + +LET x1 = 256/2 +LET y1 = 192/2 +LET i1 = -1 +LET i2 = 1 +LET r1 = -2 +LET r2 = 1 +LET s1 = (r2-r1) / x1 +LET s2 = (i2-i1) / y1 + +FOR y = 0 TO y1 STEP .05 + LET i3 = i1 + s2 * y + FOR x = 0 TO x1 STEP .05 + LET r3 = r1 + s1 * x + LET z1 = r3 + LET z2 = i3 + FOR n = 0 TO 30 + LET a = z1 * z1 + LET b = z2 * z2 + IF a+b > 4 THEN EXIT FOR + LET z2 = 2 * z1 * z2 + i3 + LET z1 = a - b + r3 + NEXT n + SET COLOR n - 16*INT(n/16) + PLOT POINTS: x,y + NEXT x +NEXT y +END diff --git a/Task/Middle-three-digits/BASIC256/middle-three-digits.basic b/Task/Middle-three-digits/BASIC256/middle-three-digits.basic new file mode 100644 index 0000000000..0115a7048b --- /dev/null +++ b/Task/Middle-three-digits/BASIC256/middle-three-digits.basic @@ -0,0 +1,23 @@ +function middleThreeDigits(n) + if n < 0 then n = -n + if n < 100 then return "" ## error code + if n < 1000 then return string(n) + if n < 10000 then return "" + ns = string(n) + if length(ns) mod 2 = 0 then return "" ## need to have an odd number of digits for there to be 3 middle + return mid(ns, length(ns) \ 2, 3) +end function + +dim a = {123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -123451, 2, -1, -10, 2002, -2002, 0} + +print "The 3 middle digits of the following numbers are : " +print +for i = 0 to 15 + result = middleThreeDigits(a[i]) + print a[i]; chr(9); " => "; + if result <> "" then + print result + else + print "Error: does not have 3 middle digits" + end if +next diff --git a/Task/Middle-three-digits/RPL/middle-three-digits.rpl b/Task/Middle-three-digits/RPL/middle-three-digits.rpl deleted file mode 100644 index 8a9792f1ad..0000000000 --- a/Task/Middle-three-digits/RPL/middle-three-digits.rpl +++ /dev/null @@ -1,16 +0,0 @@ -≪ ABS DUP XPON - IF DUP 2 < OVER 2 MOD OR THEN - DROP2 -1 - ELSE - 2 / 1 - ALOG / IP 1000 MOD - END -≫ -'→M3D' STO - -≪ { 123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345 -10 2002} - → tl - ≪ 1 tl SIZE FOR j - tl j GET →M3D - NEXT - ≫ -≫ EVAL diff --git a/Task/Middle-three-digits/Yabasic/middle-three-digits.basic b/Task/Middle-three-digits/Yabasic/middle-three-digits.basic new file mode 100644 index 0000000000..f1c66ed7ed --- /dev/null +++ b/Task/Middle-three-digits/Yabasic/middle-three-digits.basic @@ -0,0 +1,29 @@ +sub middleThreeDigits$ (n) + if n < 0 n = -n + if n < 100 return "" // error code + if n < 1000 return str$(n) + if n < 10000 return "" + ns$ = str$(n) + if mod(len(ns$), 2) = 0 return "" // need to have an odd number of digits for there to be 3 middle + return mid$(ns$, len(ns$) / 2, 3) +end sub + +dim a(16) +a(0) = 123 : a(1) = 12345 : a(2) = 1234567 +a(3) = 987654321 : a(4) = 10001 : a(5) = -10001 +a(6) = -123 : a(7) = -100 : a(8) = 100 +a(9) = -123451 +a(10) = 2 : a(11) = -1 : a(12) = -10 +a(13) = 2002 : a(14) = -2002 : a(15) = 0 + +print "The 3 middle digits of the following numbers are : \n" + +for i = 1 to 16 + result$ = middleThreeDigits$(a(i)) + print a(i), "\t => "; + if result$ <> "" then + print result$ + else + print "Error: does not have 3 middle digits" + fi +next diff --git a/Task/Multiplication-tables/N-t-roff/multiplication-tables.ntroff b/Task/Multiplication-tables/N-t-roff/multiplication-tables.ntroff new file mode 100644 index 0000000000..5b0a8dda25 --- /dev/null +++ b/Task/Multiplication-tables/N-t-roff/multiplication-tables.ntroff @@ -0,0 +1,19 @@ +.nf +.ta T 2mR +.nr x 1 1 +.nr y 2 1 +.nr p 0 +.while (\n[x] <= 12) \{\ +.if (\n[x]<10) \0\c +\n[x]\c +.if (\n[x]=1) \c +.while (\n[y] <= 12) \{\ +.nr p \n[x]*\n[y] +.ie (\n[y]>=\n[x]) \n[p] \c +.el \c +.nr y +1 +.\} +.br +.nr x +1 +.nr y 1 1 +.\} diff --git a/Task/Next-highest-int-from-digits/Ruby/next-highest-int-from-digits.rb b/Task/Next-highest-int-from-digits/Ruby/next-highest-int-from-digits.rb new file mode 100644 index 0000000000..fb7dfb69ab --- /dev/null +++ b/Task/Next-highest-int-from-digits/Ruby/next-highest-int-from-digits.rb @@ -0,0 +1,15 @@ +def next_perm(ar) + ar = ar.dup + rev_ar = ar.reverse + (a, pivot), i = rev_ar.each_cons(2).with_index(1).detect{|(e1, e2),i| e1 > e2} + return [0] if i.nil? + suffix = ar[-i..] + min_dif = suffix.map{|el|el-pivot }.reject{|el|el <= 0}.min + ri = ar.rindex{|el| el == min_dif + pivot} + ar[-(i+1)], ar[ri] = ar[ri], ar[-(i+1)] + ar[-i..] = ar[-i..].reverse + ar +end + +tests = [0, 9, 12, 21, 12453, 738440, 45072010, 95322020, 9589776899767587796600] +tests.each{|t| puts "%25d -> %d" % [t, next_perm(t.to_s.chars.map(&:to_i)).join]} diff --git a/Task/Number-names/BASIC256/number-names.basic b/Task/Number-names/BASIC256/number-names.basic new file mode 100644 index 0000000000..84dd7b9f33 --- /dev/null +++ b/Task/Number-names/BASIC256/number-names.basic @@ -0,0 +1,59 @@ +global lows +lows = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"} +global tens +tens = {"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"} +global lev +lev = {"", "thousand", "million", "billion"} + +function numname_int(n) + if n = 0 then return "zero" + if n < 0 then return "negative " + numname_int(-n) + t = -1 + redim triples(3) #con < 3 da error ¿¿?? + ret = "" + + while n > 0 + t += 1 + triples[t] = n mod 1000 + n = int(n / 1000) + end while + for i = t to 0 step -1 + tripname = "" + if triples[i] = 0 then continue for + lasttwo = triples[i] mod 100 + hundreds = triples[i] \ 100 + if lasttwo < 20 then + tripname = lows[lasttwo] + tripname + " " + else + tripname = tens[lasttwo\10] + "-" + lows[lasttwo mod 10] + " " + tripname + end if + if hundreds > 0 then + if lasttwo > 0 then tripname = " and " + tripname + tripname = lows[hundreds] + " hundred" + tripname + end if + if i = 0 and t > 0 and hundreds = 0 then tripname = " and " + tripname + tripname += lev[i] + " " + ret = ltrim(ret) + ltrim(tripname) + next i + return trim(ret) +end function + +function numname(n) + ret = "" + if n = int(n) then return numname_int(int(n)) + prefix = numname_int(int(abs(n))) + " point " + decdig = string(abs(n)-int(abs(n))) + if n < 0 then prefix = "negative " + prefix + ret = prefix + for i = 3 to length(decdig) + ret += numname(int(mid(decdig,i,1))) + " " + next i + return trim(ret) +end function + +print numname(0) +print numname(1.0) +print numname(-1.7) +print numname(910000) +print numname(987654) +print numname(100000017) diff --git a/Task/Parametric-polymorphism/C3/parametric-polymorphism-1.c3 b/Task/Parametric-polymorphism/C3/parametric-polymorphism-1.c3 index ae5eb049e5..73092184fd 100644 --- a/Task/Parametric-polymorphism/C3/parametric-polymorphism-1.c3 +++ b/Task/Parametric-polymorphism/C3/parametric-polymorphism-1.c3 @@ -1,4 +1,4 @@ -module tree; +module tree(); struct Tree { @@ -7,9 +7,9 @@ struct Tree Tree* right; } -fn void Tree.replaceAll(Tree* a_tree, Type new_value) +fn void Tree.replace_all(&self, Type new_value) { - a_tree.value = new_value; - if (a_tree.left) a_tree.left.replaceAll(new_value); - if (a_tree.right) a_tree.right.replaceAll(new_value); + self.value = new_value; + if (self.left) self.left.replace_all(new_value); + if (self.right) self.right.replace_all(new_value); } diff --git a/Task/Parametric-polymorphism/C3/parametric-polymorphism-2.c3 b/Task/Parametric-polymorphism/C3/parametric-polymorphism-2.c3 index c57919916f..bf7a6c9501 100644 --- a/Task/Parametric-polymorphism/C3/parametric-polymorphism-2.c3 +++ b/Task/Parametric-polymorphism/C3/parametric-polymorphism-2.c3 @@ -1,7 +1,7 @@ -define IntTree = tree::Tree; +import tree; fn void test() { - IntTree inttree; - inttree.replaceAll(3); + Tree() inttree; + inttree.replace_all(3); } diff --git a/Task/Pell-numbers/ALGOL-68/pell-numbers.alg b/Task/Pell-numbers/ALGOL-68/pell-numbers.alg index 8e9cb40bb7..95628dc980 100644 --- a/Task/Pell-numbers/ALGOL-68/pell-numbers.alg +++ b/Task/Pell-numbers/ALGOL-68/pell-numbers.alg @@ -2,28 +2,6 @@ BEGIN # find some Pell numbers - trans FreeBASIC ( which is trans Phix ) # PR read "primes.incl.a68" PR - PROC is prime = ( LONG INT v )BOOL: - IF v < 2 THEN FALSE - ELIF v MOD 2 = 0 THEN v = 2 - ELIF v MOD 3 = 0 THEN v = 3 - ELSE - LONG INT d := 5; - BOOL result := TRUE; - WHILE result AND d * d <= v DO - IF v MOD d = 0 - THEN result := FALSE - ELSE - d +:= 2; - IF v MOD d = 0 - THEN result := FALSE - ELSE d +:= 4 - FI - FI - OD; - result - FI # is prime # ; - - INT n; [ 0 : 90 ]LONG INT p, pl; p[ 0 ] := 0; p[ 1 ] := 1; pl[ 0 ] := 2; pl[ 1 ] := 2; @@ -45,21 +23,19 @@ BEGIN # find some Pell numbers - trans FreeBASIC ( which is trans Phix ) # OD; print( ( newline, "First 10 Pell primes:", newline, "index Pell prime", newline ) ); - INT pdx := 2; - INT c := 0; - WHILE + INT c := 0; + FOR pdx FROM 2 WHILE c < 10 DO IF is probably prime( p[ pdx ] ) THEN print( ( whole( pdx, -5 ), " ", whole( p[ pdx ], 0 ), newline ) ); c +:= 1 - FI; - pdx +:= 1; - c < 10 - DO SKIP OD; + FI + OD; - [ 0 : 20 ]LONG INT nsw; - FOR n FROM 0 TO 19 DO nsw[ n ] := p[ 2 * n ] + p[ 2 * n + 1 ] OD; print( ( newline, newline, "First 20 Newman-Shank-Williams numbers:", newline ) ); - FOR n FROM 0 TO 19 DO print( ( " ", whole( nsw[ n ], 0 ) ) ); IF n = 13 THEN print( ( newline ) ) FI OD; + FOR n FROM 0 TO 19 DO + LONG INT nsw = p[ 2 * n ] + p[ 2 * n + 1 ]; + print( ( " ", whole( nsw, 0 ) ) ); IF n = 13 THEN print( ( newline ) ) FI + OD; print( ( newline, newline, "First 20 near isosceles right triangles:", newline ) ); LONG INT i0 := 0, i1 := 1, t := 1, found := 0; diff --git a/Task/Pell-numbers/ALGOL-W/pell-numbers.alg b/Task/Pell-numbers/ALGOL-W/pell-numbers.alg new file mode 100644 index 0000000000..baa3e7510d --- /dev/null +++ b/Task/Pell-numbers/ALGOL-W/pell-numbers.alg @@ -0,0 +1,90 @@ +begin % find some Pell numbers - trans FreeBasic ( which is trans Phix ) % + + % returns true if n is prime, false otherwise, uses trial division % + logical procedure isPrime ( integer value n ) ; + if n < 3 then n = 2 + else if n rem 3 = 0 then n = 3 + else if not odd( n ) then false + else begin + logical prime; + integer f, f2, toNext; + prime := true; + f := 5; + f2 := 25; + toNext := 24; % note: ( 2n + 1 )^2 - ( 2n - 1 )^2 = 8n % + while f2 <= n and prime do begin + prime := n rem f not = 0; + f := f + 2; + f2 := toNext; + toNext := toNext + 8 + end while_f2_le_n_and_prime ; + prime + end isPrime ; + + integer MAX_P; + MAX_P := 9; + begin + integer array p, pl ( 0 :: 20 ); % need more than 10 Pell numbers % + integer c, pdx; % to find the fifth Pell prime % + + p( 0 ) := 0; p( 1 ) := 1; + pl( 0 ) := 2; pl( 1 ) := 2; + for n := 2 until 20 do begin + p( n ) := 2 * p( n - 1 ) + p( n - 2 ); + pl( n ) := 2 * pl( n - 1 ) + pl( n - 2 ) + end for_n ; + + write( "First 10 Pell numbers:" ); + for n := 0 until MAX_P do begin writeon( i_w := 1, s_w := 0, " ", p( n ) ) end; + write();write( "First 10 Pell-Lucas numbers:" ); + for n := 0 until MAX_P do begin + writeon( i_w := 1, s_w := 0, " ", pl( n ) ) + end for_n ; + + write( s_w := 0, "First 10 rational approximations of sqrt(2) (" ); + writeon( s_w := 0, r_format := "A", r_w := 8, r_d := 6, sqrt( 2 ), "):" ); + for n := 1 until MAX_P do begin + integer j; + j := pl( n ) div 2; + write( i_w := 1, s_w := 0, " ", j, "/", p( n ), " ~= " + , r_format := "A", r_w := 8, r_d := 6, j / p( n ) + ) + end for_n; + + write();write( "First 5 Pell primes:" ); write( "index Pell prime" ); + c := 0; + pdx := 2; + while c < 5 do begin + if isPrime( p( pdx ) ) then begin + write( i_w := 5, s_w := 0, pdx, " ", i_w := 1, p( pdx ) ); + c := c + 1 + end if_isPrime_p_pdx ; + pdx := pdx + 1 + end while_c_lt_5 ; + + write(); write( "First 10 Newman-Shank-Williams numbers:" );write(); + for n := 0 until MAX_P do begin + integer nsw; + nsw := p( 2 * n ) + p( 2 * n + 1 ); + writeon( i_w := 1, s_w := 0, " ", nsw ) + end for_n; + + write();write( "First 10 near isosceles right triangles:" ); + begin + integer i, i0, i1, i2, t, found; + i0 := 0; i1 := 1; t := 1; found := 0; + i := 1; + while found < 10 do begin + i := i + 1; + i2 := i1*2 + i0; + if odd( i ) then begin + write( i_w := 1, s_w := 0, " [", t, ", ", t + 1, ", ", i2, "]" ); + found := found + 1 + end if_odd_i ; + t := t + i2; i0 := i1; i1 := i2 + end while_found_lt_10 + end + + end + +end. diff --git a/Task/Pell-numbers/Ruby/pell-numbers.rb b/Task/Pell-numbers/Ruby/pell-numbers.rb new file mode 100644 index 0000000000..2a7b839887 --- /dev/null +++ b/Task/Pell-numbers/Ruby/pell-numbers.rb @@ -0,0 +1,37 @@ +require 'openssl' +def prime?(n) = OpenSSL::BN.new(n).prime? + +pell = Enumerator.new do |y| + pe = [0,1] + loop{y << pe[0]; pe << pe[1]*2 + pe.shift} +end + +pell_lucas = Enumerator.new do |y| + pe = [2,2] + loop{y << pe[0]; pe << pe[1]*2 + pe.shift} +end + +n = 20 +puts "First #{n} Pell numbers: #{pell.first(n).to_a.inspect}" +puts "\nFirst #{n} Pell-Lucas numbers: #{pell_lucas.first(n).to_a.inspect}" + +n = 15 +sqrt2 = pell.each_cons(2).lazy.map{|p1,p2| Rational(p1+p2, p2)}.take(n).to_a +puts "\nThe first #{n} rational approximations of √2 (#{Math.sqrt(2)}) are:" +sqrt2.each{|n| puts "%-16s ≈ %-18s\n"% [n, n.to_f]} + +puts "\nThe first #{n} Pell primes with index are:" +primes = pell.with_index.lazy.select{|n, i|prime?(i) && prime?(n)}.first(n) +primes.each {|prime, i| puts "#{i.to_s.ljust(3)} #{prime}"} + +puts "\nThe first #{n} NSW numbers:" +puts pell.first(2*n).each_slice(2).map(&:sum).join(", ") + +puts "\nFirst #{n} near isosceles right triangles:" +sum = 1 +pell.take(n*2+2).each_slice(2) do |p1,p2| + next if p1 == 0 + sum += p1 + puts "#{sum}, #{sum+1}, #{p2}" + sum += p2 +end diff --git a/Task/Pick-random-element/Dart/pick-random-element.dart b/Task/Pick-random-element/Dart/pick-random-element.dart new file mode 100644 index 0000000000..87c95b221c --- /dev/null +++ b/Task/Pick-random-element/Dart/pick-random-element.dart @@ -0,0 +1,11 @@ +import 'dart:math'; + +void main() { + final array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; + int i; + + for (i = 1; i < 30; i++) { + var intValue = Random().nextInt(i) % 10; + print(array[intValue]); + } +} diff --git a/Task/Pick-random-element/REXX/pick-random-element-1.rexx b/Task/Pick-random-element/REXX/pick-random-element-1.rexx index 2074f9b237..1f74ec87a3 100644 --- a/Task/Pick-random-element/REXX/pick-random-element-1.rexx +++ b/Task/Pick-random-element/REXX/pick-random-element-1.rexx @@ -1,21 +1,46 @@ /*REXX program picks a random element from a list (tongue in cheek, a visual pun).*/ -_= 'hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine neon sodium' -_=_ 'magnesium aluminum silicon phosphorous sulfur chlorine argon potassium calcium' -_=_ 'scandium titanium vanadium chromium manganese iron cobalt nickel copper zinc gallium' -_=_ 'germanium arsenic selenium bromine krypton rubidium strontium yttrium zirconium' -_=_ 'niobium molybdenum technetium ruthenium rhodium palladium silver cadmium indium tin' -_=_ 'antimony tellurium iodine xenon cesium barium lanthanum cerium praseodymium' -_=_ 'neodymium promethium samarium europium gadolinium terbium dysprosium holmium erbium' -_=_ 'thulium ytterbium lutetium hafnium tantalum tungsten rhenium osmium iridium platinum' -_=_ 'gold mercury thallium lead bismuth polonium astatine radon francium radium actinium' -_=_ 'thorium protactinium uranium neptunium plutonium americium curium berkelium' -_=_ 'californium einsteinium fermium mendelevium nobelium lawrencium rutherfordium dubnium' -_=_ 'seaborgium bohrium hassium meitnerium darmstadtium roentgenium copernicium nihonium' -_=_ 'flerovium moscovium livermorium tennessine oganesson ununenniym unbinvlium umbiunium' +l= "Hydrogen_H Helium_He Lithium_Li Beryllium_Be Boron_B" +l=l "Carbon_C Nitrogen_N Oxygen_O Fluorine_F Neon_Ne Sodium_Na" +l=l "Magnesium_Mg Aluminium_Al Silicon_Si Phosphorus_P Sulfur_S" +l=l "Chlorine_Cl Argon_Ar Potassium_K Calcium_Ca Scandium_Sc" +l=l "Titanium_Ti Vanadium_V Chromium_Cr Manganese_Mn Iron_Fe" +l=l "Cobalt_Co Nickel_Ni Copper_Cu Zinc_Zn Gallium_Ga" +l=l "Germanium_Ge Arsenic_As Selenium_Se Bromine_Br Krypton_Kr" +l=l "Rubidium_Rb Strontium_Sr Yttrium_Y Zirconium_Zr Niobium_Nb" +l=l "Molybdenum_Mo Technetium_Tc Ruthenium_Ru Rhodium_Rh" +l=l "Palladium_Pd Silver_Ag Cadmium_Cd Indium_In Tin_Sn" +l=l "Antimony_Sb Tellurium_Te Iodine_I Xenon_Xe Caesium_Cs" +l=l "Barium_Ba Lanthanum_La Cerium_Ce Praseodymium_Pr" +l=l "Neodymium_Nd Promethium_Pm Samarium_Sm Europium_Eu" +l=l "Gadolinium_Gd Terbium_Tb Dysprosium_Dy Holmium_Ho Erbium_Er" +l=l "Thulium_Tm Ytterbium_Yb Lutetium_Lu Hafnium_Hf Tantalum_Ta" +l=l "Tungsten_W Rhenium_Re Osmium_Os Iridium_Ir Platinum_Pt" +l=l "Gold_Au Mercury_Hg Thallium_Tl Lead_Pb Bismuth_Bi" +l=l "Polonium_Po Astatine_At Radon_Rn Francium_Fr Radium_Ra" +l=l "Actinium_Ac Thorium_Th Protactinium_Pa Uranium_U" +l=l "Neptunium_Np Plutonium_Pu Americium_Am Curium_Cm" +l=l "Berkelium_Bk Californium_Cf Einsteinium_Es Fermium_Fm" +l=l "Mendelevium_Md Nobelium_No Lawrencium_Lr Rutherfordium_Rf" +l=l "Dubnium_Db Seaborgium_Sg Bohrium_Bh Hassium_Hs Meitnerium_Mt" +l=l "Darmstadtium_Ds Roentgenium_Rg Copernicium_Cn Nihonium_Nh" +l=l "Flerovium_Fl Moscovium_Mc Livermorium_Lv Tennessine_Ts" +l=l "Oganesson_Og Ununbium_Uub Ununtrium_Uut Ununquadium_Uuq" +n=words(l) /* Number of known elements */ + /*----- You can't trust atoms, -----*/ + /*----- they make everything up. -----*/ +Parse Arg pick /* atomic number specified */ +If pick>n Then Do + Say 'Element' pick 'hasn''t been discovered by now' + Exit + End +take=pick +If pick='' Then + take=random(1,n) - /*───── You can't trust atoms, ─────*/ - /*───── they make everything up. ─────*/ - -#= words(_) /*obtain the number of words in list. */ -item= word(_, random(1, #) ) /*pick a random word (element) in list.*/ -say 'random element: ' item /*stick a fork in it, we're all done. */ +item=word(l,take) /*pick the specified or random element */ +Parse Var item name '_' symbol +If pick='' Then + which='Random' +Else + which='Specified' +Say which 'element: ' take name '('symbol')' /*stick a fork in it, we're all done. */ diff --git a/Task/Prime-decomposition/ANSI-BASIC/prime-decomposition.basic b/Task/Prime-decomposition/ANSI-BASIC/prime-decomposition.basic new file mode 100644 index 0000000000..35d8ffce2a --- /dev/null +++ b/Task/Prime-decomposition/ANSI-BASIC/prime-decomposition.basic @@ -0,0 +1,31 @@ +100 PROGRAM PrimeDecomposition +110 REM -(2^31) has most prime factors (31 twos) than other 32-bit signed integer. +120 DIM Facs(0 TO 30) +130 INPUT PROMPT "Enter a number: ": N +140 CALL CalcFacs(N, Facs, FacsCnt) +150 REM There is at least one factor +160 FOR I = 0 TO FacsCnt - 1 +170 PRINT Facs(I); +180 NEXT I +190 PRINT +200 END +210 REM ** +220 EXTERNAL SUB CalcFacs(N, Facs(), FacsCnt) +230 LET N = ABS(N) +240 LET FacsCnt = 0 +250 IF N >= 2 THEN +260 LET I = 2 +270 DO WHILE I * I <= N +280 IF MOD(N, I) = 0 THEN +290 LET N = INT(N / I) +300 LET Facs(FacsCnt) = I +310 LET FacsCnt = FacsCnt + 1 +320 LET I = 2 +330 ELSE +340 LET I = I + 1 +350 END IF +360 LOOP +370 LET Facs(FacsCnt) = N +380 LET FacsCnt = FacsCnt + 1 +390 END IF +400 END SUB diff --git a/Task/Prime-decomposition/Modula-2/prime-decomposition.mod2 b/Task/Prime-decomposition/Modula-2/prime-decomposition.mod2 new file mode 100644 index 0000000000..7a83315a70 --- /dev/null +++ b/Task/Prime-decomposition/Modula-2/prime-decomposition.mod2 @@ -0,0 +1,55 @@ +MODULE PrimeDecomposition; + +FROM STextIO IMPORT + SkipLine, WriteLn, WriteString; +FROM SWholeIO IMPORT + ReadCard, WriteInt; + +CONST + MaxFacIndex = 31; +(* 2^31 has most prime factors (31 twos) than other 32-bit unsigned integer. *) + +TYPE + TFacs = ARRAY [0 .. MaxFacIndex] OF CARDINAL; + +VAR + Facs: TFacs; + I, N, FacsCnt: CARDINAL; + +PROCEDURE CalcFacs(N: CARDINAL; VAR Facs: TFacs; VAR FacsCnt: CARDINAL); +VAR + I: CARDINAL; +BEGIN + FacsCnt := 0; + IF N >= 2 THEN + I := 2; + WHILE I * I <= N DO + IF N MOD I = 0 THEN + N := N DIV I; + Facs[FacsCnt] := I; + FacsCnt := FacsCnt + 1; + I := 2 + ELSE + I := I + 1 + END + END; + Facs[FacsCnt] := N; + FacsCnt := FacsCnt + 1 + END; +END CalcFacs; + +BEGIN + WriteString("Enter a number: "); + ReadCard(N); + SkipLine; + CalcFacs(N, Facs, FacsCnt); + (* There is at least one factor *) + IF FacsCnt > 1 THEN + FOR I := 0 TO FacsCnt - 2 DO + WriteInt(Facs[I], 1); + WriteString(" ") + END; + END; + WriteInt(Facs[FacsCnt - 1], 1); + WriteLn +END PrimeDecomposition. diff --git a/Task/Pseudo-random-numbers-Middle-square-method/Chipmunk-Basic/pseudo-random-numbers-middle-square-method.basic b/Task/Pseudo-random-numbers-Middle-square-method/Chipmunk-Basic/pseudo-random-numbers-middle-square-method.basic new file mode 100644 index 0000000000..9409407a6f --- /dev/null +++ b/Task/Pseudo-random-numbers-Middle-square-method/Chipmunk-Basic/pseudo-random-numbers-middle-square-method.basic @@ -0,0 +1,5 @@ +10 semilla = 675248 +20 for i = 1 to 5 +30 print i;": ";semilla +31 semilla = ((semilla*semilla)/1000) mod 1000000 +40 next i diff --git a/Task/Pseudo-random-numbers-Splitmix64/Phix/pseudo-random-numbers-splitmix64.phix b/Task/Pseudo-random-numbers-Splitmix64/Phix/pseudo-random-numbers-splitmix64.phix index d7752a9e9d..b3548db3a8 100644 --- a/Task/Pseudo-random-numbers-Splitmix64/Phix/pseudo-random-numbers-splitmix64.phix +++ b/Task/Pseudo-random-numbers-Splitmix64/Phix/pseudo-random-numbers-splitmix64.phix @@ -1,52 +1,50 @@ -(phixonline)--> - with javascript_semantics - include mpfr.e - mpz state = mpz_init(), - shift = mpz_init("0x9e3779b97f4a7c15"), - mult1 = mpz_init("0xbf58476d1ce4e5b9"), - mult2 = mpz_init("0x94d049bb133111eb"), - b64 = mpz_init("0x10000000000000000"), -- (truncate to 64 bits) - tmp = mpz_init(), - z = mpz_init() +with javascript_semantics +include mpfr.e +mpz state = mpz_init(), + shift = mpz_init("0x9e3779b97f4a7c15"), + mult1 = mpz_init("0xbf58476d1ce4e5b9"), + mult2 = mpz_init("0x94d049bb133111eb"), + b64 = mpz_init("0x10000000000000000"), -- (truncate to 64 bits) + tmp = mpz_init(), + z = mpz_init() - procedure seed(integer num) - mpz_set_si(state,num) - end procedure +procedure seed(integer num) + mpz_set_si(state,num) +end procedure - procedure next_int() - mpz_add(state, state, shift) -- state += shift - mpz_fdiv_r(state, state, b64) -- state := remainder(z,b64) - mpz_set(z, state) -- z := state - mpz_tdiv_q_2exp(tmp, z, 30) -- tmp := trunc(z/2^30) - mpz_xor(z, z, tmp) -- z := xor_bits(z,tmp) - mpz_mul(z, z, mult1) -- z *= mult1 - mpz_fdiv_r(z, z, b64) -- z := remainder(z,b64) - mpz_tdiv_q_2exp(tmp, z, 27) -- tmp := trunc(z/2^27) - mpz_xor(z, z, tmp) -- z := xor_bits(z,tmp) - mpz_mul(z, z, mult2) -- z *= mult2 - mpz_fdiv_r(z, z, b64) -- z := remainder(z,b64) - mpz_tdiv_q_2exp(tmp, z, 31) -- tmp := trunc(z/2^31) - mpz_xor(z, z, tmp) -- z := xor_bits(z,tmp) - -- (result left in z) - end procedure +procedure next_int() + mpz_add(state, state, shift) -- state += shift + mpz_fdiv_r(state, state, b64) -- state := remainder(z,b64) + mpz_set(z, state) -- z := state + mpz_tdiv_q_2exp(tmp, z, 30) -- tmp := trunc(z/2^30) + mpz_xor(z, z, tmp) -- z := xor_bits(z,tmp) + mpz_mul(z, z, mult1) -- z *= mult1 + mpz_fdiv_r(z, z, b64) -- z := remainder(z,b64) + mpz_tdiv_q_2exp(tmp, z, 27) -- tmp := trunc(z/2^27) + mpz_xor(z, z, tmp) -- z := xor_bits(z,tmp) + mpz_mul(z, z, mult2) -- z *= mult2 + mpz_fdiv_r(z, z, b64) -- z := remainder(z,b64) + mpz_tdiv_q_2exp(tmp, z, 31) -- tmp := trunc(z/2^31) + mpz_xor(z, z, tmp) -- z := xor_bits(z,tmp) + -- (result left in z) +end procedure - function next_float() - next_int() - mpfr f = mpfr_init_set_z(z) - mpfr_div_z(f, f, b64) - return mpfr_get_d(f) - end function +function next_float() + next_int() + mpfr f = mpfr_init_set_z(z) + mpfr_div_z(f, f, b64) + return mpfr_get_d(f) +end function - seed(1234567) - for i=1 to 5 do - next_int() - printf(1,"%s\n",mpz_get_str(z)) - end for - seed(987654321) - sequence r = repeat(0,5) - for i=1 to 100000 do - integer rdx = floor(next_float()*5)+1 - r[rdx] += 1 - end for - ?r -