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,75 +0,0 @@
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
with Ada.Numerics.Discrete_Random;
procedure NumberReverse is
subtype RandRange is Integer range 1..9;
type NumArrayType is array (Integer range 1..9) of Integer;
package RandNumbers is new Ada.Numerics.Discrete_Random(RandRange);
use RandNumbers;
G : Generator;
procedure FillArray (A : in out NumArrayType) is
Temp : RandRange;
begin
A := (others => 0);
for I in 1..9 loop
Temp := Random(G);
while A(Temp) /= 0 loop
Temp := Random(G);
end loop;
A(Temp) := I;
end loop;
end FillArray;
procedure Put(A : in NumArrayType) is
begin
for I in 1..9 loop
Put(A(I), 0);
Put(" ");
end loop;
end Put;
procedure Prompt (Index : out Integer) is
begin
New_Line;
Put("How many numbers would you like to reverse: ");
Get(Index);
end Prompt;
procedure ReverseArray(Arr : in out NumArrayType;
Index : in Integer) is
Temp : RandRange;
begin
for I in 1..Index/2 loop
Temp := Arr(I);
Arr(I) := Arr(Index + 1 - I);
Arr(Index + 1 - I) := Temp;
end loop;
end ReverseArray;
Sorted : constant NumArrayType := (1,2,3,4,5,6,7,8,9);
Arr : NumArrayType;
Index : Integer;
Count : Integer := 0;
begin
Reset(G);
loop
FillArray(Arr);
exit when Sorted /= Arr;
end loop;
loop
Put(Arr);
Prompt(Index);
Count := Count + 1;
ReverseArray(Arr, Index);
exit when Sorted = Arr;
end loop;
Put(Arr);
New_Line;
Put("Congratulations! You win. It took " &
Integer'Image(Count) & " tries.");
end NumberReverse;

View file

@ -1,115 +0,0 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. REVERSAL.
AUTHOR. Bill Gunshannon
INSTALLATION. Home.
DATE-WRITTEN. 11 December 2021
****************************************************************
** Program Abstract:
** Use a Knuth Shuffle to reate our out ot sort array.
** Use a procedure called "reverse" to pancake sort the array.
****************************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RNUM PIC 9.
01 TRIES PIC 99 VALUE 0.
01 ANSWER PIC 9(9) VALUE 123456789.
01 TBL-LEN PIC 9 VALUE 9.
01 TBL.
05 TZ PIC 9(9).
05 TA REDEFINES TZ
PIC 9 OCCURS 9 TIMES.
PROCEDURE DIVISION.
MAIN-pROGRAM.
MOVE ANSWER TO TBL
CALL 'KNUTH-SHUFFLE'
USING BY REFERENCE TBL
END-CALL.
DISPLAY "TABLE after shuffle: " TBL.
PERFORM UNTIL TBL = ANSWER
ADD 1 TO TRIES
DISPLAY "How many to reverse? "
ACCEPT RNUM
CALL 'REVERSE' USING BY CONTENT RNUM,
BY REFERENCE TBL
END-CALL
DISPLAY "Try #" TRIES " " TBL
END-PERFORM.
DISPLAY "Congratulations. You did it!"
STOP RUN.
END PROGRAM REVERSAL.
IDENTIFICATION DIVISION.
PROGRAM-ID. KNUTH-SHUFFLE.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 I PIC 9(9).
01 J PIC 9(9).
01 TEMP PIC 9(9).
01 tABLE-lEN PIC 9 value 9.
LINKAGE SECTION.
01 TTABLE-AREA.
03 TTABLE PIC 9 OCCURS 9 TIMES.
PROCEDURE DIVISION USING ttable-area.
MOVE FUNCTION RANDOM(FUNCTION CURRENT-DATE (11:6)) TO I
PERFORM VARYING i FROM Table-Len BY -1 UNTIL i = 0
COMPUTE j =
FUNCTION MOD(FUNCTION RANDOM * 10000, Table-Len) + 1
MOVE ttable (i) TO temp
MOVE ttable (j) TO ttable (i)
MOVE temp TO ttable (j)
END-PERFORM.
GOBACK.
END PROGRAM KNUTH-SHUFFLE.
IDENTIFICATION DIVISION.
PROGRAM-ID. REVERSE.
DATA DIVISION.
LOCAL-STORAGE SECTION.
01 I PIC 9.
01 J PIC 9.
01 X PIC 9.
01 LOOP-IDX PIC 9.
LINKAGE SECTION.
01 IDX PIC 9.
01 TTABLE-AREA.
03 TTABLE PIC 9 OCCURS 9 TIMES.
PROCEDURE DIVISION USING IDX, TTABLE-AREA.
DIVIDE IDX BY 2 GIVING LOOP-IDx
MOVE 1 TO I
MOVE IDX TO J
PERFORM LOOP-IDX TIMES
MOVE TTABLE(I) TO X
MOVE TTABLE(J) TO TTABLE(I)
MOVE X TO TTABLE(J)
ADD 1 TO I
SUBTRACT 1 FROM J
END-PERFORM.
GOBACK.
END PROGRAM REVERSE.

View file

@ -1,7 +1,7 @@
import system'routines;
import extensions;
public program()
public Program()
{
var sorted := Array.allocate(9).populate::(n => n + 1 );
var values := sorted.clone().randomize(9);
@ -16,10 +16,10 @@ public program()
{
tries.append(1);
console.print("# ",tries," : LIST : ",values," - Flip how many?");
Console.print("# ",tries," : LIST : ",values," - Flip how many?");
values.sequenceReverse(0, console.readLine().toInt())
};
console.printLine("You took ",tries," attempts to put the digits in order!").readChar()
Console.printLine("You took ",tries," attempts to put the digits in order!").readChar()
}

View file

@ -1,55 +0,0 @@
include get.e
function accending(sequence s)
for i = 1 to length(s)-1 do
if s[i]>s[i+1] then
return 0
end if
end for
return 1
end function
puts(1,"Given a jumbled list of the numbers 1 to 9,\n")
puts(1,"you must select how many digits from the left to reverse.\n")
puts(1,"Your goal is to get the digits in order with 1 on the left and 9 on the right.\n")
sequence nums
nums = repeat(0,9)
integer n,flp,tries,temp
-- initial values
for i = 1 to 9 do
nums[i] = i
end for
while accending(nums) do -- shuffle
for i = 1 to 9 do
n = rand(9)
temp = nums[n]
nums[n] = nums[i]
nums[i] = temp
end for
end while
tries = 0
while 1 do
printf(1,"%2d : ",tries)
for i = 1 to 9 do
printf(1,"%d ",nums[i])
end for
if accending(nums) then
exit
end if
flp = prompt_number(" -- How many numbers should be flipped? ",{1,9})
for i = 1 to flp/2 do
temp = nums[i]
nums[i] = nums[flp-i+1]
nums[flp-i+1] = temp
end for
tries += 1
end while
printf(1,"\nYou took %d tries to put the digits in order.", tries)

View file

@ -1,24 +0,0 @@
#adding the below function to the previous users submission to prevent the small
#chance of getting an array that is in ascending order.
#Full disclosure: I am an infrastructure engineer, not a dev. My code is likely
#bad.
function generateArray{
$fArray = 1..9 | Get-Random -Count 9
if (-join $fArray -eq -join @(1..9)){
generateArray
}
return $fArray
}
$array = generateArray
#everything below is untouched from original submission
$nTries = 0
While(-join $Array -ne -join @(1..9)){
$nTries++
$nReverse = Read-Host -Prompt "[$Array] -- How many digits to reverse? "
[Array]::Reverse($Array,0,$nReverse)
}
"$Array"
"Your score: $nTries"

View file

@ -1,22 +0,0 @@
REBOL []
print "NUMBER REVERSAL GAME"
tries: 0
goal: [1 2 3 4 5 6 7 8 9]
random/seed now
until [
jumble: random goal
jumble != goal ; repeat in the unlikely case that jumble isn't jumbled
]
while [jumble != goal] [
prin jumble
prin " How many to flip? "
flip-index: to-integer input ; no validation!
reverse/part jumble flip-index
tries: tries + 1
]
print rejoin ["You took " tries " attempts."]