Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
13
Task/Babbage-problem/Amazing-Hopper/babbage-problem.hopper
Normal file
13
Task/Babbage-problem/Amazing-Hopper/babbage-problem.hopper
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <basico.h>
|
||||
|
||||
algoritmo
|
||||
decimales '0'
|
||||
número = 0, i=10
|
||||
ciclo:
|
||||
iterar grupo( número+=2, \
|
||||
#( (número^2) % 1000000 != 269696 ), ; )
|
||||
imprimir ("The smallest number whose square ends in 269696 is: ",\
|
||||
número,\
|
||||
"\nIt's square is: ", #(número ^ 2), NL )
|
||||
i--, jnz(ciclo)
|
||||
terminar
|
||||
|
|
@ -1,8 +1,13 @@
|
|||
"""
|
||||
babbage(x::Integer)
|
||||
|
||||
Returns the smallest positive integer whose square ends in `x`
|
||||
"""
|
||||
function babbage(x::Integer)
|
||||
i = big(0)
|
||||
d = floor(log10(x)) + 1
|
||||
while i ^ 2 % 10 ^ d != x
|
||||
i += 1
|
||||
i = big(0) # start with 0 and increase by 1 until target reaached
|
||||
d = 10^ndigits(x) # smallest power of 10 greater than x
|
||||
while (i * i) % d != x
|
||||
i += 1 # try next squre of numbers 0, 1, 2, ...
|
||||
end
|
||||
return i
|
||||
end
|
||||
|
|
|
|||
14
Task/Babbage-problem/Maxima/babbage-problem.maxima
Normal file
14
Task/Babbage-problem/Maxima/babbage-problem.maxima
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/* Function that returns a list of digits given a nonnegative integer */
|
||||
decompose(num) := block([digits, remainder],
|
||||
digits: [],
|
||||
while num > 0 do
|
||||
(remainder: mod(num, 10),
|
||||
digits: cons(remainder, digits),
|
||||
num: floor(num/10)),
|
||||
digits
|
||||
)$
|
||||
|
||||
/* Test case */
|
||||
block(babbage_param:269696,i:isqrt(babbage_param)+1,cache_babbage:decompose(babbage_param),
|
||||
while rest(decompose(i^2),(length(decompose(i^2))-6))#cache_babbage do i:i+2,
|
||||
i);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# For all positives integers from 1 to Infinity
|
||||
# For all positive integers from 1 to Infinity
|
||||
for 1 .. Inf -> $integer {
|
||||
|
||||
# calculate the square of the integer
|
||||
|
|
|
|||
32
Task/Babbage-problem/S-BASIC/babbage-problem.basic
Normal file
32
Task/Babbage-problem/S-BASIC/babbage-problem.basic
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
$lines
|
||||
|
||||
$constant true = FFFFH
|
||||
$constant false = 0
|
||||
|
||||
var n, sq, r = real.double
|
||||
var done = integer
|
||||
|
||||
print "Finding smallest number whose square ends in 269696"
|
||||
|
||||
n = 520 rem - no smaller number has a square that large
|
||||
done = false
|
||||
|
||||
rem - no need to search beyond the number Babbage already knew
|
||||
while not done and n <= 99736.0 do
|
||||
begin
|
||||
sq = n * n
|
||||
rem - compute sq mod 1000000 by repeated subtraction
|
||||
r = sq
|
||||
while r >= 1000000.0 do
|
||||
r = r - 1000000.0
|
||||
if r = 269696.0 then
|
||||
begin
|
||||
print using "The smallest number is ######"; n
|
||||
print using "and its square is ##,###,###,###"; sq
|
||||
done = true
|
||||
end
|
||||
rem - only even numbers can have a square ending in 6
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
// Vedit Macro Language stores numerical values in numeric registers,
|
||||
// referred as #0 to #255.
|
||||
|
||||
// Check all positive integer values until the required value found
|
||||
for (#1 = 1; #1 < MAXNUM; #1++) {
|
||||
|
||||
#2 = #1 * #1 // #2 = square of the value
|
||||
|
||||
// The operator % is the modulo operator (the remainder of division).
|
||||
// Modulo 1000000 gives the last 6 digits of a value.
|
||||
#3 = #2 % 1000000
|
||||
|
||||
if (#3 == 269696) {
|
||||
break // We found it, lets stop here
|
||||
}
|
||||
}
|
||||
|
||||
if (#1 < MAXNUM) {
|
||||
Message("The smallest number whose square ends in 269696 is ", NOCR)
|
||||
Num_Type(#1)
|
||||
Message("The square is ", NOCR)
|
||||
Num_Type(#2)
|
||||
} else {
|
||||
Message("Condition not satisfied before MAXNUM reached.)
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
However, we can skip numbers which don't end in 4 or 6 as their squares can't end in 6.
|
||||
*/
|
||||
|
||||
import "/fmt" for Fmt // this enables us to format numbers with thousand separators
|
||||
import "./fmt" for Fmt // this enables us to format numbers with thousand separators
|
||||
var start = 269696.sqrt.ceil // get the next integer higher than (or equal to) the square root
|
||||
start = (start/2).ceil * 2 // if it's odd, use the next even integer
|
||||
var i = start // assign it to a variable 'i' for use in the following loop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue