Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,46 +0,0 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
procedure Range_Extraction is
type Sequence is array (Positive range <>) of Integer;
function Image (S : Sequence) return String is
Result : Unbounded_String;
From : Integer;
procedure Flush (To : Integer) is
begin
if Length (Result) > 0 then
Append (Result, ',');
end if;
Append (Result, Trim (Integer'Image (From), Ada.Strings.Left));
if From < To then
if From+1 = To then
Append (Result, ',');
else
Append (Result, '-');
end if;
Append (Result, Trim (Integer'Image (To), Ada.Strings.Left));
end if;
end Flush;
begin
if S'Length > 0 then
From := S (S'First);
for I in S'First + 1..S'Last loop
if S (I - 1) + 1 /= S (I) then
Flush (S (I - 1));
From := S (I);
end if;
end loop;
Flush (S (S'Last));
end if;
return To_String (Result);
end Image;
begin
Put_Line
( Image
( ( 0, 1, 2, 4, 6, 7, 8, 11, 12, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 28, 29, 30, 31, 32, 33, 35, 36,
37, 38, 39
) ) );
end Range_Extraction;

View file

@ -1,45 +0,0 @@
with Ada.Text_IO, Ada.Strings.Fixed;
procedure Range_Extract is
type Sequence is array (Positive range <>) of Integer;
function Img(I: Integer) return String is -- the image of an Integer
begin
return
Ada.Strings.Fixed.Trim(Integer'Image(I), Ada.Strings.Left);
end Img;
function Img(S: Sequence) return String is -- the image of a Sequence
function X(S : Sequence) return String is -- recursive eXtract
Idx: Positive := S'First;
begin
if S'Length = 0 then return
""; -- return nothing if Sequence is empty
else
while Idx < S'Last and then S(Idx+1) = S(Idx) + 1 loop
Idx := Idx + 1;
end loop;
if Idx = S'First then return
"," & Img(S(Idx)) & X(S(Idx+1 .. S'Last));
elsif Idx = S'First+1 then return
"," & Img(S(S'First)) & ',' & Img(S(Idx)) & X(S(Idx+1 .. S'Last));
else return
"," & Img(S(S'First)) & '-' & Img(S(Idx)) & X(S(Idx+1 .. S'Last));
end if;
end if;
end X;
begin -- function Img(S: Sequence) return String
if S'Length = 0 then return
"";
else return
Img(S(S'First)) & X(S(S'First+1 .. S'Last));
end if;
end Img;
begin -- main
Ada.Text_IO.Put_Line(Img( ( 0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29,
30, 31, 32, 33, 35, 36, 37, 38, 39) ));
end Range_Extract;

View file

@ -12,10 +12,11 @@ extractRange: function [inp][
i: i + 1
]
lst: items\[i]
case [(lst-fst)=]
when? -> 0 -> 'ranges ++ ~"|fst|"
when? -> 1 -> 'ranges ++ ~"|fst|, |lst|"
else -> 'ranges ++ ~"|fst|-|lst|"
'ranges ++ case lst-fst [
0 -> ~"|fst|"
1 -> ~"|fst|, |lst|"
any -> ~"|fst|-|lst|"
]
i: i + 1
]

View file

@ -1,180 +0,0 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. extract-range-task.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 data-str PIC X(200) VALUE "0, 1, 2, 4, 6,"
& " 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, "
& "24, 25, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39".
01 result PIC X(200).
PROCEDURE DIVISION.
CALL "extract-range" USING CONTENT data-str, REFERENCE result
DISPLAY FUNCTION TRIM(result)
GOBACK
.
END PROGRAM extract-range-task.
IDENTIFICATION DIVISION.
PROGRAM-ID. extract-range.
DATA DIVISION.
LOCAL-STORAGE SECTION.
COPY "nums-table.cpy".
01 difference PIC 999.
01 rng-begin PIC S999.
01 rng-end PIC S999.
01 num-trailing PIC 999.
01 trailing-comma-pos PIC 999.
LINKAGE SECTION.
01 nums-str PIC X(200).
01 extracted-range PIC X(200).
01 extracted-range-len CONSTANT LENGTH extracted-range.
PROCEDURE DIVISION USING nums-str, extracted-range.
CALL "split-nums" USING CONTENT nums-str, ", ",
REFERENCE nums-table
*> Process the table
MOVE nums (1) TO rng-begin
PERFORM VARYING nums-idx FROM 2 BY 1
UNTIL num-nums < nums-idx
SUBTRACT nums (nums-idx - 1) FROM nums (nums-idx)
GIVING difference
*> If number is more than one away from the previous one
*> end the range and start a new one.
IF difference > 1
MOVE nums (nums-idx - 1) TO rng-end
CALL "add-next-range" USING CONTENT rng-begin,
rng-end, REFERENCE extracted-range
MOVE nums (nums-idx) TO rng-begin
END-IF
END-PERFORM
*> Process the last number
MOVE nums (num-nums) TO rng-end
CALL "add-next-range" USING CONTENT rng-begin,
rng-end, REFERENCE extracted-range
*> Remove trailing comma.
CALL "find-num-trailing-spaces"
USING CONTENT extracted-range, REFERENCE num-trailing
COMPUTE trailing-comma-pos =
extracted-range-len - num-trailing
MOVE SPACE TO extracted-range (trailing-comma-pos:1)
GOBACK
.
IDENTIFICATION DIVISION.
PROGRAM-ID. split-nums INITIAL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 num-len PIC 9.
01 next-num-pos PIC 999.
LINKAGE SECTION.
01 str PIC X(200).
01 delim PIC X ANY LENGTH.
COPY "nums-table.cpy".
PROCEDURE DIVISION USING str, delim, nums-table.
INITIALIZE num-nums
PERFORM UNTIL str = SPACES
INITIALIZE num-len
INSPECT str TALLYING num-len FOR CHARACTERS BEFORE delim
ADD 1 TO num-nums
*> If there are no more instances of delim in the string,
*> add the rest of the string to the last element of the
*> table.
IF num-len = 0
MOVE str TO nums (num-nums)
EXIT PERFORM
ELSE
MOVE str (1:num-len) TO nums (num-nums)
ADD 3 TO num-len GIVING next-num-pos
MOVE str (next-num-pos:) TO str
END-IF
END-PERFORM
.
END PROGRAM split-nums.
IDENTIFICATION DIVISION.
PROGRAM-ID. add-next-range INITIAL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 num-trailing PIC 999.
01 start-pos PIC 999.
01 range-len PIC 999.
01 begin-edited PIC -ZZ9.
01 end-edited PIC -ZZ9.
LINKAGE SECTION.
01 rng-begin PIC S999.
01 rng-end PIC S999.
01 extracted-range PIC X(200).
01 extracted-range-len CONSTANT LENGTH extracted-range.
PROCEDURE DIVISION USING rng-begin, rng-end, extracted-range.
CALL "find-num-trailing-spaces"
USING CONTENT extracted-range, REFERENCE num-trailing
COMPUTE start-pos = extracted-range-len - num-trailing + 1
SUBTRACT rng-begin FROM rng-end GIVING range-len
MOVE rng-begin TO begin-edited
MOVE rng-end TO end-edited
EVALUATE TRUE
WHEN rng-begin = rng-end
STRING FUNCTION TRIM(begin-edited), ","
INTO extracted-range (start-pos:)
WHEN range-len = 1
STRING FUNCTION TRIM(begin-edited), ",",
FUNCTION TRIM(end-edited), ","
INTO extracted-range (start-pos:)
WHEN OTHER
STRING FUNCTION TRIM(begin-edited), "-",
FUNCTION TRIM(end-edited), ","
INTO extracted-range (start-pos:)
END-EVALUATE
.
END PROGRAM add-next-range.
IDENTIFICATION DIVISION.
PROGRAM-ID. find-num-trailing-spaces.
DATA DIVISION.
LINKAGE SECTION.
01 str PIC X(200).
01 num-trailing PIC 999.
PROCEDURE DIVISION USING str, num-trailing.
INITIALIZE num-trailing
INSPECT str TALLYING num-trailing FOR TRAILING SPACES
.
END PROGRAM find-num-trailing-spaces.
END PROGRAM extract-range.

View file

@ -1,6 +0,0 @@
01 nums-table.
03 num-nums PIC 999.
03 nums-area.
05 nums PIC S999 OCCURS 1 TO 100 TIMES
DEPENDING ON num-nums
INDEXED BY nums-idx.

View file

@ -1,17 +0,0 @@
(require 'gnus-range)
(defun rangext (lst)
(mapconcat (lambda (item)
(if (consp item)
(if (= (+ 1 (car item)) (cdr item))
(format "%d,%d" (car item) (cdr item))
(format "%d-%d" (car item) (cdr item)))
(format "%d" item)))
(gnus-compress-sequence lst)
","))
(rangext '(0 1 2 4 6 7 8 11 12 14
15 16 17 18 19 20 21 22 23 24
25 27 28 29 30 31 32 33 35 36
37 38 39))
;; => "0-2,4,6-8,11,12,14-25,27-33,35-39"

View file

@ -1,31 +0,0 @@
(defun split-into-ranges (numbers)
(let* ((last-number (pop numbers))
(range (list last-number))
ranges)
(dolist (n numbers)
(if (= n (1+ last-number))
(push n range)
(push (nreverse range) ranges)
(setq range (list n)))
(setq last-number n))
(nreverse (cons (nreverse range) ranges))))
(defun format-range (range)
(cond
((not range)
(error "invalid range"))
((= (length range) 1)
(number-to-string (car range)))
((= (length range) 2)
(format "%d,%d" (car range) (cadr range)))
(t
(format "%d-%d" (car range) (car (last range))))))
(defun rangext (numbers)
(mapconcat #'format-range (split-into-ranges numbers) ","))
(rangext '(0 1 2 4 6 7 8 11 12 14
15 16 17 18 19 20 21 22 23 24
25 27 28 29 30 31 32 33 35 36
37 38 39))
;; => "0-2,4,6-8,11,12,14-25,27-33,35-39"

View file

@ -1,32 +0,0 @@
function extract_ranges(sequence s)
integer first
sequence out
out = ""
if length(s) = 0 then
return out
end if
first = 1
for i = 2 to length(s) do
if s[i] != s[i-1]+1 then
if first = i-1 then
out &= sprintf("%d,", s[first])
elsif first = i-2 then
out &= sprintf("%d,%d,", {s[first],s[i-1]})
else
out &= sprintf("%d-%d,", {s[first],s[i-1]})
end if
first = i
end if
end for
if first = length(s) then
out &= sprintf("%d", s[first])
elsif first = length(s)-1 then
out &= sprintf("%d,%d", {s[first],s[$]})
else
out &= sprintf("%d-%d", {s[first],s[$]})
end if
return out
end function
puts(1, extract_ranges({0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39}))

View file

@ -1,30 +0,0 @@
function range-extraction($arr) {
if($arr.Count -gt 2) {
$a, $b, $c, $arr = $arr
$d = $e = $c
if((($a + 1) -eq $b) -and (($b + 1) -eq $c)) {
$test = $true
while($arr -and $test) {
$d = $e
$e, $arr = $arr
$test = ($d+1) -eq $e
}
if($test){"$a-$e"}
elseif((-not $arr) -and $test){"$a-$d"}
elseif(-not $arr){"$a-$d,$e"}
else{"$a-$d," + (range-extraction (@($e)+$arr))}
}
elseif(($b + 1) -eq $c) {"$a," + (range-extraction (@($b, $c)+$arr))}
else {"$a,$b," + (range-extraction (@($c)+$arr))}
} else {
switch($arr.Count) {
0 {""}
1 {"$arr"}
2 {"$($arr[0]),$($arr[1])"}
}
}
}
range-extraction @(0, 1, 2, 4, 6, 7, 8, 11, 12, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 27, 28, 29, 30, 31, 32, 33, 35, 36,
37, 38, 39)

View file

@ -1,41 +0,0 @@
Function Range_Extraction(list)
num = Split(list,",")
For i = 0 To UBound(num)
startnum = CInt(num(i))
sum = startnum
Do While i <= UBound(num)
If sum = CInt(num(i)) Then
If i = UBound(num) Then
If startnum <> CInt(num(i)) Then
If startnum + 1 = CInt(num(i)) Then
Range_Extraction = Range_Extraction & startnum & "," & num(i) & ","
Else
Range_Extraction = Range_Extraction & startnum & "-" & num(i) & ","
End If
Else
Range_Extraction = Range_Extraction & startnum & ","
End If
Exit Do
Else
i = i + 1
sum = sum + 1
End If
Else
If startnum = CInt(num(i-1)) Then
Range_Extraction = Range_Extraction & startnum & ","
Else
If startnum + 1 = CInt(num(i-1)) Then
Range_Extraction = Range_Extraction & startnum & "," & num(i-1) & ","
Else
Range_Extraction = Range_Extraction & startnum & "-" & num(i-1) & ","
End If
End If
i = i - 1
Exit Do
End If
Loop
Next
Range_Extraction = Left(Range_Extraction,Len(Range_Extraction)-1)
End Function
WScript.StdOut.Write Range_Extraction("0,1,2,4,6,7,8,11,12,14,15,16,17,18,19,20,21,22,23,24,25,27,28,29,30,31,32,33,35,36,37,38,39")