Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,68 +0,0 @@
|
|||
-- Magic constants
|
||||
-- J. Carter 2024 May
|
||||
|
||||
with Ada.Text_IO;
|
||||
with System;
|
||||
|
||||
procedure Magic_Constant is
|
||||
type Big_U is mod System.Max_Binary_Modulus;
|
||||
|
||||
function Magic (Order : in Big_U) return Big_U with
|
||||
Pre => Order > 2;
|
||||
-- Returns the constant for the magic square of order Order
|
||||
|
||||
function Order (Guess : in Big_U) return Big_U;
|
||||
-- Returns the order of the smallest magic square with constant > Guess
|
||||
|
||||
function Image (N : in Big_U; Width : in Positive) return String;
|
||||
-- Returns a blank-filled image of N of at least width characters
|
||||
|
||||
function Magic (Order : in Big_U) return Big_U is
|
||||
(Order * (Order ** 2 + 1) / 2);
|
||||
|
||||
function Order (Guess : in Big_U) return Big_U is
|
||||
Min : Big_U := 3;
|
||||
Max : Big_U := 5_850_000;
|
||||
Mid : Big_U;
|
||||
Prev : Big_U := 0;
|
||||
begin -- Order
|
||||
Search : loop
|
||||
Mid := Min + (Max - Min) / 2;
|
||||
|
||||
exit Search when Mid = Prev;
|
||||
|
||||
Prev := Mid;
|
||||
|
||||
if Magic (Mid) > Guess and (Mid = 3 or else Magic (Mid - 1) <= Guess) then
|
||||
return Mid;
|
||||
end if;
|
||||
|
||||
if Magic (Mid) > Guess then
|
||||
Max := Mid;
|
||||
else
|
||||
Min := Mid;
|
||||
end if;
|
||||
end loop Search;
|
||||
|
||||
raise Program_Error with "Order: no solution for" & Guess'Image;
|
||||
end Order;
|
||||
|
||||
function Image (N : in Big_U; Width : in Positive) return String is
|
||||
Raw : String renames N'Image;
|
||||
Img : String renames Raw (2 .. Raw'Last);
|
||||
begin -- Image
|
||||
return (1 .. Width - Img'Length => ' ') & Img;
|
||||
end Image;
|
||||
begin -- Magic_Constant
|
||||
First_20 : for N in Big_U range 3 .. 22 loop
|
||||
Ada.Text_IO.Put_Line (Item => Image (N, 2) & Image (Magic (N), 5) );
|
||||
end loop First_20;
|
||||
|
||||
Ada.Text_IO.New_Line;
|
||||
Ada.Text_IO.Put_Line (Item => "1000" & Magic (1000)'Image);
|
||||
Ada.Text_IO.New_Line;
|
||||
|
||||
Ten_To : for P in 1 .. (if Big_U'Size < 64 then 9 elsif Big_U'Size < 128 then 18 else 20) loop
|
||||
Ada.Text_IO.Put_Line (Item => "10 ** " & Image (Big_U (P), 2) & Image (Order (10 ** P), 8) );
|
||||
end loop Ten_To;
|
||||
end Magic_Constant;
|
||||
|
|
@ -4,7 +4,7 @@ a: function [n][
|
|||
]
|
||||
|
||||
aInv: function [x][
|
||||
k: new 0
|
||||
k: 0
|
||||
while [x > 2 + k*(1+k^2)/2]
|
||||
-> inc 'k
|
||||
return k
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
-- 8 May 2025
|
||||
include Settings
|
||||
-- 23 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'MAGIC CONSTANT'
|
||||
say version
|
||||
|
|
@ -56,7 +56,4 @@ say Format(Time('e'),,3) 'seconds'
|
|||
say
|
||||
return
|
||||
|
||||
include Functions
|
||||
include Sequences
|
||||
include Numbers
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue