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,43 +0,0 @@
with Ada.Command_Line, Ada.Text_IO;
procedure Josephus is
function Arg(Index, Default: Positive) return Natural is -- read Argument(Index)
(if Ada.Command_Line.Argument_Count >= Index
then Natural'Value(Ada.Command_Line.Argument(Index)) else Default);
Prisoners: constant Positive := Arg(Index => 1, Default => 41);
Steps: constant Positive := Arg(Index => 2, Default => 3);
Survivors: constant Positive := Arg(Index => 3, Default => 1);
Print: Boolean := (Arg(Index => 4, Default => 1) = 1);
subtype Index_Type is Natural range 0 .. Prisoners-1;
Next: array(Index_Type) of Index_Type;
X: Index_Type := (Steps-2) mod Prisoners;
begin
Ada.Text_IO.Put_Line
("N =" & Positive'Image(Prisoners) & ", K =" & Positive'Image(Steps) &
(if Survivors > 1 then ", #survivors =" & Positive'Image(Survivors)
else ""));
for Index in Next'Range loop -- initialize Next
Next(Index) := (Index+1) mod Prisoners;
end loop;
if Print then
Ada.Text_IO.Put("Executed: ");
end if;
for Execution in reverse 1 .. Prisoners loop
if Execution = Survivors then
Ada.Text_IO.New_Line;
Ada.Text_IO.Put("Surviving: ");
Print := True;
end if;
if Print then
Ada.Text_IO.Put(Positive'Image(Next(X)));
end if;
Next(X) := Next(Next(X)); -- "delete" a prisoner
for Prisoner in 1 .. Steps-1 loop
X := Next(X);
end loop;
end loop;
end Josephus;

View file

@ -1,5 +1,5 @@
josephus: function [n,k][
p: new 0..n-1
p: @ 0..n-1
i: 0
seq: []

View file

@ -1,9 +0,0 @@
(defun jo (n k)
(if (= 1 n)
1
(1+ (% (+ (1- k)
(jo (1- n) k))
n))))
(message "%d" (jo 50 2))
(message "%d" (jo 60 3))

View file

@ -1,20 +0,0 @@
function Get-JosephusPrisoners ( [int]$N, [int]$K )
{
# Just for convenience
$End = $N - 1
# Create circle of prisoners
$Prisoners = New-Object System.Collections.ArrayList ( , (0..$End) )
# For each starting point of the reducing circle...
ForEach ( $Start in 0..($End - 1) )
{
# We subtract one from K for the one we advanced by incrementing $Start
# Then take K modulus the length of the remaining circle
$RoundK = ( $K - 1 ) % ( $End - $Start + 1 )
# Rotate the remaining prisoners K places around the remaining circle
$Prisoners.SetRange( $Start, $Prisoners[ $Start..$End ][ ( $RoundK + $Start - $End - 1 )..( $RoundK - 1 ) ] )
}
return $Prisoners
}

View file

@ -1,12 +0,0 @@
# Get the prisoner order for a circle of 41 prisoners, selecting every third
$Prisoners = Get-JosephusPrisoners -N 41 -K 3
# Display the prisoner order
$Prisoners -join " "
# Display the last remaining prisoner
"Last prisoner remmaining: " + $Prisoners[-1]
# Display the last three remaining prisoners
$S = 3
"Last $S remaining: " + $Prisoners[-$S..-1]

View file

@ -1,13 +0,0 @@
Rebol []
execute: func [death-list [block!] kill [integer!]] [
assert [not empty? death-list]
until [
loop kill - 1 [append death-list take death-list]
(1 == length? remove death-list)
]
]
prisoner: [] for n 0 40 1 [append prisoner n]
execute prisoner 3
print ["Prisoner" prisoner "survived"]

View file

@ -1,3 +0,0 @@
for-the-chop: [Joe Jack William Averell Rantanplan]
execute for-the-chop 2
print [for-the-chop "survived"]

View file

@ -1,32 +0,0 @@
Function josephus(n,k,s)
Set prisoner = CreateObject("System.Collections.ArrayList")
For i = 0 To n - 1
prisoner.Add(i)
Next
index = -1
Do Until prisoner.Count = s
step_count = 0
Do Until step_count = k
If index+1 <= prisoner.Count-1 Then
index = index+1
Else
index = (index+1)-(prisoner.Count)
End If
step_count = step_count+1
Loop
prisoner.RemoveAt(index)
index = index-1
Loop
For j = 0 To prisoner.Count-1
If j < prisoner.Count-1 Then
josephus = josephus & prisoner(j) & ","
Else
josephus = josephus & prisoner(j)
End If
Next
End Function
'testing the function
WScript.StdOut.WriteLine josephus(5,2,1)
WScript.StdOut.WriteLine josephus(41,3,1)
WScript.StdOut.WriteLine josephus(41,3,3)