Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,122 @@
org 100h
lxi h,tests
test: mov b,m
inx h
dcr b
inr b
rz
lxi d,buf
call lincmb
push b
push h
mvi c,9
lxi d,buf
call 5
mvi c,9
lxi d,nl
call 5
pop h
pop b
jmp test
tests: db 3, 1, 2, 3
db 4, 0, 1, 2, 3
db 4, 1, 0, 3, 4
db 3, 1, 2, 0
db 3, 0, 0, 0
db 1, 0
db 3, 1, 1, 1
db 3, -1, -1, -1
db 4, -1, -2, 0, -3
db 1, -1
db 0
nl: db 13,10,'$'
; Write string representation of linear combination
; at [HL], of length B, to memory at [DE].
lincmb: push d
lxi d,1
lcstep: mov a,m
inx h
ora a
jz lcnxt
xthl
call lcsgn
ana a
jp lcchk
dcr a
cma
lcchk: cpi 1
jz lctrm
push b
call wrnum
pop b
mvi m,'*'
inx h
lctrm: mvi m,'e'
inx h
mvi m,'('
inx h
mov a,e
push b
call wrnum
pop b
mvi m,')'
inx h
inr d
xthl
lcnxt: inr e
dcr b
jnz lcstep
dcr d
inr d
pop d
xchg
jnz lcdone
mvi m,'0'
inx h
lcdone: mvi m,'$'
xchg
ret
lcsgn: dcr d
inr d
mvi c,'-'
jz lcsgnf
ana a
jm lcsgnw
mvi c,'+'
lcsgnw: mvi m,' '
inx h
mov m,c
inx h
mvi m,' '
inx h
ret
lcsgnf: ana a
rp
mov m,c
inx h
ret
; Write string representation of signed integer in A at [HL]
; Returns with HL pointing after the number
wrnum: ana a
jp wrdgt
mvi m,'-'
inx h
dcr a
cma
wrdgt: mvi b,-1
dgtlp: inr b
sui 10
jnc dgtlp
adi 58
mov c,a
mov a,b
ana a
push b
cnz wrdgt
pop b
mov m,c
inx h
ret
buf equ $

View file

@ -0,0 +1,54 @@
with Ada.Text_Io;
with Ada.Strings.Unbounded;
with Ada.Strings.Fixed;
procedure Display_Linear is
subtype Position is Positive;
type Coefficient is new Integer;
type Combination is array (Position range <>) of Coefficient;
function Linear_Combination (Comb : Combination) return String is
use Ada.Strings.Unbounded;
use Ada.Strings;
Accu : Unbounded_String;
begin
for Pos in Comb'Range loop
case Comb (Pos) is
when Coefficient'First .. -1 =>
Append (Accu, (if Accu = "" then "-" else " - "));
when 0 => null;
when 1 .. Coefficient'Last =>
Append (Accu, (if Accu /= "" then " + " else ""));
end case;
if Comb (Pos) /= 0 then
declare
Abs_Coeff : constant Coefficient := abs Comb (Pos);
Coeff_Image : constant String := Fixed.Trim (Coefficient'Image (Abs_Coeff), Left);
Exp_Image : constant String := Fixed.Trim (Position'Image (Pos), Left);
begin
if Abs_Coeff /= 1 then
Append (Accu, Coeff_Image & "*");
end if;
Append (Accu, "e(" & Exp_Image & ")");
end;
end if;
end loop;
return (if Accu = "" then "0" else To_String (Accu));
end Linear_Combination;
use Ada.Text_Io;
begin
Put_Line (Linear_Combination ((1, 2, 3)));
Put_Line (Linear_Combination ((0, 1, 2, 3)));
Put_Line (Linear_Combination ((1, 0, 3, 4)));
Put_Line (Linear_Combination ((1, 2, 0)));
Put_Line (Linear_Combination ((0, 0, 0)));
Put_Line (Linear_Combination ((1 => 0)));
Put_Line (Linear_Combination ((1, 1, 1)));
Put_Line (Linear_Combination ((-1, -1, -1)));
Put_Line (Linear_Combination ((-1, -2, 0, -3)));
Put_Line (Linear_Combination ((1 => -1)));
end Display_Linear;

View file

@ -0,0 +1,28 @@
function basisify(a) {
let terms = [];
for (let i = 0; i < a.length; i++) {
if (a[i] !== 0) {
terms.push(`${a[i]}*e(${i+1})`);
}
}
if (terms.length === 0) {
return "0";
}
terms = terms.map(s => s.replace("1*", ""));
return terms.join(" + ").replace("+ -", "- ");
}
const test_vectors = [[1, 2, 3],
[0, 1, 2, 3],
[1, 0, 3, 4],
[1, 2, 0],
[0, 0, 0],
[0],
[1, 1, 1],
[-1, -1, -1],
[-1, -2, 0, -3],
[-1]];
for (const s of test_vectors.map(basisify)){
console.log(s);
}

View file

@ -0,0 +1,20 @@
main :: [sys_message]
main = [Stdout (lay (map lincomb tests))]
where tests = [[1,2,3], [0,1,2,3], [1,0,3,4], [1,2,0], [0,0,0],
[0], [1,1,1], [-1,-1,-1], [-1,-2,0,-3], [-1]]
lincomb :: [num]->[char]
lincomb xs = "0", if result = ""
= result, otherwise
where result = foldl term "" (zip2 [1..] xs)
term r (i,0) = r
term "" (i,-1) = "-" ++ te i
term "" (i,1) = te i
term "" (i,n) = "-" ++ show (abs n) ++ "*" ++ te i, if n<0
= show n ++ "*" ++ te i, otherwise
term r (i,-1) = r ++ " - " ++ te i
term r (i,1) = r ++ " + " ++ te i
term r (i,n) = r ++ sgn ++ show (abs n) ++ "*" ++ te i
where sgn = " - ", if n<0
= " + ", otherwise
te n = "e(" ++ shownum n ++ ")"

View file

@ -0,0 +1,44 @@
Rebol [
title: "Rosetta code: Display a linear combination"
file: %Display_a_linear_combination.r3
url: https://rosettacode.org/wiki/Display_a_linear_combination
needs: 3.10.0 ;; or something like that (pad/ajoin)
]
display-linear-combination: function [
vec [block! vector!] "Vector of coefficients"
][
terms: copy ""
repeat i length? vec [
coeff: vec/:i
if coeff <> 0 [
;; build "c * e(k)" term
append terms ajoin [
unless empty? terms [" + "]
pad coeff -2
" * e(" i ")"
]
]
]
print ajoin [
pad mold vec -15 ;; padded input
" -> "
terms
]
]
;; Test output...
foreach v [
[1 2 3]
[0 1 2 3]
[1 0 3 4]
[1 2 0]
[0 0 0]
[0]
[1 1 1]
[-1 -1 -1]
[-1 -2 0 -3]
[-1]
][
display-linear-combination v
]

View file

@ -0,0 +1,56 @@
$ENTRY Go {
= <Each Show <Tests>>;
};
Tests {
= ((1) (2) (3))
((0) (1) (2) (3))
((1) (0) (3) (4))
((1) (2) (0))
((0) (0) (0))
((0))
((1) (1) (1))
(('-'1) ('-'1) ('-'1))
(('-'1) ('-'2) (0) (3))
(('-'1));
};
Each {
s.F = ;
s.F (e.X) e.Y = <Mu s.F e.X> <Each s.F e.Y>;
};
Show {
e.X = <Prout <LinearCombination e.X>>;
};
LinearCombination {
e.X, <LC1 T 1 e.X>: {
= '0';
e.Y = e.Y;
};
};
LC1 {
s.F s.N = ;
s.F s.N (e.X) e.Y, <LCTerm s.F s.N e.X>: {
= <LC1 s.F <Add 1 s.N> e.Y>;
e.Z = e.Z <LC1 F <Add 1 s.N> e.Y>;
};
};
LCTerm {
s.F s.N 0 = ;
s.F s.N e.M = <LCMult s.F e.M> '(' <Symb s.N> ')';
};
LCMult {
T '-' 1 = '-e';
T '-' s.M = '-' <Symb s.M> '*e';
T 1 = 'e';
T s.M = <Symb s.M> '*e';
F '-' 1 = ' - e';
F '-' s.M = ' - ' <Symb s.M> '*e';
F 1 = ' + e';
F s.M = ' + ' <Symb s.M> '*e';
};