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,28 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Lcm_Test is
function Gcd (A, B : Integer) return Integer is
M : Integer := A;
N : Integer := B;
T : Integer;
begin
while N /= 0 loop
T := M;
M := N;
N := T mod N;
end loop;
return M;
end Gcd;
function Lcm (A, B : Integer) return Integer is
begin
if A = 0 or B = 0 then
return 0;
end if;
return abs (A) * (abs (B) / Gcd (A, B));
end Lcm;
begin
Put_Line ("LCM of 12, 18 is" & Integer'Image (Lcm (12, 18)));
Put_Line ("LCM of -6, 14 is" & Integer'Image (Lcm (-6, 14)));
Put_Line ("LCM of 35, 0 is" & Integer'Image (Lcm (35, 0)));
end Lcm_Test;

View file

@ -0,0 +1,13 @@
Func _LCM($a, $b)
Local $c, $f, $m = $a, $n = $b
$c = 1
While $c <> 0
$f = Int($a / $b)
$c = $a - $b * $f
If $c <> 0 Then
$a = $b
$b = $c
EndIf
WEnd
Return $m * $n / $b
EndFunc ;==>_LCM

View file

@ -0,0 +1,3 @@
ConsoleWrite(_LCM(12,18) & @LF)
ConsoleWrite(_LCM(-5,12) & @LF)
ConsoleWrite(_LCM(13,0) & @LF)

View file

@ -0,0 +1,63 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. show-lcm.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION lcm
.
PROCEDURE DIVISION.
DISPLAY "lcm(35, 21) = " FUNCTION lcm(35, 21)
GOBACK
.
END PROGRAM show-lcm.
IDENTIFICATION DIVISION.
FUNCTION-ID. lcm.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION gcd
.
DATA DIVISION.
LINKAGE SECTION.
01 m PIC S9(8).
01 n PIC S9(8).
01 ret PIC S9(8).
PROCEDURE DIVISION USING VALUE m, n RETURNING ret.
COMPUTE ret = FUNCTION ABS(m * n) / FUNCTION gcd(m, n)
GOBACK
.
END FUNCTION lcm.
IDENTIFICATION DIVISION.
FUNCTION-ID. gcd.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 temp PIC S9(8).
01 x PIC S9(8).
01 y PIC S9(8).
LINKAGE SECTION.
01 m PIC S9(8).
01 n PIC S9(8).
01 ret PIC S9(8).
PROCEDURE DIVISION USING VALUE m, n RETURNING ret.
MOVE m to x
MOVE n to y
PERFORM UNTIL y = 0
MOVE x TO temp
MOVE y TO x
MOVE FUNCTION MOD(temp, y) TO Y
END-PERFORM
MOVE FUNCTION ABS(x) TO ret
GOBACK
.
END FUNCTION gcd.

View file

@ -0,0 +1 @@
7.lcm 8 #=> 56

View file

@ -0,0 +1,13 @@
function gcd(integer m, integer n)
integer tmp
while m do
tmp = m
m = remainder(n,m)
n = tmp
end while
return n
end function
function lcm(integer m, integer n)
return m / gcd(m, n) * n
end function

View file

@ -0,0 +1,7 @@
local int = require "int"
local fmt = require "fmt"
local xys = {{12, 18}, {-6, 14}, {35, 0}}
for xys as xy do
local [x, y] = xy
fmt.print("lcm(%2d, %2d) = %d", x, y, int.lcm(x, y))
end

View file

@ -0,0 +1,16 @@
function gcd ($a, $b) {
function pgcd ($n, $m) {
if($n -le $m) {
if($n -eq 0) {$m}
else{pgcd $n ($m-$n)}
}
else {pgcd $m $n}
}
$n = [Math]::Abs($a)
$m = [Math]::Abs($b)
(pgcd $n $m)
}
function lcm ($a, $b) {
[Math]::Abs($a*$b)/(gcd $a $b)
}
lcm 12 18

View file

@ -0,0 +1,16 @@
function gcd ($a, $b) {
function pgcd ($n, $m) {
if($n -le $m) {
if($n -eq 0) {$m}
else{pgcd $n ($m%$n)}
}
else {pgcd $m $n}
}
$n = [Math]::Abs($a)
$m = [Math]::Abs($b)
(pgcd $n $m)
}
function lcm ($a, $b) {
[Math]::Abs($a*$b)/(gcd $a $b)
}
lcm 12 18

View file

@ -1,17 +1,29 @@
Procedure GCDiv(a, b); Euclidean algorithm
Protected r
While b
r = b
b = a%b
a = r
Wend
ProcedureReturn a
Procedure GCDiv(a.q, b.q); Euclidean algorithm
a = Abs(a)
b = Abs(b)
If a = 0
ProcedureReturn b
ElseIf b = 0
ProcedureReturn a
Else
Protected r.q
While b
r = b
b = a % b
a = r
Wend
ProcedureReturn a
EndIf
EndProcedure
Procedure LCM(m,n)
Protected t
If m And n
t=m*n/GCDiv(m,n)
Procedure LCM(m.d, n.d)
m = Abs(m)
n = Abs(n)
If m = 0
ProcedureReturn n
ElseIf n = 0
ProcedureReturn m
Else
ProcedureReturn m / GCDiv(m, n) * n
EndIf
ProcedureReturn t*Sign(t)
EndProcedure

View file

@ -0,0 +1,30 @@
Function LCM(a,b)
LCM = POS((a * b)/GCD(a,b))
End Function
Function GCD(a,b)
Do
If a Mod b > 0 Then
c = a Mod b
a = b
b = c
Else
GCD = b
Exit Do
End If
Loop
End Function
Function POS(n)
If n < 0 Then
POS = n * -1
Else
POS = n
End If
End Function
i = WScript.Arguments(0)
j = WScript.Arguments(1)
WScript.StdOut.Write "The LCM of " & i & " and " & j & " is " & LCM(i,j) & "."
WScript.StdOut.WriteLine