Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -178,4 +178,4 @@ divisionpar10U:
|
|||
sub r1,r4,r2, lsl #1 @ r1 <- r4 - (r2 * 2) = r4 - (r0 * 10)
|
||||
pop {r2,r3,r4,lr}
|
||||
bx lr @ leave function
|
||||
iMagicNumber: .int 0xCCCCCCCD
|
||||
iMagicNumber: .int 0xCCCCCCCD
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
-- The program is written in the programming language Ada. The name "Ada"
|
||||
-- has been chosen in honour of your friend,
|
||||
-- Augusta Ada King-Noel, Countess of Lovelace (née Byron).
|
||||
--
|
||||
-- This is an program to search for the smallest integer X, such that
|
||||
-- (X*X) mod 1_000_000 = 269_696.
|
||||
--
|
||||
-- In the Ada language, "*" represents the multiplication symbol, "mod" the
|
||||
-- modulo reduction, and the underscore "_" after every third digit in
|
||||
-- literals is supposed to simplify reading numbers for humans.
|
||||
-- Everything written after "--" in a line is a comment for the human,
|
||||
-- and will be ignored by the computer.
|
||||
|
||||
with Ada.Text_IO;
|
||||
-- We need this to tell the computer how it will later output its result.
|
||||
|
||||
procedure Babbage_Problem is
|
||||
|
||||
-- We know that 99_736*99_736 is 9_947_269_696. This implies:
|
||||
-- 1. The smallest X with X*X mod 1_000_000 = 269_696 is at most 99_736.
|
||||
-- 2. The largest square X*X, which the program may have to deal with,
|
||||
-- will be at most 9_947_269_69.
|
||||
|
||||
type Number is range 1 .. 99_736*99_736;
|
||||
X: Number := 1;
|
||||
-- X can store numbers between 1 and 99_736*99_736. Computations
|
||||
-- involving X can handle intermediate results in that range.
|
||||
-- Initially the value stored at X is 1.
|
||||
-- When running the program, the value will become 2, 3, 4, etc.
|
||||
|
||||
begin
|
||||
-- The program starts running.
|
||||
|
||||
-- The computer first squares X, then it truncates the square, such
|
||||
-- that the result is a six-digit number.
|
||||
-- Finally, the computer checks if this number is 269_696.
|
||||
while not (((X*X) mod 1_000_000) = 269_696) loop
|
||||
|
||||
-- When the computer goes here, the number was not 269_696.
|
||||
X := X+1;
|
||||
-- So we replace X by X+1, and then go back and try again.
|
||||
|
||||
end loop;
|
||||
|
||||
-- When the computer eventually goes here, the number is 269_696.
|
||||
-- E.e., the value stored at X is the value we are searching for.
|
||||
-- We still have to print out this value.
|
||||
|
||||
Ada.Text_IO.Put_Line(Number'Image(X));
|
||||
-- Number'Image(X) converts the value stored at X into a string of
|
||||
-- printable characters (more specifically, of digits).
|
||||
-- Ada.Text_IO.Put_Line(...) prints this string, for humans to read.
|
||||
-- I did already run the program, and it did print out 25264.
|
||||
end Babbage_Problem;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
n: new 0
|
||||
n: 0
|
||||
while [269696 <> (n^2) % 1000000]
|
||||
-> inc 'n
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ n = 519
|
|||
|
||||
; Loop this action while condition is not satisfied
|
||||
while (Mod(n*n, 1000000) != 269696) {
|
||||
; Increment n
|
||||
n++
|
||||
; Increment n
|
||||
n++
|
||||
}
|
||||
|
||||
; Display n as value
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
;; Let's Create a tool [a function] that helps us check positive integers
|
||||
;; to see which one's square is the first one that ends in ...269696
|
||||
;; It should be noted that a function can be used many times repetitively
|
||||
;; so let's create that function which will be used many times.
|
||||
|
||||
;; First, define the function, give it a name and parameters; it will look like:
|
||||
;; (defun [function_name] ([input_parameter] / [local_variables])
|
||||
(defun SquareEndsWith269696? (number / )
|
||||
;; Let's have the computer Square the number (whichever number was passed to the function)
|
||||
(setq number (* number number))
|
||||
;; Now let's convert that number to a string
|
||||
(setq numberString (itoa number))
|
||||
;; Is the length of the numberString greater than or equal to 6 digits?
|
||||
(if (>= (strlen numberString) 6)
|
||||
;; If it was greater than or equal to 6, we will check the last 6 characters to see if they are equal to "269696"
|
||||
;; If this equality check is successful, then we have found our number, and will return a successful function check!
|
||||
(eq "269696" (substr numberString (- (strlen numberString) 5)))
|
||||
;; Otherwise, an unsuccessful function check will be returned
|
||||
)
|
||||
)
|
||||
|
||||
;; Second, we will create a function that only needs to be used once, they do not always need to be used many times
|
||||
;; Let's use your name as the initiator/name for this function
|
||||
(defun c:BABBAGE ( / integer SquareFound)
|
||||
;; Once we have initiated the function, let's create our first integer to check
|
||||
(setq integer 1)
|
||||
;; Now, let's perform a loop do perform an action many times within the function
|
||||
;; We do not want our loop to run infinitely, so let's create a True/False variable to identify if our task is complete
|
||||
(setq SquareFound nil)
|
||||
;; ok, let's use the loop and True/False variable to continually check if we have found our correct integer
|
||||
(while (not SquareFound)
|
||||
;; Now within the loop, let's use our First function to check if we have the correct integer
|
||||
;; We will save the new result of our check over our existing True/False variable
|
||||
(setq SquareFound (SquareEndsWith269696? integer))
|
||||
;; If the square was not found...
|
||||
(if (not SquareFound)
|
||||
;; ...increase our integer number by 1
|
||||
(setq integer (1+ integer))
|
||||
)
|
||||
;; Once the integer is found, our loop will end and the code will continue forward
|
||||
;; Otherwise, it will start back at "(while ..."
|
||||
)
|
||||
;; If we have made it this far, then our integer has been found!
|
||||
;; let's show everyone what the integer is
|
||||
(prompt
|
||||
(strcat
|
||||
"\nThe smallest integer has been found!"
|
||||
"\nInteger: " (itoa integer) ;; <-- we are converting the integer to a string
|
||||
"\nSquared: " (itoa (* integer integer)) ;; <-- let's show everyone the squared number to prove it
|
||||
)
|
||||
)
|
||||
;; All done, this last line is not required, but makes the ending cleaner
|
||||
(princ)
|
||||
)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#This code is an implementation of Babbage Problem
|
||||
number = 2
|
||||
DO
|
||||
number += 2
|
||||
number += 2
|
||||
UNTIL ((number^2) % 1000000) = 269696
|
||||
PRINT "The smallest number whose square ends in 269696 is: "; number
|
||||
PRINT "It's square is "; number*number
|
||||
|
|
|
|||
|
|
@ -5,21 +5,21 @@
|
|||
#include <limits.h>
|
||||
|
||||
int main() {
|
||||
int current = 0, //the current number
|
||||
square; //the square of the current number
|
||||
int current = 0, //the current number
|
||||
square; //the square of the current number
|
||||
|
||||
//the strategy of take the rest of division by 1e06 is
|
||||
//to take the a number how 6 last digits are 269696
|
||||
while (((square=current*current) % 1000000 != 269696) && (square<INT_MAX)) {
|
||||
current++;
|
||||
}
|
||||
//the strategy of take the rest of division by 1e06 is
|
||||
//to take the a number how 6 last digits are 269696
|
||||
while (((square=current*current) % 1000000 != 269696) && (square<INT_MAX)) {
|
||||
current++;
|
||||
}
|
||||
|
||||
//output
|
||||
if (square>+INT_MAX)
|
||||
printf("Condition not satisfied before INT_MAX reached.");
|
||||
else
|
||||
printf ("The smallest number whose square ends in 269696 is %d\n", current);
|
||||
|
||||
if (square>+INT_MAX)
|
||||
printf("Condition not satisfied before INT_MAX reached.");
|
||||
else
|
||||
printf ("The smallest number whose square ends in 269696 is %d\n", current);
|
||||
|
||||
//the end
|
||||
return 0 ;
|
||||
return 0 ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. BABBAGE-PROGRAM.
|
||||
* A line beginning with an asterisk is an explanatory note.
|
||||
* The machine will disregard any such line.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
* In this part of the program we reserve the storage space we shall
|
||||
* be using for our variables, using a 'PICTURE' clause to specify
|
||||
* how many digits the machine is to keep free.
|
||||
* The prefixed number 77 indicates that these variables do not form part
|
||||
* of any larger 'record' that we might want to deal with as a whole.
|
||||
77 N PICTURE 99999.
|
||||
* We know that 99,736 is a valid answer.
|
||||
77 N-SQUARED PICTURE 9999999999.
|
||||
77 LAST-SIX PICTURE 999999.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
* Here we specify the calculations that the machine is to carry out.
|
||||
CONTROL-PARAGRAPH.
|
||||
PERFORM COMPUTATION-PARAGRAPH VARYING N FROM 1 BY 1
|
||||
UNTIL LAST-SIX IS EQUAL TO 269696.
|
||||
STOP RUN.
|
||||
COMPUTATION-PARAGRAPH.
|
||||
MULTIPLY N BY N GIVING N-SQUARED.
|
||||
MOVE N-SQUARED TO LAST-SIX.
|
||||
* Since the variable LAST-SIX can hold a maximum of six digits,
|
||||
* only the final six digits of N-SQUARED will be moved into it:
|
||||
* the rest will not fit and will simply be discarded.
|
||||
IF LAST-SIX IS EQUAL TO 269696 THEN DISPLAY N.
|
||||
|
||||
END PROGRAM BABBAGE-PROGRAM.
|
||||
|
|
@ -3,13 +3,13 @@ IMPORT StdLog;
|
|||
|
||||
PROCEDURE Do*;
|
||||
VAR
|
||||
i: LONGINT;
|
||||
i: LONGINT;
|
||||
BEGIN
|
||||
i := 2;
|
||||
WHILE (i * i MOD 1000000) # 269696 DO
|
||||
IF i MOD 10 = 4 THEN INC(i,2) ELSE INC(i,8) END
|
||||
END;
|
||||
StdLog.Int(i)
|
||||
i := 2;
|
||||
WHILE (i * i MOD 1000000) # 269696 DO
|
||||
IF i MOD 10 = 4 THEN INC(i,2) ELSE INC(i,8) END
|
||||
END;
|
||||
StdLog.Int(i)
|
||||
END Do;
|
||||
|
||||
END BabbageProblem.
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
print "calculating..."
|
||||
|
||||
let n = 2
|
||||
|
||||
do
|
||||
|
||||
let n = n + 2
|
||||
wait
|
||||
|
||||
let n = n + 2
|
||||
wait
|
||||
loopuntil (n ^ 2) % 1000000 = 269696
|
||||
|
||||
print "The smallest number whose square ends in 269696 is: ", n
|
||||
print "It's square is ", n * n
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
main() {
|
||||
var x = 0;
|
||||
while((x*x)% 1000000 != 269696)
|
||||
{ x++;}
|
||||
|
||||
print('$x');
|
||||
var x = 0;
|
||||
while((x*x)% 1000000 != 269696)
|
||||
{ x++;}
|
||||
|
||||
print('$x');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
var i = 0
|
||||
while i * i % 1000000 != 269696 {
|
||||
i += 1
|
||||
i += 1
|
||||
}
|
||||
|
||||
print("\(i) is the smallest number that ends with 269696")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
for i in 2..Integer.Max {
|
||||
if i * i % 1000000 == 269696 {
|
||||
print("\(i) is the smallest number that ends with 269696")
|
||||
break
|
||||
}
|
||||
if i * i % 1000000 == 269696 {
|
||||
print("\(i) is the smallest number that ends with 269696")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import extensions;
|
||||
import system'math;
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var n := 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
-module(solution1).
|
||||
-export([main/0]).
|
||||
babbage(N,E) when N*N rem 1000000 == 269696 ->
|
||||
io:fwrite("~p",[N]);
|
||||
io:fwrite("~p",[N]);
|
||||
babbage(N,E) ->
|
||||
case E of
|
||||
4 -> babbage(N+2,6);
|
||||
6 -> babbage(N+8,4)
|
||||
case E of
|
||||
4 -> babbage(N+2,6);
|
||||
6 -> babbage(N+8,4)
|
||||
end.
|
||||
main()->
|
||||
babbage(4,4).
|
||||
babbage(4,4).
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ while true
|
|||
{
|
||||
// This prints i and i²
|
||||
println[i + "² = " + i²]
|
||||
exit[] // This terminates the program if a solution is found.
|
||||
exit[] // This terminates the program if a solution is found.
|
||||
}
|
||||
i = i + 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,18 +3,18 @@ package main
|
|||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const (
|
||||
target = 269696
|
||||
modulus = 1000000
|
||||
)
|
||||
for n := 1; ; n++ { // Repeat with n=1, n=2, n=3, ...
|
||||
square := n * n
|
||||
ending := square % modulus
|
||||
if ending == target {
|
||||
fmt.Println("The smallest number whose square ends with",
|
||||
target, "is", n,
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
const (
|
||||
target = 269696
|
||||
modulus = 1000000
|
||||
)
|
||||
for n := 1; ; n++ { // Repeat with n=1, n=2, n=3, ...
|
||||
square := n * n
|
||||
ending := square % modulus
|
||||
if ending == target {
|
||||
fmt.Println("The smallest number whose square ends with",
|
||||
target, "is", n,
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
implement Babbage;
|
||||
|
||||
include "sys.m";
|
||||
sys: Sys;
|
||||
print: import sys;
|
||||
sys: Sys;
|
||||
print: import sys;
|
||||
include "draw.m";
|
||||
draw: Draw;
|
||||
draw: Draw;
|
||||
|
||||
Babbage : module
|
||||
{
|
||||
init : fn(ctxt : ref Draw->Context, args : list of string);
|
||||
init : fn(ctxt : ref Draw->Context, args : list of string);
|
||||
};
|
||||
|
||||
init (ctxt: ref Draw->Context, args: list of string)
|
||||
{
|
||||
sys = load Sys Sys->PATH;
|
||||
current := 0;
|
||||
while ((current * current) % 1000000 != 269696)
|
||||
current++;
|
||||
print("%d", current);
|
||||
sys = load Sys Sys->PATH;
|
||||
current := 0;
|
||||
while ((current * current) % 1000000 != 269696)
|
||||
current++;
|
||||
print("%d", current);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
-- MAXScript : Babbage problem : N.H.
|
||||
posInt = 1
|
||||
while posInt < 1000000 do
|
||||
(
|
||||
if (matchPattern((posInt * posInt) as string) pattern: "*269696") then exit
|
||||
posInt += 1
|
||||
)
|
||||
(
|
||||
if (matchPattern((posInt * posInt) as string) pattern: "*269696") then exit
|
||||
posInt += 1
|
||||
)
|
||||
Print "The smallest number whose square ends in 269696 is " + ((posInt) as string)
|
||||
Print "Its square is " + (((pow posInt 2) as integer) as string)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
n = 0
|
||||
|
||||
while not (n ^ 2 % 1000000) = 269696
|
||||
n += 1
|
||||
n += 1
|
||||
end
|
||||
|
||||
println n
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
;;; Start by assigning n the integer square root of 269696
|
||||
;;; minus 1 to be even
|
||||
;;; Start by assigning n the integer square root of 269696
|
||||
;;; minus 1 to be even
|
||||
(setq n 518)
|
||||
;;; Increment n by 2 till the last 6 digits of its square are 269696
|
||||
;;; Increment n by 2 till the last 6 digits of its square are 269696
|
||||
(while (!= (% (* n n) 1000000) 269696)
|
||||
(++ n 2))
|
||||
;;; Show the result and its square
|
||||
(++ n 2))
|
||||
;;; Show the result and its square
|
||||
(println n "^2 = " (* n n))
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
###########################################################################################
|
||||
#
|
||||
# Definitions:
|
||||
#
|
||||
# Lines that begin with the "#" symbol are comments: they will be ignored by the machine.
|
||||
#
|
||||
# -----------------------------------------------------------------------------------------
|
||||
#
|
||||
# While
|
||||
#
|
||||
# Run a command block based on the results of a conditional test.
|
||||
#
|
||||
# Syntax
|
||||
# while (condition) {command_block}
|
||||
#
|
||||
# Key
|
||||
#
|
||||
# condition If this evaluates to TRUE the loop {command_block} runs.
|
||||
# when the loop has run once the condition is evaluated again.
|
||||
#
|
||||
# command_block Commands to run each time the loop repeats.
|
||||
#
|
||||
# As long as the condition remains true, PowerShell reruns the {command_block} section.
|
||||
#
|
||||
# -----------------------------------------------------------------------------------------
|
||||
#
|
||||
# * means 'multiplied by'
|
||||
# % means 'modulo', or remainder after division
|
||||
# -ne means 'is not equal to'
|
||||
# ++ means 'increment variable by one'
|
||||
#
|
||||
###########################################################################################
|
||||
|
||||
# Declare a variable, $integer, with a starting value of 0.
|
||||
|
||||
$integer = 0
|
||||
|
||||
while (($integer * $integer) % 1000000 -ne 269696)
|
||||
{
|
||||
$integer++
|
||||
}
|
||||
|
||||
# Show the result.
|
||||
|
||||
$integer
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
# Start with the smallest potential square number
|
||||
$TestSquare = 269696
|
||||
|
||||
# Test if our potential square is a square
|
||||
# by testing if the square root of it is an integer
|
||||
# Test if the square root is an integer by testing if the remainder
|
||||
# of the square root divided by 1 is greater than zero
|
||||
# % is the remainder operator
|
||||
# -gt is the "greater than" operator
|
||||
|
||||
# While the remainder of the square root divided by one is greater than zero
|
||||
While ( [Math]::Sqrt( $TestSquare ) % 1 -gt 0 )
|
||||
{
|
||||
# Add 100,000 to get the next potential square number
|
||||
$TestSquare = $TestSquare + 1000000
|
||||
}
|
||||
# This will loop until we get a value for $TestSquare that is a square number
|
||||
|
||||
# Caclulate the root
|
||||
$Root = [Math]::Sqrt( $TestSquare )
|
||||
|
||||
# Display the result and its square
|
||||
$Root
|
||||
$TestSquare
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
:- use_module(library(clpfd)).
|
||||
|
||||
babbage_(B, B, Sq) :-
|
||||
B * B #= Sq,
|
||||
number_chars(Sq, R),
|
||||
append(_, ['2','6','9','6','9','6'], R).
|
||||
B * B #= Sq,
|
||||
number_chars(Sq, R),
|
||||
append(_, ['2','6','9','6','9','6'], R).
|
||||
babbage_(B, R, Sq) :-
|
||||
N #= B + 1,
|
||||
babbage_(N, R, Sq).
|
||||
|
||||
N #= B + 1,
|
||||
babbage_(N, R, Sq).
|
||||
|
||||
babbage :-
|
||||
once(babbage_(1, Num, Square)),
|
||||
format('lowest number is ~p which squared becomes ~p~n', [Num, Square]).
|
||||
once(babbage_(1, Num, Square)),
|
||||
format('lowest number is ~p which squared becomes ~p~n', [Num, Square]).
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
babbage :-
|
||||
Start is ceil(sqrt(269696)),
|
||||
between(Start, inf, N),
|
||||
Square is N * N,
|
||||
Square mod 100 =:= 96, % speed up
|
||||
Square mod 1000000 =:= 269696,!, % break after first true
|
||||
format('lowest number is ~d which squared becomes ~d~n', [N, Square]).
|
||||
Start is ceil(sqrt(269696)),
|
||||
between(Start, inf, N),
|
||||
Square is N * N,
|
||||
Square mod 100 =:= 96, % speed up
|
||||
Square mod 1000000 =:= 269696,!, % break after first true
|
||||
format('lowest number is ~d which squared becomes ~d~n', [N, Square]).
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
object BabbageProblem {
|
||||
def main( args:Array[String] ): Unit = {
|
||||
|
||||
|
||||
var x : Int = 524 // Sqrt of 269696 = 519.something
|
||||
|
||||
|
||||
while( (x * x) % 1000000 != 269696 ){
|
||||
if( x % 10 == 4 ) x = x + 2
|
||||
else x = x + 8
|
||||
}
|
||||
|
||||
|
||||
println("The smallest positive integer whose square ends in 269696 = " + x )
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ What is the smallest positive integer whose square ends in the digits 269,696?
|
|||
put 1 into int
|
||||
|
||||
repeat forever
|
||||
if int squared ends with "269696" then
|
||||
put "The smallest positive integer whose square ends in the digits 269696 is" && int
|
||||
exit all -- don't keep repeating forever!
|
||||
end if
|
||||
|
||||
add 1 to int
|
||||
if int squared ends with "269696" then
|
||||
put "The smallest positive integer whose square ends in the digits 269696 is" && int
|
||||
exit all -- don't keep repeating forever!
|
||||
end if
|
||||
|
||||
add 1 to int
|
||||
end repeat
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
main() := babbage(0);
|
||||
|
||||
|
||||
babbage(current) :=
|
||||
current when current * current mod 1000000 = 269696
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import Swift
|
||||
|
||||
for i in 2...Int.max {
|
||||
if i * i % 1000000 == 269696 {
|
||||
print(i, "is the smallest number that ends with 269696")
|
||||
break
|
||||
}
|
||||
if i * i % 1000000 == 269696 {
|
||||
print(i, "is the smallest number that ends with 269696")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/dash
|
||||
#!/bin/dash
|
||||
|
||||
# Babbage problem:
|
||||
# What is the smallest (positive) integer whose square ends in the digits 269,696?
|
||||
# What is the smallest (positive) integer whose square ends in the digits 269,696?
|
||||
#
|
||||
# He found the second to smallest number (99736 instead of 25264) using pencil and paper,
|
||||
# and would not have wasted hours of computing time on his (planned) Analytical Engine (AE).
|
||||
|
|
@ -47,38 +47,38 @@ done
|
|||
a=1
|
||||
|
||||
# first workfile contains just the number 0
|
||||
echo 0 >$wrk
|
||||
echo 0 >$wrk
|
||||
|
||||
# test all workfile numbers with another digit in front
|
||||
while test $a -lt $m # until the increment excees the modulus
|
||||
do mm=$((a*10)) # modulus in this round
|
||||
ee=$((e % mm)) # ending in this round
|
||||
cat $wrk | # numbers from current workfile
|
||||
while test $a -lt $m # until the increment excees the modulus
|
||||
do mm=$((a*10)) # modulus in this round
|
||||
ee=$((e % mm)) # ending in this round
|
||||
cat $wrk | # numbers from current workfile
|
||||
while read x
|
||||
do y=$x # first number to test is the number read
|
||||
while test $y -le $((x+mm-1))
|
||||
do z=$(($y * $y)) # calculate the square
|
||||
z=$(($z % $mm)) # ending in this round
|
||||
if test $z -eq $ee
|
||||
then echo $y # candidate for next round
|
||||
fi
|
||||
y=$(($y + $a)) # advance leftmost digit
|
||||
done
|
||||
done >$wrk.new # create new workfile
|
||||
do y=$x # first number to test is the number read
|
||||
while test $y -le $((x+mm-1))
|
||||
do z=$(($y * $y)) # calculate the square
|
||||
z=$(($z % $mm)) # ending in this round
|
||||
if test $z -eq $ee
|
||||
then echo $y # candidate for next round
|
||||
fi
|
||||
y=$(($y + $a)) # advance leftmost digit
|
||||
done
|
||||
done >$wrk.new # create new workfile
|
||||
# next round
|
||||
a=$((a*10)) # another leftmost digit
|
||||
mv $wrk.new $wrk # cycle workfiles
|
||||
a=$((a*10)) # another leftmost digit
|
||||
mv $wrk.new $wrk # cycle workfiles
|
||||
done
|
||||
|
||||
# find each number in the last workfile if x*x mod m = e
|
||||
# ending in $e and modulus in $m
|
||||
cat $wrk | # numbers from last workfile
|
||||
cat $wrk | # numbers from last workfile
|
||||
while read x
|
||||
do y=$(($x * $x)) # check
|
||||
do y=$(($x * $x)) # check
|
||||
y=$(($y % $m))
|
||||
if test $y -eq $e
|
||||
then echo $x # solution found
|
||||
then echo $x # solution found
|
||||
fi
|
||||
done |
|
||||
sort -n | # numbers in ascending order
|
||||
head -n 1 # show only smallest
|
||||
sort -n | # numbers in ascending order
|
||||
head -n 1 # show only smallest
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ const (
|
|||
modulus = 1000000
|
||||
)
|
||||
fn main() {
|
||||
for n := 1; ; n++ { // Repeat with n=1, n=2, n=3, ...
|
||||
square := n * n
|
||||
ending := square % modulus
|
||||
if ending == target {
|
||||
println("The smallest number whose square ends with $target is $n")
|
||||
return
|
||||
}
|
||||
}
|
||||
for n := 1; ; n++ { // Repeat with n=1, n=2, n=3, ...
|
||||
square := n * n
|
||||
ending := square % modulus
|
||||
if ending == target {
|
||||
println("The smallest number whose square ends with $target is $n")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
'Sir, this is a script that could solve your problem.
|
||||
|
||||
'Lines that begin with the apostrophe are comments. The machine ignores them.
|
||||
|
||||
'The next line declares a variable n and sets it to 0. Note that the
|
||||
'equals sign "assigns", not just "relates". So in here, this is more
|
||||
'of a command, rather than just a mere proposition.
|
||||
n = 0
|
||||
|
||||
'Starting from the initial value, which is 0, n is being incremented
|
||||
'by 1 while its square, n * n (* means multiplication) does not have
|
||||
'a modulo of 269696 when divided by one million. This means that the
|
||||
'loop will stop when the smallest positive integer whose square ends
|
||||
'in 269696 is found and stored in n. Before I forget, "<>" basically
|
||||
'means "not equal to".
|
||||
Do While ((n * n) Mod 1000000) <> 269696
|
||||
n = n + 1 'Increment by 1.
|
||||
Loop
|
||||
|
||||
'The function "WScript.Echo" displays the string to the monitor. The
|
||||
'ampersand concatenates strings or variables to be displayed.
|
||||
WScript.Echo("The smallest positive integer whose square ends in 269696 is " & n & ".")
|
||||
WScript.Echo("Its square is " & n*n & ".")
|
||||
|
||||
'End of Program.
|
||||
|
|
@ -4,14 +4,14 @@
|
|||
// Check all positive integer values until the required value found
|
||||
for (#1 = 1; #1 < MAXNUM; #1++) {
|
||||
|
||||
#2 = #1 * #1 // #2 = square of the value
|
||||
#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
|
||||
break // We found it, lets stop here
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
PROGRAM "Babbage problem"
|
||||
VERSION "0.0000"
|
||||
PROGRAM "Babbage problem"
|
||||
VERSION "0.0000"
|
||||
|
||||
DECLARE FUNCTION Entry ()
|
||||
|
||||
FUNCTION Entry ()
|
||||
number = 524
|
||||
DO
|
||||
number = number + 2
|
||||
LOOP UNTIL ((number ** 2) MOD 1000000) = 269696
|
||||
PRINT "The smallest number whose square ends in 269696 is: "; number
|
||||
PRINT "It's square is "; number ** 2
|
||||
PRINT "It's square is "; number * number
|
||||
number = 524
|
||||
DO
|
||||
number = number + 2
|
||||
LOOP UNTIL ((number ** 2) MOD 1000000) = 269696
|
||||
PRINT "The smallest number whose square ends in 269696 is: "; number
|
||||
PRINT "It's square is "; number ** 2
|
||||
PRINT "It's square is "; number * number
|
||||
END FUNCTION
|
||||
END PROGRAM
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
number = 524 // primer numero a probar
|
||||
repeat
|
||||
number = number + 2
|
||||
number = number + 2
|
||||
until mod((number ^ 2), 1000000) = 269696
|
||||
print "El menor numero cuyo cuadrado termina en 269696 es: ", number
|
||||
print "Y su cuadrado es: ", number*number
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue