Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,46 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
procedure Dinesman is
|
||||
subtype Floor is Positive range 1 .. 5;
|
||||
type People is (Baker, Cooper, Fletcher, Miller, Smith);
|
||||
type Floors is array (People'Range) of Floor;
|
||||
type PtFloors is access all Floors;
|
||||
|
||||
function Constrained (f : PtFloors) return Boolean is begin
|
||||
if f (Baker) /= Floor'Last and
|
||||
f (Cooper) /= Floor'First and
|
||||
Floor'First < f (Fletcher) and f (Fletcher) < Floor'Last and
|
||||
f (Miller) > f (Cooper) and
|
||||
abs (f (Smith) - f (Fletcher)) /= 1 and
|
||||
abs (f (Fletcher) - f (Cooper)) /= 1
|
||||
then return True; end if;
|
||||
return False;
|
||||
end Constrained;
|
||||
|
||||
procedure Solve (list : PtFloors; n : Natural) is
|
||||
procedure Swap (I : People; J : Natural) is
|
||||
temp : constant Floor := list (People'Val (J));
|
||||
begin list (People'Val (J)) := list (I); list (I) := temp;
|
||||
end Swap;
|
||||
begin
|
||||
if n = 1 then
|
||||
if Constrained (list) then
|
||||
for p in People'Range loop
|
||||
Put_Line (p'Img & " on floor " & list (p)'Img);
|
||||
end loop;
|
||||
end if;
|
||||
return;
|
||||
end if;
|
||||
for i in People'First .. People'Val (n - 1) loop
|
||||
Solve (list, n - 1);
|
||||
if n mod 2 = 1 then Swap (People'First, n - 1);
|
||||
else Swap (i, n - 1); end if;
|
||||
end loop;
|
||||
end Solve;
|
||||
|
||||
thefloors : aliased Floors;
|
||||
begin
|
||||
for person in People'Range loop
|
||||
thefloors (person) := People'Pos (person) + Floor'First;
|
||||
end loop;
|
||||
Solve (thefloors'Access, Floors'Length);
|
||||
end Dinesman;
|
||||
|
|
@ -17,11 +17,14 @@ proc check .
|
|||
.
|
||||
.
|
||||
proc permute k .
|
||||
for i = k to 5
|
||||
if k = 0
|
||||
check
|
||||
return
|
||||
.
|
||||
for i = 1 to k
|
||||
swap floors[i] floors[k]
|
||||
permute k + 1
|
||||
permute k - 1
|
||||
swap floors[k] floors[i]
|
||||
.
|
||||
if k = 5 : check
|
||||
.
|
||||
permute 1
|
||||
permute len floors[]
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
# Floors are numbered 1 (ground) to 5 (top)
|
||||
|
||||
# Baker, Cooper, Fletcher, Miller, and Smith live on different floors:
|
||||
$statement1 = '$baker -ne $cooper -and $baker -ne $fletcher -and $baker -ne $miller -and
|
||||
$baker -ne $smith -and $cooper -ne $fletcher -and $cooper -ne $miller -and
|
||||
$cooper -ne $smith -and $fletcher -ne $miller -and $fletcher -ne $smith -and
|
||||
$miller -ne $smith'
|
||||
|
||||
# Baker does not live on the top floor:
|
||||
$statement2 = '$baker -ne 5'
|
||||
|
||||
# Cooper does not live on the bottom floor:
|
||||
$statement3 = '$cooper -ne 1'
|
||||
|
||||
# Fletcher does not live on either the top or the bottom floor:
|
||||
$statement4 = '$fletcher -ne 1 -and $fletcher -ne 5'
|
||||
|
||||
# Miller lives on a higher floor than does Cooper:
|
||||
$statement5 = '$miller -gt $cooper'
|
||||
|
||||
# Smith does not live on a floor adjacent to Fletcher's:
|
||||
$statement6 = '[Math]::Abs($smith - $fletcher) -ne 1'
|
||||
|
||||
# Fletcher does not live on a floor adjacent to Cooper's:
|
||||
$statement7 = '[Math]::Abs($fletcher - $cooper) -ne 1'
|
||||
|
||||
for ($baker = 1; $baker -lt 6; $baker++)
|
||||
{
|
||||
for ($cooper = 1; $cooper -lt 6; $cooper++)
|
||||
{
|
||||
for ($fletcher = 1; $fletcher -lt 6; $fletcher++)
|
||||
{
|
||||
for ($miller = 1; $miller -lt 6; $miller++)
|
||||
{
|
||||
for ($smith = 1; $smith -lt 6; $smith++)
|
||||
{
|
||||
if (Invoke-Expression $statement2)
|
||||
{
|
||||
if (Invoke-Expression $statement3)
|
||||
{
|
||||
if (Invoke-Expression $statement5)
|
||||
{
|
||||
if (Invoke-Expression $statement4)
|
||||
{
|
||||
if (Invoke-Expression $statement6)
|
||||
{
|
||||
if (Invoke-Expression $statement7)
|
||||
{
|
||||
if (Invoke-Expression $statement1)
|
||||
{
|
||||
$multipleDwellings = @()
|
||||
$multipleDwellings+= [PSCustomObject]@{Name = "Baker" ; Floor = $baker}
|
||||
$multipleDwellings+= [PSCustomObject]@{Name = "Cooper" ; Floor = $cooper}
|
||||
$multipleDwellings+= [PSCustomObject]@{Name = "Fletcher"; Floor = $fletcher}
|
||||
$multipleDwellings+= [PSCustomObject]@{Name = "Miller" ; Floor = $miller}
|
||||
$multipleDwellings+= [PSCustomObject]@{Name = "Smith" ; Floor = $smith}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
$multipleDwellings
|
||||
|
|
@ -1 +0,0 @@
|
|||
$multipleDwellings | Sort-Object -Property Floor -Descending
|
||||
Loading…
Add table
Add a link
Reference in a new issue