Data update

This commit is contained in:
Ingy dot Net 2024-04-20 12:30:13 -07:00
parent aec8ed51b6
commit 29a5eea0d4
128 changed files with 1298 additions and 0 deletions

View File

@ -16,6 +16,7 @@
A+: .a+
AArch64 Assembly: .aarch64
ABAP: .abap
ABC: .abc
ACL2: .acl2
Acornsoft Lisp: .lisp
Action!: .action
@ -74,6 +75,8 @@ Asymptote: .asymptote
Atari BASIC: .basic
ATS: .ats
AutoHotkey: .ahk
Autohotkey V2: .ahk
AutoHotKey V2: .ahk
AutoIt: .autoit
AutoLISP: .l
Avail: .avail
@ -209,6 +212,7 @@ DMS: .dms
Dodo0: .dodo0
Draco: .draco
Dragon: .dragon
DreamBerd: .dreamberd
Dt: .dt
DUP: .dup
DWScript: .dw
@ -292,6 +296,7 @@ F Sharp: .fs
FTCBASIC: .basic
FunL: .funl
Furor: .furor
FurryScript: .furryscript
Futhark: .futhark
FutureBasic: .basic
FUZE BASIC: .basic
@ -311,6 +316,7 @@ GFA Basic: .basic
G-fu: .gfu
Glagol: .glagol
GLBasic: .basic
Gleam: .gleam
Glee: .glee
Global Script: .global
GlovePIE: .glovepie
@ -575,6 +581,7 @@ Oforth: .fth
Ol: .ol
Omega: .omega
Onyx: .onyx
Onyx (wasm): .onyx
OOC: .ooc
OOCalc: .oocalc
OoRexx: .rexx
@ -781,6 +788,7 @@ Star: .star
Stata: .stata
Stax: .stax
StreamIt: .streamit
Stringle: .stringle
Suneido: .suneido
Superbase BASIC: .basic
SuperCollider: .sc
@ -805,6 +813,7 @@ Terraform: .terraform
TestML: .tml
Thistle: .thistle
Thyrd: .thyrd
TI BASIC: .basic
TI-57: .ti57
TI-83 BASIC: .basic
TI-83 Hex Assembly: .asm

18
Lang/ABC/00-LANG.txt Normal file
View File

@ -0,0 +1,18 @@
{{language
|exec=interpreted
|site=https://homepages.cwi.nl/~steven/abc/
|strength=strong
|safety=safe
|express=implicit
|checking=dynamic
|parampass=value, reference
|gc=yes}}{{language programming paradigm|Dynamic}}{{language programming paradigm|Imperative}}
'''ABC''' is a programming language and development environment developed for teaching purposes at the National Research Institute for Mathematics and Computer Science in the Netherlands in the late 80s. It was meant to be a replacement for BASIC in teaching programming to students. The language was meant to be used interactively. Instead of traditional source files, the environment uses workspaces, though the UNIX version does have (rather minimal) script support. Function definitions and global variables persist from session to session without the user having to explicitly save or load them. The environment furthermore includes autocompletion and a syntax-aware editor. There is no supported way to access the underlying OS or file system directly. The tight integration between the language implementation and the IDE turned out to be a barrier to expansion, and the language was largely abandoned in the early 90s.
There is an unfortunate bug in the official interpreter: it switches to the alternate terminal screen even when running a non-interactive script, resulting in the output being invisible. A workaround is to specify a terminal type that does not support it, e.g. <tt>TERM=vt100 abc script.abc</tt>.
==References==
* [https://homepages.cwi.nl/~steven/abc/ Official homepage]
* [[wp:ABC_(programming_language)|ABC on Wikipedia]]

2
Lang/ABC/00-META.yaml Normal file
View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:ABC

1
Lang/ABC/100-doors Symbolic link
View File

@ -0,0 +1 @@
../../Task/100-doors/ABC

1
Lang/ABC/100-prisoners Symbolic link
View File

@ -0,0 +1 @@
../../Task/100-prisoners/ABC

1
Lang/ABC/99-bottles-of-beer Symbolic link
View File

@ -0,0 +1 @@
../../Task/99-bottles-of-beer/ABC

1
Lang/ABC/ABC-problem Symbolic link
View File

@ -0,0 +1 @@
../../Task/ABC-problem/ABC

View File

@ -0,0 +1 @@
../../Task/Abundant-deficient-and-perfect-number-classifications/ABC

1
Lang/ABC/Ackermann-function Symbolic link
View File

@ -0,0 +1 @@
../../Task/Ackermann-function/ABC

1
Lang/ABC/Additive-primes Symbolic link
View File

@ -0,0 +1 @@
../../Task/Additive-primes/ABC

1
Lang/ABC/Amicable-pairs Symbolic link
View File

@ -0,0 +1 @@
../../Task/Amicable-pairs/ABC

1
Lang/ABC/Attractive-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Attractive-numbers/ABC

1
Lang/ABC/Benfords-law Symbolic link
View File

@ -0,0 +1 @@
../../Task/Benfords-law/ABC

1
Lang/ABC/Bulls-and-cows Symbolic link
View File

@ -0,0 +1 @@
../../Task/Bulls-and-cows/ABC

1
Lang/ABC/Casting-out-nines Symbolic link
View File

@ -0,0 +1 @@
../../Task/Casting-out-nines/ABC

1
Lang/ABC/Comma-quibbling Symbolic link
View File

@ -0,0 +1 @@
../../Task/Comma-quibbling/ABC

1
Lang/ABC/Department-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Department-numbers/ABC

View File

@ -0,0 +1 @@
../../Task/Evolutionary-algorithm/ABC

1
Lang/ABC/FizzBuzz Symbolic link
View File

@ -0,0 +1 @@
../../Task/FizzBuzz/ABC

1
Lang/ABC/Floyds-triangle Symbolic link
View File

@ -0,0 +1 @@
../../Task/Floyds-triangle/ABC

1
Lang/ABC/Giuga-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Giuga-numbers/ABC

1
Lang/ABC/Hailstone-sequence Symbolic link
View File

@ -0,0 +1 @@
../../Task/Hailstone-sequence/ABC

1
Lang/ABC/Happy-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Happy-numbers/ABC

View File

@ -0,0 +1 @@
../../Task/Harshad-or-Niven-series/ABC

View File

@ -0,0 +1 @@
../../Task/Hofstadter-Figure-Figure-sequences/ABC

1
Lang/ABC/ISBN13-check-digit Symbolic link
View File

@ -0,0 +1 @@
../../Task/ISBN13-check-digit/ABC

1
Lang/ABC/Jewels-and-stones Symbolic link
View File

@ -0,0 +1 @@
../../Task/Jewels-and-stones/ABC

1
Lang/ABC/Lah-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Lah-numbers/ABC

1
Lang/ABC/McNuggets-problem Symbolic link
View File

@ -0,0 +1 @@
../../Task/McNuggets-problem/ABC

View File

@ -0,0 +1 @@
../../Task/Minimum-multiple-of-m-where-digital-sum-equals-m/ABC

1
Lang/ABC/Munchausen-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Munchausen-numbers/ABC

1
Lang/ABC/Mutual-recursion Symbolic link
View File

@ -0,0 +1 @@
../../Task/Mutual-recursion/ABC

View File

@ -0,0 +1 @@
../../Task/Primality-by-trial-division/ABC

1
Lang/ABC/Rep-string Symbolic link
View File

@ -0,0 +1 @@
../../Task/Rep-string/ABC

View File

@ -0,0 +1 @@
../../Task/Sequence-of-non-squares/ABC

View File

@ -0,0 +1 @@
../../Task/Sieve-of-Eratosthenes/ABC

1
Lang/ABC/Smith-numbers Symbolic link
View File

@ -0,0 +1 @@
../../Task/Smith-numbers/ABC

View File

@ -0,0 +1 @@
../../Task/Strip-a-set-of-characters-from-a-string/ABC

1
Lang/ABC/Towers-of-Hanoi Symbolic link
View File

@ -0,0 +1 @@
../../Task/Towers-of-Hanoi/ABC

1
Lang/ABC/Van-Eck-sequence Symbolic link
View File

@ -0,0 +1 @@
../../Task/Van-Eck-sequence/ABC

View File

@ -0,0 +1 @@
{{stub}}{{language|AutoHotKey V2}}

View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:AutoHotKey_V2

View File

@ -0,0 +1 @@
../../Task/Hello-world-Graphical/AutoHotKey-V2

View File

@ -0,0 +1,10 @@
DreamBerd is a perfect esoteric programming language. Some of its features include:
*Array indexes starting at -1
*No loops
*"Maybe" boolean value
*Many kinds of equality checks
*Type annotations
*"previous/next/current" keywords (for seeing the past/future/present of a variable)
*Signals
{{language|DreamBerd|exec=interpreted|site=https://github.com/TodePond/DreamBerd|gc=yes}}

View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:DreamBerd

View File

@ -0,0 +1 @@
../../Task/Hello-world-Text/DreamBerd

View File

@ -0,0 +1,12 @@
{{stub}}{{language|FurryScript|hopl=no}}
From the [https://esolangs.org/wiki/User:Zzo38/FurryScript esolangs.org article]:
FurryScript is a domain specific programming language (mostly for random text generation), also usable (but not very well) for other programming (as esolangs often are), with some strange features compared with ordinary programming languages:
* The only arithmetic operation is subtraction.
* Negative numbers cannot be entered directly and can only be achieved by subtraction or type casting.
* Strings may contain subroutine calls, but these calls are probabilistic and delayed.
* There are no scalar variables (actually there is one (the input), but it only stores text strings).
* There are only some kinds of loops, and not most of the common kinds found in other programming languages (although it does have some of them).
* List variables and subroutine variables can be anonymous, even though they are not first-class objects.
* There are no conditional blocks.
* Subroutines may exit "OK", "bad", or "very bad", with different effects depending on circumstances.

View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:FurryScript

View File

@ -0,0 +1 @@
../../Task/Array-length/FurryScript

2
Lang/Gleam/00-LANG.txt Normal file
View File

@ -0,0 +1,2 @@
{{stub}}{{language|Gleam|hopl=no|site=https://gleam.run/}}
Gleam is a type-safe functional programming language that runs on the [[Erlang]] virtual machine.

2
Lang/Gleam/00-META.yaml Normal file
View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:Gleam

1
Lang/Gleam/FizzBuzz Symbolic link
View File

@ -0,0 +1 @@
../../Task/FizzBuzz/Gleam

1
Lang/Gleam/Hello-world-Text Symbolic link
View File

@ -0,0 +1 @@
../../Task/Hello-world-Text/Gleam

View File

@ -0,0 +1,22 @@
{{stub}}{{language|site=https://onyxlang.io/}}
Onyx is a WebAssembly-first language (`app.wasm`). WebAssembly can be used inside of a browser but is also growing in popularity outside of the browser, in part due to projects like Wasmer, Wasmtime, and WasmEdge. These "controlled environments" could be game engines, where WASM is used as a "script" system; cloud functions, where WASM is used to respond to requests; plug-in systems for editors or tools.
Onyx uses a modernized C-like syntax, similar to Jai or Odin. Onyx is an imperative and procedural language in which statements are evaluated in the order they are written in, but does allow for functional-inspired syntax using the pipe operator.
For example:
<syntaxhighlight lang="C">
use core { printf, iter }
main :: () {
for i in 1 .. 10 {
fact := factorial(i);
printf("{}! = {}\n", i, fact);
}
}
factorial :: (n: i32) -> i32 {
return iter.as_iter(1 .. n)
|> iter.fold(1, (x, y) => x * y);
}
</syntaxhighlight>

View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:Onyx_(wasm)

View File

@ -0,0 +1 @@
../../Task/Almost-prime/Onyx-(wasm)

View File

@ -0,0 +1 @@
../../Task/Fibonacci-sequence/Onyx-(wasm)

1
Lang/Onyx-(wasm)/FizzBuzz Symbolic link
View File

@ -0,0 +1 @@
../../Task/FizzBuzz/Onyx-(wasm)

View File

@ -0,0 +1 @@
../../Task/Golden-ratio-Convergence/Onyx-(wasm)

View File

@ -0,0 +1 @@
../../Task/Hailstone-sequence/Onyx-(wasm)

View File

@ -0,0 +1 @@
../../Task/Hello-world-Text/Onyx-(wasm)

28
Lang/Stringle/00-LANG.txt Normal file
View File

@ -0,0 +1,28 @@
{{language|Stringle
|exec=interpreted
|gc=no
|parampass=both
|untyped=yes
}}
'''Stringle''' is a simple imperative scripting language based around the manipulation of string variables created by Vacek Nules. Its name is a portmanteau of ''string'' and ''wrangle'', being a language to “wrangle strings”. It supports string assignment and concatenation, loops, conditionals with different ''predicates'' and overloaded, composable functions called ''string operators''.
It has a concise, J-like syntax with single-character operator symbols instead of keywords. Operators are evaluated over strings as functions and are freely composable in arbitrary chains, but some of them can be assigned to as well to modify the string in their argument in various ways.
[[File:Stringle Cheat Sheet.png|thumb]]
Stringle has an extremely simple and basic syntax with only a few primitive operators, easily learnt in just a few hours, yet contains highly powerful ways to amplify and combine the building-block operations, like overloaded operators, function pointers and on-demand creation of extensive function chains.
For a quick example how Stringle looks like, this line of code:
b %.\c #c #:c
could be expanded to the following:
'''if''' b ''contain head reverse'' c '''then set''' ''curtail'' c '''to''' ''length tail'' c
that is, “delete the last character of <code>c</code> if it occurs in the string <code>b</code>”.
It is ideal as a replacement for ''sed'' or ''awk'' for creating and running text processing scripts and filters, or could also be used as the built-in macro language in larger applications.
The complete specification of Stringle can be consulted [https://esolangs.org/wiki/Stringle here].

View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:Stringle

1
Lang/Stringle/100-doors Symbolic link
View File

@ -0,0 +1 @@
../../Task/100-doors/Stringle

1
Lang/Stringle/Nth Symbolic link
View File

@ -0,0 +1 @@
../../Task/Nth/Stringle

View File

@ -0,0 +1 @@
../../Task/Reverse-a-string/Stringle

1
Lang/Stringle/Rot-13 Symbolic link
View File

@ -0,0 +1 @@
../../Task/Rot-13/Stringle

1
Lang/Stringle/String-length Symbolic link
View File

@ -0,0 +1 @@
../../Task/String-length/Stringle

View File

@ -0,0 +1 @@
../../Task/Strip-a-set-of-characters-from-a-string/Stringle

View File

@ -0,0 +1,6 @@
{{stub}}{{language|TI BASIC}}
TI BASIC is the language included in the TI-99/4 (1979) and TI-99/4A (1981) computers. It is similar to Dartmouth BASIC 6th edition. It does not have some features in Microsoft BASIC such as multi-statement lines, other statements after IF..THEN, PEEK, POKE, and USR. It's capabilites are between those of Minimal BASIC and GW-BASIC. It is slower than the BASIC in most other computers but it has high accuracy for calculations.
It can be used to read and write data files on disk but it is not ideal for reading text files (known as DISPLAY/VARIABLE 80 in the TI file system) because the INPUT #X statement would stop reading a line before the end if it contained a comma. This problem was solved with TI Extended BASIC by the addition of the LINPUT #X statement which is like LINE INPUT# in Microsoft Disk BASIC.
Many TI-99/4A owners had a TI Extended BASIC cartridge to write or use more advanced programs, including assembly language programs. Almost all TI BASIC programs would run correctly in TI Extended BASIC.

View File

@ -0,0 +1,2 @@
---
from: http://rosettacode.org/wiki/Category:TI_BASIC

View File

@ -0,0 +1 @@
../../Task/Colour-bars-Display/TI-BASIC

View File

@ -0,0 +1,26 @@
HOW TO INITIALIZE:
SHARE doors
PUT {} IN doors
FOR door IN {1..100}:
PUT 0 IN doors[door]
HOW TO TOGGLE door:
SHARE doors
PUT 1-doors[door] IN doors[door]
HOW TO WALK step:
SHARE doors
PUT step IN door
WHILE door <= 100:
TOGGLE door
PUT door+step IN door
HOW TO DISPLAY OPEN DOORS:
SHARE doors
FOR door IN {1..100}:
IF doors[door] = 1:
WRITE "Door", door, "is open"/
INITIALIZE
FOR pass IN {1..100}: WALK pass
DISPLAY OPEN DOORS

View File

@ -0,0 +1,15 @@
d "."
#d
i d
#i
p "door" #i
*p *p "."
i d f "oc"
i d #@f #*p
i d .\f "o" $ #i
i i d
#i +101 i ""
#i
d d "."
#d +101 d ""
#d

View File

@ -0,0 +1,40 @@
HOW TO FILL drawers:
PUT {} IN drawers
FOR i IN {1..100}: PUT i IN drawers[i]
FOR i IN {1..100}:
PUT choice {i..100} IN j
PUT drawers[i], drawers[j] IN drawers[j], drawers[i]
HOW TO REPORT prisoner random.strat drawers:
PUT {1..100} IN available
FOR turn IN {1..50}:
PUT choice available IN drawer
IF drawers[drawer] = prisoner: SUCCEED
REMOVE drawer FROM available
FAIL
HOW TO REPORT prisoner optimal.strat drawers:
PUT prisoner IN drawer
FOR turn IN {1..50}:
IF drawers[drawer] = prisoner: SUCCEED
PUT drawers[drawer] IN drawer
FAIL
HOW TO REPORT simulate strategy:
FILL drawers
FOR prisoner IN {1..100}:
SELECT:
strategy = "Random":
IF NOT prisoner random.strat drawers: FAIL
strategy = "Optimal":
IF NOT prisoner optimal.strat drawers: FAIL
SUCCEED
HOW TO RETURN n.sim chance.of.success strategy:
PUT 0 IN success
FOR n IN {1..n.sim}:
IF simulate strategy: PUT success+1 IN success
RETURN success * 100 / n.sim
FOR strategy IN {"Random"; "Optimal"}:
WRITE strategy, ": ", 10000 chance.of.success strategy, '%'/

View File

@ -0,0 +1,19 @@
HOW TO RETURN bottles n:
SELECT:
n<0: RETURN "99 bottles"
n=0: RETURN "No more bottles"
n=1: RETURN "1 bottle"
n>1: RETURN "`n` bottles"
HOW TO SING VERSE n:
WRITE "`bottles n` of beer on the wall,"/
WRITE "`bottles n` of beer,"/
SELECT:
n=0: WRITE "Go to the store and buy some more,"/
n=1: WRITE "Take it down and pass it around,"/
n>1: WRITE "Take one down and pass it around,"/
WRITE "`bottles (n-1)` of beer on the wall."/
WRITE /
FOR n IN {0..99}:
SING VERSE 99-n

View File

@ -0,0 +1,17 @@
HOW TO REPORT word can.be.made.with blocks:
FOR letter IN upper word:
IF NO block IN blocks HAS letter in block: FAIL
REMOVE block FROM blocks
SUCCEED
PUT {"BO";"XK";"DQ";"CP";"NA";"GT";"RE";"TG";"QD";"FS"} IN blocks
PUT {"JW";"HU";"VI";"AN";"OB";"ER";"FS";"LY";"PC";"ZM"} IN blocks2
FOR block IN blocks2: INSERT block IN blocks
PUT {"A";"BARK";"BOOK";"treat";"common";"Squad";"CoNfUsE"} IN words
FOR word IN words:
WRITE word, ": "
SELECT:
word can.be.made.with blocks: WRITE "yes"/
ELSE: WRITE "no"/

View File

@ -0,0 +1,28 @@
PUT 0 IN deficient
PUT 0 IN perfect
PUT 0 IN abundant
HOW TO FIND PROPER DIVISOR SUMS UP TO limit:
SHARE p
PUT {} IN p
FOR i IN {0..limit}: PUT 0 IN p[i]
FOR i IN {1..floor (limit/2)}:
PUT i+i IN j
WHILE j <= limit:
PUT p[j]+i IN p[j]
PUT j+i IN j
HOW TO CLASSIFY n:
SHARE deficient, perfect, abundant, p
SELECT:
p[n] < n: PUT deficient+1 IN deficient
p[n] = n: PUT perfect+1 IN perfect
p[n] > n: PUT abundant+1 IN abundant
PUT 20000 IN limit
FIND PROPER DIVISOR SUMS UP TO limit
FOR n IN {1..limit}: CLASSIFY n
WRITE deficient, "deficient"/
WRITE perfect, "perfect"/
WRITE abundant, "abundant"/

View File

@ -0,0 +1,10 @@
HOW TO RETURN m ack n:
SELECT:
m=0: RETURN n+1
m>0 AND n=0: RETURN (m-1) ack 1
m>0 AND n>0: RETURN (m-1) ack (m ack (n-1))
FOR m IN {0..3}:
FOR n IN {0..8}:
WRITE (m ack n)>>6
WRITE /

View File

@ -0,0 +1,20 @@
HOW TO REPORT prime n:
REPORT n>=2 AND NO d IN {2..floor root n} HAS n mod d = 0
HOW TO RETURN digit.sum n:
SELECT:
n<10: RETURN n
ELSE: RETURN (n mod 10) + digit.sum floor (n/10)
HOW TO REPORT additive.prime n:
REPORT prime n AND prime digit.sum n
PUT 0 IN n
FOR i IN {1..499}:
IF additive.prime i:
WRITE i>>4
PUT n+1 IN n
IF n mod 10 = 0: WRITE /
WRITE /
WRITE "There are `n` additive primes less than 500."/

View File

@ -0,0 +1,29 @@
package main
use core {printf}
main :: () -> void {
printf("\n");
for k in 1..6 {
printf("k = {}:", k);
i := 2;
c: i32;
while c < 10 {
if kprime(i, k) {
printf(" {}", i);
c += 1;
}
i += 1;
}
printf("\n");
}
}
kprime :: (n: i32, k: i32) -> bool {
f: i32;
while p := 2; f < k && p * p <= n {
while n % p == 0 {
n /= p;
f += 1;
}
p += 1;
}
return f + (1 if n > 1 else 0) == k;
}

View File

@ -0,0 +1,37 @@
//+optional-semicolons
use core {printf}
use core.iter
main :: () {
generator :=
iter.counter(1)
|> iter.map(k => .{
k = k, kprimes = kprime_iter(k)->take(10)
})
|> iter.take(5)
for val in generator {
printf("k = {}:", val.k)
for p in val.kprimes do printf(" {}", p)
printf("\n")
}
}
kprime_iter :: k =>
iter.counter(2)
|> iter.filter((i, [k]) => kprime(i, k))
kprime :: (n, k) => {
f := 0
for p in iter.counter(2) {
if f >= k do break
if p * p > n do break
while n % p == 0 {
n /= p
f += 1
}
}
return f + (1 if n > 1 else 0) == k
}

View File

@ -0,0 +1,17 @@
HOW TO RETURN proper.divisor.sum.table n:
PUT {} IN propdivs
FOR i IN {1..n}: PUT 1 IN propdivs[i]
FOR i IN {2..floor (n/2)}:
PUT i+i IN j
WHILE j<=n:
PUT propdivs[j] + i IN propdivs[j]
PUT i + j IN j
RETURN propdivs
PUT 20000 IN maximum
PUT proper.divisor.sum.table maximum IN propdivs
FOR cand IN {1..maximum}:
PUT propdivs[cand] IN other
IF cand<other<maximum AND propdivs[other]=cand:
WRITE cand, other/

View File

@ -0,0 +1,5 @@
THE_LIST( <apple> <orange> )
COUNT[ 0 SW ~| COUNT_STEP# 0 SW SU ]
COUNT_STEP[ DR 1 SU ]
`THE_LIST COUNT# +<>

View File

@ -0,0 +1,21 @@
HOW TO RETURN factors n:
PUT {} IN factors
PUT 2 IN factor
WHILE n >= factor:
SELECT:
n mod factor = 0:
INSERT factor IN factors
PUT n/factor IN n
ELSE:
PUT factor+1 IN factor
RETURN factors
HOW TO REPORT attractive n:
REPORT 1 = #factors #factors n
PUT 0 IN col
FOR i IN {1..120}:
IF attractive i:
WRITE i>>5
PUT col+1 IN col
IF col mod 10=0: WRITE /

View File

@ -0,0 +1,25 @@
HOW TO RETURN fibonacci.numbers n:
PUT 1, 1 IN a, b
PUT {} IN fibo
FOR i IN {1..n}:
INSERT a IN fibo
PUT b, a+b IN a, b
RETURN fibo
HOW TO RETURN digit.distribution nums:
PUT {} IN digits
FOR i IN {1..9}: PUT i IN digits["`i`"]
PUT {} IN dist
FOR i IN {1..9}: PUT 0 IN dist[i]
FOR n IN nums:
PUT digits["`n`"|1] IN digit
PUT dist[digit] + 1 IN dist[digit]
FOR i IN {1..9}:
PUT dist[i] / #nums IN dist[i]
RETURN dist
PUT digit.distribution fibonacci.numbers 1000 IN observations
WRITE "Digit"<<6, "Expected">>10, "Observed">>10/
FOR d IN {1..9}:
WRITE d<<6, ((10 log (1 + 1/d))>>10)|10, observations[d]>>10/

View File

@ -0,0 +1,62 @@
HOW TO RETURN random.digit:
RETURN choice "123456789"
HOW TO MAKE SECRET secret:
PUT "" IN secret
FOR i IN {1..4}:
PUT random.digit IN digit
WHILE SOME j IN {1..i-1} HAS secret item j = digit:
PUT random.digit IN digit
PUT secret^digit IN secret
HOW TO RETURN guess count.bulls secret:
PUT 0 IN bulls
FOR i IN {1..4}:
IF secret item i = guess item i: PUT bulls+1 IN bulls
RETURN bulls
HOW TO RETURN guess count.cows secret:
PUT -(guess count.bulls secret) IN cows
FOR c IN guess:
IF c in secret: PUT cows+1 IN cows
RETURN cows
HOW TO REPORT has.duplicates guess:
FOR i IN {1..3}:
FOR j IN {i+1..4}:
IF guess item i = guess item j: SUCCEED
FAIL
HOW TO REPORT is.valid guess:
IF SOME digit IN guess HAS digit not.in "123456789":
WRITE "Invalid digit: ", digit/
FAIL
IF #guess <> 4:
WRITE "Guess must contain 4 digits."/
FAIL
IF has.duplicates guess:
WRITE "No duplicates allowed"/
FAIL
SUCCEED
HOW TO READ GUESS guess:
WHILE 1=1:
WRITE "Guess? "
READ guess RAW
IF is.valid guess: QUIT
HOW TO PLAY BULLS AND COWS:
PUT 0, 0, 0 IN tries, bulls, cows
MAKE SECRET secret
WRITE "Bulls and cows"/
WRITE "--------------"/
WRITE /
WHILE bulls<>4:
READ GUESS guess
PUT guess count.bulls secret IN bulls
PUT guess count.cows secret IN cows
WRITE "Bulls:",bulls,"- Cows:",cows/
PUT tries+1 IN tries
WRITE "You win! Tries:", tries
PLAY BULLS AND COWS

View File

@ -0,0 +1,12 @@
\ casting out nines - based on the Action! sample
HOW TO ADD v TO n: PUT n + v IN n
PUT 10, 2, 0, 0 IN base, n, count, total
FOR i IN { 1 .. base ** n }:
ADD 1 TO total
IF i mod ( base - 1 ) = ( i * i ) mod ( base - 1 ):
ADD 1 TO count
WRITE i
WRITE // "Trying", count, "numbers instead of", total, "numbers saves"
WRITE 100 - ( ( 100 * count ) / total ), "%" /

View File

@ -0,0 +1,43 @@
100 REM SMPTE Format Color Bars
110 REM with 400 Hz reference tone
120 CALL CLEAR
130 CALL SCREEN(2)
140 CALL COLOR(8,15,1)
150 CALL COLOR(9,11,1)
160 CALL COLOR(10,8,1)
170 CALL COLOR(11,13,1)
180 CALL COLOR(12,14,1)
190 CALL COLOR(13,10,1)
200 CALL COLOR(14,5,1)
210 CALL COLOR(15,2,1)
220 CALL COLOR(16,16,1)
230 GOSUB 510
240 REM color bars
250 CALL VCHAR(1,3,88,96)
260 CALL VCHAR(1,7,96,96)
270 CALL VCHAR(1,11,104,96)
280 CALL VCHAR(1,15,112,96)
290 CALL VCHAR(1,19,120,96)
300 CALL VCHAR(1,23,128,96)
310 CALL VCHAR(1,27,136,96)
320 REM BLACK BAR
330 CALL HCHAR(19,1,144,224)
340 REM WHITE BOX
350 FOR I=19 TO 24
360 CALL HCHAR(I,8,152,6)
370 NEXT I
410 REM SMPTE Complementary boxes
420 CALL HCHAR(18,3,136,4)
430 CALL HCHAR(18,7,144,4)
440 CALL HCHAR(18,11,120,4)
450 CALL HCHAR(18,15,144,4)
460 CALL HCHAR(18,19,104,4)
470 CALL HCHAR(18,23,144,4)
480 CALL HCHAR(18,27,88,4)
490 CALL SOUND(3000,400,12)
500 GOTO 490
510 SQUARE$="FFFFFFFFFFFFFFFF"
520 FOR I = 88 TO 152 STEP 8
530 CALL CHAR(I,SQUARE$)
540 NEXT I
590 RETURN

View File

@ -0,0 +1,17 @@
HOW TO RETURN quibble words:
PUT "" IN result
PUT #words IN remaining
FOR word IN words:
PUT result^word IN result
PUT remaining-1 IN remaining
IF remaining = 1: PUT result^" and " IN result
IF remaining > 1: PUT result^", " IN result
RETURN "{" ^ result ^ "}"
PUT {} IN tests
INSERT {} IN tests
INSERT {[1]: "ABC"} IN tests
INSERT {[1]: "ABC"; [2]: "DEF"} IN tests
INSERT {[1]: "ABC"; [2]: "DEF"; [3]: "G"; [4]: "H"} IN tests
FOR test IN tests:
WRITE quibble test/

View File

@ -0,0 +1,11 @@
PUT 7 IN max.department.number
PUT 12 IN department.sum
WRITE "police sanitation fire" /
PUT 2 IN police
WHILE police <= max.department.number:
FOR sanitation IN { 1 .. max.department.number }:
IF sanitation <> police:
PUT ( department.sum - police ) - sanitation IN fire
IF fire > 0 AND fire <= max.department.number AND fire <> sanitation AND fire <> police:
WRITE police>>6, sanitation>>11, fire>>5 /
PUT police + 2 IN police

View File

@ -0,0 +1,39 @@
PUT "ABCDEFGHIJKLMNOPQRSTUVWXYZ " IN alphabet
HOW TO RETURN initial.state target:
SHARE alphabet
PUT "" IN state
FOR c IN target: PUT state^choice alphabet IN state
RETURN state
HOW TO RETURN state fitness target:
PUT #target IN score
FOR i IN {1..#target}:
IF state item i = target item i: PUT score-1 IN score
RETURN score
HOW TO RETURN chance mutate state:
SHARE alphabet
PUT "" IN mutated
FOR i IN {1..#state}:
SELECT:
random < chance: PUT choice alphabet IN next
ELSE: PUT state item i IN next
PUT mutated^next IN mutated
RETURN mutated
HOW TO EVOLVE TOWARD target:
PUT 0.1 IN mutation.rate
PUT 100 IN generation.size
PUT initial.state target IN state
WHILE state fitness target > 0:
WRITE (state fitness target)>>2, ": ", state/
PUT {} IN next.generation
FOR i IN {1..generation.size}:
PUT mutation.rate mutate state IN child
PUT child fitness target IN score
PUT child IN next.generation[score]
PUT next.generation[min keys next.generation] IN state
WRITE (state fitness target)>>2, ": ", state/
EVOLVE TOWARD "METHINKS IT IS LIKE A WEASEL"

View File

@ -0,0 +1,64 @@
use core.iter
use core { printf }
// Procedural Simple For-Loop Style
fib_for_loop :: (n: i32) -> i32 {
a: i32 = 0;
b: i32 = 1;
for 0 .. n {
tmp := a;
a = b;
b = tmp + b;
}
return a;
}
FibState :: struct { a, b: u64 }
// Functional Folding Style
fib_by_fold :: (n: i32) => {
end_state :=
iter.counter()
|> iter.take(n)
|> iter.fold(
FibState.{ a = 0, b = 1 },
(_, state) => FibState.{
a = state.b,
b = state.a + state.b
}
);
return end_state.a;
}
// Custom Iterator Style
fib_iterator :: (n: i32) =>
iter.generator(
&.{ a = cast(u64) 0, b = cast(u64) 1, counter = n },
(state: & $Ctx) -> (u64, bool) {
if state.counter <= 0 {
return 0, false;
}
tmp := state.a;
state.a = state.b;
state.b = state.b + tmp;
state.counter -= 1;
return tmp, true;
}
);
main :: () {
printf("\nBy For Loop:\n");
for i in 0 .. 21 {
printf("{} ", fib_for_loop(i));
}
printf("\n\nBy Iterator:\n");
for i in 0 .. 21 {
printf("{} ", fib_by_fold(i));
}
printf("\n\nBy Fold:\n");
for value, index in fib_iterator(21) {
printf("{} ", value);
}
}

View File

@ -0,0 +1,12 @@
HOW TO RETURN fizzbuzz num:
PUT "" IN result
PUT {[3]: "Fizz"; [5]: "Buzz"} IN divwords
FOR div IN keys divwords:
IF num mod div=0:
PUT result^divwords[div] IN result
IF result="":
PUT num>>0 IN result
RETURN result
FOR i IN {1..100}:
WRITE fizzbuzz i/

View File

@ -0,0 +1,19 @@
import gleam/int
import gleam/io
import gleam/iterator
pub fn main() {
iterator.range(1, 101)
|> iterator.map(to_fizzbuzz)
|> iterator.map(io.println)
|> iterator.run
}
fn to_fizzbuzz(n: Int) -> String {
case n % 3, n % 5 {
0, 0 -> "FizzBuzz"
0, _ -> "Fizz"
_, 0 -> "Buzz"
_, _ -> int.to_string(n)
}
}

View File

@ -0,0 +1,16 @@
use core { * }
fizzbuzz :: (len: u32) -> void {
for i in 1..len+1 {
msg : str;
if (i%3 == 0 && i%5 == 0) { msg = "FizzBuzz !!!"; }
elseif (i%3 == 0) { msg = "Fizz"; }
elseif (i%5 == 0) { msg = "Buzz"; }
else { msg = tprintf("{}", i); }
printf("{}\n", msg);
}
}
main :: () {
fizzbuzz(100);
}

View File

@ -0,0 +1,18 @@
HOW TO RETURN width n:
SELECT:
n<10: RETURN 1
ELSE: RETURN 1 + width floor (n/10)
HOW TO DISPLAY A FLOYD TRIANGLE WITH lines LINES:
PUT lines * (lines+1)/2 IN maxno
PUT 1 IN n
FOR line IN {1..lines}:
FOR col IN {1..line}:
WRITE n >> (1 + width (maxno - lines + col))
PUT n+1 IN n
WRITE /
DISPLAY A FLOYD TRIANGLE WITH 5 LINES
WRITE /
DISPLAY A FLOYD TRIANGLE WITH 14 LINES
WRITE /

View File

@ -0,0 +1,21 @@
HOW TO REPORT is.giuga n:
\ each prime factor must appear only once, e.g.: for 2:
\ [ ( n / 2 ) - 1 ] mod 2 = 0 => n / 2 is odd => n isn't divisible by 4
\ similarly for other primes
PUT 1, 3, 1, floor( n / 2 ) IN f.count, f, giuga, v
WHILE f <= v AND giuga = 1:
IF v mod f = 0:
PUT f.count + 1 IN f.count
IF ( ( floor( n / f ) ) - 1 ) mod f <> 0: PUT 0 IN giuga
PUT floor( v / f ) IN v
PUT f + 2 IN f
IF giuga = 1: \ n is still a candidate, check it is not prime
IF f.count = 1: FAIL \ only 1 factor - it is prime so not giuga
REPORT giuga = 1
PUT 0, -2 IN g.count, n
WHILE g.count < 4:
PUT n + 4 IN n \ assume the numbers are all even
IF is.giuga n:
PUT g.count + 1 IN g.count
WRITE n

View File

@ -0,0 +1,26 @@
package main
use core {*}
use core.math{abs}
use core.intrinsics.wasm{sqrt_f64}
main :: () {
iterate();
}
iterate :: () {
count := 0;
phi0: f64 = 1.0;
difference: f64 = 1.0;
phi1: f64;
println("\nGolden ratio/Convergence");
println("-----------------------------------------");
while 0.00001 < difference {
phi1 = 1.0 + (1.0 / phi0);
difference = abs(phi1 - phi0);
phi0 = phi1;
count += 1;
printf("Iteration {} : Estimate : {.8}\n", count, phi1);
}
println("-----------------------------------------");
printf("Result: {} after {} iterations", phi1, count);
printf("\nThe error is approximately {.8}\n", (phi1 - (0.5 * (1.0 + sqrt_f64(5.0)))));
println("\n");
}

View File

@ -0,0 +1,22 @@
HOW TO RETURN hailstone n:
PUT {} IN seq
WHILE 1=1:
PUT n IN seq[#seq]
SELECT:
n=1: RETURN seq
n mod 2=0: PUT floor(n/2) IN n
n mod 2=1: PUT 3*n+1 IN n
RETURN seq
PUT hailstone 27 IN h27
WRITE "Length of Hailstone sequence for 27:", #h27/
WRITE "First 4 elements:", h27[0], h27[1], h27[2], h27[3]/
WRITE "Last 4 elements:", h27[#h27-4], h27[#h27-3], h27[#h27-2], h27[#h27-1]/
PUT 0, 0 IN longest, length
FOR n IN {1..100000}:
PUT hailstone n IN hn
IF #hn > length:
PUT n, #hn IN longest, length
WRITE longest, "has the longest hailstone sequence < 100,000, of length:", length/

Some files were not shown because too many files have changed in this diff Show More