Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,35 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Square_But_Not_Cube is
|
||||
|
||||
function Is_Cube (N : in Positive) return Boolean is
|
||||
Cube : Positive;
|
||||
begin
|
||||
for I in Positive loop
|
||||
Cube := I**3;
|
||||
if Cube = N then return True;
|
||||
elsif Cube > N then return False;
|
||||
end if;
|
||||
end loop;
|
||||
raise Program_Error;
|
||||
end Is_Cube;
|
||||
|
||||
procedure Show (Limit : in Natural) is
|
||||
Count : Natural := 0;
|
||||
Square : Natural;
|
||||
use Ada.Text_IO;
|
||||
begin
|
||||
for N in Positive loop
|
||||
Square := N**2;
|
||||
if not Is_Cube (Square) then
|
||||
Count := Count + 1;
|
||||
Put (Square'Image);
|
||||
exit when Count = Limit;
|
||||
end if;
|
||||
end loop;
|
||||
New_Line;
|
||||
end Show;
|
||||
|
||||
begin
|
||||
Show (Limit => 30);
|
||||
end Square_But_Not_Cube;
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. SQUARE-NOT-CUBE.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 COMPUTATION.
|
||||
02 SQ-ROOT PIC 9999 COMP VALUE 1.
|
||||
02 CUBE-ROOT PIC 9999 COMP VALUE 1.
|
||||
02 SQUARE PIC 9999 COMP VALUE 1.
|
||||
02 CUBE PIC 9999 COMP VALUE 1.
|
||||
02 SEEN PIC 99 COMP VALUE 0.
|
||||
01 OUTPUT-FORMAT.
|
||||
02 OUT-NUM PIC ZZZ9.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
SQUARE-STEP.
|
||||
COMPUTE SQUARE = SQ-ROOT ** 2.
|
||||
CUBE-STEP.
|
||||
IF SQUARE IS GREATER THAN CUBE
|
||||
ADD 1 TO CUBE-ROOT
|
||||
COMPUTE CUBE = CUBE-ROOT ** 3
|
||||
GO TO CUBE-STEP.
|
||||
IF SQUARE IS NOT EQUAL TO CUBE
|
||||
ADD 1 TO SEEN
|
||||
MOVE SQUARE TO OUT-NUM
|
||||
DISPLAY OUT-NUM.
|
||||
ADD 1 TO SQ-ROOT.
|
||||
IF SEEN IS LESS THAN 30 GO TO SQUARE-STEP.
|
||||
STOP RUN.
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
function nthroot (x, n)
|
||||
local r = 1
|
||||
for i = 1, 16 do
|
||||
r = (((n - 1) * r) + x / (r ^ (n - 1))) / n
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
local i, count, sq, cbrt = 0, 0
|
||||
while count < 30 do
|
||||
i = i + 1
|
||||
sq = i * i
|
||||
-- The next line should say nthroot(sq, 3), right? But this works. Maths, eh?
|
||||
cbrt = nthroot(i, 3)
|
||||
if cbrt == math.floor(cbrt) then
|
||||
print(sq .. " is square and cube")
|
||||
else
|
||||
print(sq)
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
|
@ -1,20 +1,18 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">square</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">squared</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">cube</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cubed</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
integer square = 1, squared = 1*1,
|
||||
cube = 1, cubed = 1*1*1,
|
||||
count = 0
|
||||
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">30</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">squared</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">square</span><span style="color: #0000FF;">*</span><span style="color: #000000;">square</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">squared</span><span style="color: #0000FF;">></span><span style="color: #000000;">cubed</span> <span style="color: #008080;">do</span> <span style="color: #000000;">cube</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">;</span> <span style="color: #000000;">cubed</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cube</span><span style="color: #0000FF;">*</span><span style="color: #000000;">cube</span><span style="color: #0000FF;">*</span><span style="color: #000000;">cube</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">squared</span><span style="color: #0000FF;">=</span><span style="color: #000000;">cubed</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d: %d == %d^3\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">square</span><span style="color: #0000FF;">,</span><span style="color: #000000;">squared</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cube</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d: %d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">square</span><span style="color: #0000FF;">,</span><span style="color: #000000;">squared</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">square</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
while count<30 do
|
||||
squared = square*square
|
||||
while squared>cubed do cube += 1; cubed = cube*cube*cube end while
|
||||
if squared=cubed then
|
||||
printf(1,"%d: %d == %d^3\n",{square,squared,cube})
|
||||
else
|
||||
count += 1
|
||||
printf(1,"%d: %d\n",{square,squared})
|
||||
end if
|
||||
square += 1
|
||||
end while
|
||||
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nThe first 15 positive integers that are both a square and a cube: \n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">sq_power</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">15</span><span style="color: #0000FF;">),</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
printf(1,"\nThe first 15 positive integers that are both a square and a cube: \n")
|
||||
?sq_power(tagset(15),6)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue