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,10 +0,0 @@
With
Ada.Text_IO,
Connection_Types,
Connection_Combinations;
procedure main is
Result : Connection_Types.Partial_Board renames Connection_Combinations;
begin
Ada.Text_IO.Put_Line( Connection_Types.Image(Result) );
end;

View file

@ -1,47 +0,0 @@
Pragma Ada_2012;
Package Connection_Types with Pure is
-- Name of the nodes.
Type Node is (A, B, C, D, E, F, G, H);
-- Type for indicating if a node is connected.
Type Connection_List is array(Node) of Boolean
with Size => 8, Object_Size => 8, Pack;
Function "&"( Left : Connection_List; Right : Node ) return Connection_List;
-- The actual map of the network connections.
Network : Constant Array (Node) of Connection_List:=
(
A => (C|D|E => True, others => False),
B => (D|E|F => True, others => False),
C => (A|D|G => True, others => False),
D => (C|A|B|E|H|G => True, others => False),
E => (D|A|B|F|H|G => True, others => False),
F => (B|E|H => True, others => False),
G => (C|D|E => True, others => False),
H => (D|E|F => True, others => False)
);
-- Values of the nodes.
Type Peg is range 1..8;
-- Indicator for which values have been assigned.
Type Used_Peg is array(Peg) of Boolean
with Size => 8, Object_Size => 8, Pack;
Function "&"( Left : Used_Peg; Right : Peg ) return Used_Peg;
-- Type describing the layout of the network.
Type Partial_Board is array(Node range <>) of Peg;
Subtype Board is Partial_Board(Node);
-- Determines if the given board is a solution or partial-solution.
Function Is_Solution ( Input : Partial_Board ) return Boolean;
-- Displays the board as text.
Function Image ( Input : Partial_Board ) Return String;
End Connection_Types;

View file

@ -1,6 +0,0 @@
Pragma Ada_2012;
with Connection_Types;
use Connection_Types;
Function Connection_Combinations return Partial_Board;

View file

@ -1,73 +0,0 @@
Pragma Ada_2012;
Package Body Connection_Types is
New_Line : Constant String := ASCII.CR & ASCII.LF;
---------------------
-- Solution Test --
---------------------
Function Is_Solution( Input : Partial_Board ) return Boolean is
(for all Index in Input'Range =>
(for all Connection in Node'Range =>
(if Network(Index)(Connection) and Connection in Input'Range
then abs (Input(Index) - Input(Connection)) > 1
)
)
);
------------------------
-- Concat Operators --
------------------------
Function "&"( Left : Used_Peg; Right : Peg ) return Used_Peg is
begin
return Result : Used_Peg := Left do
Result(Right):= True;
end return;
end "&";
Function "&"(Left : Connection_List; Right : Node) return Connection_List is
begin
Return Result : Connection_List := Left do
Result(Right):= True;
end return;
end "&";
-----------------------
-- IMAGE FUNCTIONS --
-----------------------
Function Image(Input : Peg) Return Character is
( Peg'Image(Input)(2) );
Function Image(Input : Peg) Return String is
( 1 => Image(Input) );
Function Image(Input : Partial_Board; Item : Node) Return String is
( 1 => (if Item not in Input'Range then '*' else Image(Input(Item)) ));
Function Image( Input : Partial_Board ) Return String is
A : String renames Image(Input, Connection_Types.A);
B : String renames Image(Input, Connection_Types.B);
C : String renames Image(Input, Connection_Types.C);
D : String renames Image(Input, Connection_Types.D);
E : String renames Image(Input, Connection_Types.E);
F : String renames Image(Input, Connection_Types.F);
G : String renames Image(Input, Connection_Types.G);
H : String renames Image(Input, Connection_Types.H);
begin
return
" "&A&" "&B & New_Line &
" /|\ /|\" & New_Line &
" / | X | \" & New_Line &
" / |/ \| \" & New_Line &
" "&C&" - "&D&" - "&E&" - "&F & New_Line &
" \ |\ /| /" & New_Line &
" \ | X | /" & New_Line &
" \|/ \|/" & New_Line &
" "&G&" "&H & New_Line;
end Image;
End Connection_Types;

View file

@ -1,73 +0,0 @@
Function Connection_Combinations return Partial_Board is
begin
Return Result : Board do
declare
-- The Generate task takes two parameters
-- (1) a list of pegs already in use, and
-- (2) a partial-board
-- and, if the state given is a viable yet incomplete solution, it
-- takes a peg and adds it to the state creating a new task with
-- that peg in its used list.
--
-- When a complete solution is found it is copied into result.
task type Generate(
Pegs : not null access Used_Peg:= new Used_Peg'(others => False);
State : not null access Partial_Board:= new Partial_Board'(Node'Last..Node'First => <>)
) is
end Generate;
-- An access to Generate and array thereof, for creating the
-- children tasks.
type Generator is access all Generate;
type Generators is array(Peg range <>) of Generator;
-- Gen handles the actual creation of a new task and state.
Function Gen(P : Peg; G : not null access Generate) return Generator is
begin
return (if G.Pegs(P) then null
else new Generate(
Pegs => new Used_Peg'(G.Pegs.all & P),
State => New Partial_Board'(G.All.State.All & P)
)
);
end;
task body Generate is
begin
if Is_Solution(State.All) then
-- If the state is a partial board, we make children to
-- complete the calculations.
if State'Length <= Node'Pos(Node'Last) then
declare
Subtasks : Constant Generators:=
(
Gen(1, Generate'Access),
Gen(2, Generate'Access),
Gen(3, Generate'Access),
Gen(4, Generate'Access),
Gen(5, Generate'Access),
Gen(6, Generate'Access),
Gen(7, Generate'Access),
Gen(8, Generate'Access)
);
begin
null;
end;
else
Result:= State.All;
end if;
else
-- The current state is not a solution, so we do not continue it.
Null;
end if;
end Generate;
Master : Generate;
begin
null;
end;
End return;
End Connection_Combinations;

View file

@ -1,78 +0,0 @@
type hole = int;
param A : hole = 1;
param B : hole = A+1;
param C : hole = B+1;
param D : hole = C+1;
param E : hole = D+1;
param F : hole = E+1;
param G : hole = F+1;
param H : hole = G+1;
param starting : int = 0;
const holes : domain(hole) = { A,B,C,D,E,F,G,H };
const graph : [holes] domain(hole) = [ A => { C,D,E },
B => { D,E,F },
C => { A,D,G },
D => { A,B,C,E,G,H },
E => { A,B,D,F,G,H },
F => { B,E,H },
G => { C,D,E },
H => { D,E,F }
];
proc check( configuration : [] int, idx : hole ) : bool {
var good = true;
for adj in graph[idx] {
if adj >= idx then continue;
if abs( configuration[idx] - configuration[adj] ) <= 1 {
good = false;
break;
}
}
return good;
}
proc solve( configuration : [] int, pegs : domain(int), idx : hole = A ) : bool {
for value in pegs {
configuration[idx] = value;
if check( configuration, idx ) {
if idx < holes.size {
var prePegs = pegs;
if solve( configuration, prePegs - value, idx + 1 ){
return true;
}
} else {
return true;
}
}
}
configuration[idx] = starting;
return false;
}
proc printBoard( configuration : [] int ){
return
"\n " + configuration[A] + " " + configuration[B]+ "\n" +
" /|\\ /|\\ \n"+
" / | X | \\ \n"+
" / |/ \\| \\ \n"+
" " + configuration[C] +" - " + configuration[D] + " - " + configuration[E] + " - " + configuration[F] + " \n"+
" \\ |\\ /| / \n"+
" \\ | X | / \n"+
" \\|/ \\|/ \n"+
" " + configuration[G] + " " + configuration[H]+ "\n";
}
proc main(){
var configuration : [holes] int;
for idx in holes do configuration[idx] = starting;
var pegs : domain(int) = {1,2,3,4,5,6,7,8};
solve( configuration, pegs );
writeln( printBoard( configuration ) );
}