Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,44 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Gapful_Numbers is
|
||||
|
||||
function Divisor (N : in Positive) return Positive is
|
||||
NN : Positive := N;
|
||||
begin
|
||||
while NN >= 10 loop
|
||||
NN := NN / 10;
|
||||
end loop;
|
||||
return 10 * NN + (N mod 10);
|
||||
end Divisor;
|
||||
|
||||
function Is_Gapful (N : in Positive) return Boolean is
|
||||
begin
|
||||
return N mod Divisor (N) = 0;
|
||||
end Is_Gapful;
|
||||
|
||||
procedure Find_Gapful (Count : in Positive; From : in Positive) is
|
||||
Found : Natural := 0;
|
||||
begin
|
||||
for Candidate in From .. Positive'Last loop
|
||||
if Is_Gapful (Candidate) then
|
||||
Put (Candidate'Image);
|
||||
Found := Found + 1;
|
||||
exit when Found = Count;
|
||||
end if;
|
||||
end loop;
|
||||
New_Line;
|
||||
end Find_Gapful;
|
||||
|
||||
begin
|
||||
Put_Line ("First 30 gapful numbers over 100:");
|
||||
Find_Gapful (From => 100, Count => 30);
|
||||
New_Line;
|
||||
|
||||
Put_Line ("First 15 gapful numbers over 1_000_000:");
|
||||
Find_Gapful (From => 1_000_000, Count => 15);
|
||||
New_Line;
|
||||
|
||||
Put_Line ("First 10 gapful numbers over 1_000_000_000:");
|
||||
Find_Gapful (From => 1_000_000_000, Count => 10);
|
||||
New_Line;
|
||||
end Gapful_Numbers;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
Gapful_numbers(Min, Qty){
|
||||
counter:= 0, output := ""
|
||||
while (counter < Qty){
|
||||
n := A_Index+Min-1
|
||||
d := SubStr(n, 1, 1) * 10 + SubStr(n, 0)
|
||||
if (n/d = Floor(n/d))
|
||||
output .= ++counter ": " n "`t" n " / " d " = " Format("{:d}", n/d) "`n"
|
||||
}
|
||||
return output
|
||||
counter:= 0, output := ""
|
||||
while (counter < Qty){
|
||||
n := A_Index+Min-1
|
||||
d := SubStr(n, 1, 1) * 10 + SubStr(n, 0)
|
||||
if (n/d = Floor(n/d))
|
||||
output .= ++counter ": " n "`t" n " / " d " = " Format("{:d}", n/d) "`n"
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
function is_gapful(n)
|
||||
m = n
|
||||
l = n mod 10
|
||||
while (m >= 10)
|
||||
m = int(m / 10)
|
||||
end while
|
||||
return (m * 10) + l
|
||||
m = n
|
||||
l = n mod 10
|
||||
while (m >= 10)
|
||||
m = int(m / 10)
|
||||
end while
|
||||
return (m * 10) + l
|
||||
end function
|
||||
|
||||
subroutine muestra_gapful(n, gaps)
|
||||
inc = 0
|
||||
print "First "; gaps; " gapful numbers >= "; n
|
||||
while inc < gaps
|
||||
if n mod is_gapful(n) = 0 then
|
||||
print " " ; n ;
|
||||
inc = inc + 1
|
||||
end if
|
||||
n = n + 1
|
||||
end while
|
||||
print chr(10)
|
||||
inc = 0
|
||||
print "First "; gaps; " gapful numbers >= "; n
|
||||
while inc < gaps
|
||||
if n mod is_gapful(n) = 0 then
|
||||
print " " ; n ;
|
||||
inc = inc + 1
|
||||
end if
|
||||
n = n + 1
|
||||
end while
|
||||
print chr(10)
|
||||
end subroutine
|
||||
|
||||
call muestra_gapful(100, 30)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,16 @@
|
|||
import ballerina/io;
|
||||
|
||||
function commatize(int n) returns string {
|
||||
string s = n.toString();
|
||||
if n < 0 { s = s.substring(1); }
|
||||
int le = s.length();
|
||||
foreach int i in int:range(le - 3, 0, -3) {
|
||||
s = s.substring(0, i) + "," + s.substring(i);
|
||||
}
|
||||
if n >= 0 { return s; }
|
||||
return "-" + s;
|
||||
}
|
||||
|
||||
public function main() {
|
||||
int[] starts = [100, <int>1e6, <int>1e7, <int>1e9, 7123];
|
||||
int[] counts = [30, 15, 15, 10, 25];
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. GAPFUL.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 COMPUTATION.
|
||||
02 N PIC 9(10).
|
||||
02 N-DIGITS REDEFINES N.
|
||||
03 ND PIC 9 OCCURS 10 TIMES.
|
||||
02 DIV-CHECK PIC 9(10)V9(2).
|
||||
02 DIV-PARTS REDEFINES DIV-CHECK.
|
||||
03 DIV-INT PIC 9(10).
|
||||
03 DIV-FRAC PIC 9(2).
|
||||
02 GAP-AMOUNT PIC 99.
|
||||
02 GAP-DSOR PIC 99.
|
||||
02 FIRST-DIGIT PIC 99.
|
||||
01 OUTPUT-FORMAT.
|
||||
02 N-OUT PIC Z(10).
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
BEGIN.
|
||||
DISPLAY "First 30 gapful numbers >= 100:".
|
||||
MOVE 100 TO N. MOVE 30 TO GAP-AMOUNT.
|
||||
PERFORM CHECK-GAPFUL-NUMBER.
|
||||
|
||||
DISPLAY " ".
|
||||
DISPLAY "First 15 gapful numbers >= 1000000:".
|
||||
MOVE 1000000 TO N. MOVE 15 TO GAP-AMOUNT.
|
||||
PERFORM CHECK-GAPFUL-NUMBER.
|
||||
|
||||
DISPLAY " ".
|
||||
DISPLAY "First 10 gapful numbers >= 1000000000:".
|
||||
MOVE 1000000000 TO N. MOVE 10 TO GAP-AMOUNT.
|
||||
PERFORM CHECK-GAPFUL-NUMBER.
|
||||
STOP RUN.
|
||||
|
||||
CHECK-GAPFUL-NUMBER.
|
||||
SET FIRST-DIGIT TO 1.
|
||||
INSPECT N TALLYING FIRST-DIGIT FOR LEADING '0'.
|
||||
COMPUTE GAP-DSOR = ND(FIRST-DIGIT) * 10 + ND(10).
|
||||
DIVIDE N BY GAP-DSOR GIVING DIV-CHECK.
|
||||
IF DIV-FRAC IS EQUAL TO 0
|
||||
MOVE N TO N-OUT
|
||||
DISPLAY N-OUT
|
||||
SUBTRACT 1 FROM GAP-AMOUNT.
|
||||
ADD 1 TO N.
|
||||
IF GAP-AMOUNT IS GREATER THAN 0
|
||||
GO TO CHECK-GAPFUL-NUMBER.
|
||||
|
|
@ -29,5 +29,5 @@ showSample k =
|
|||
chunksOf 5 $
|
||||
take
|
||||
(read (ws !! 1))
|
||||
[read (ws !! 5) :: Int ..]
|
||||
$ filter isGapful [read (ws !! 5) :: Int ..]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,54 +1,54 @@
|
|||
// Function to construct a new integer from the first and last digits of another
|
||||
function gapfulness_divisor (number) {
|
||||
var digit_string = number.toString(10)
|
||||
var digit_count = digit_string.length
|
||||
var first_digit = digit_string.substring(0, 1)
|
||||
var last_digit = digit_string.substring(digit_count - 1)
|
||||
return parseInt(first_digit.concat(last_digit), 10)
|
||||
var digit_string = number.toString(10)
|
||||
var digit_count = digit_string.length
|
||||
var first_digit = digit_string.substring(0, 1)
|
||||
var last_digit = digit_string.substring(digit_count - 1)
|
||||
return parseInt(first_digit.concat(last_digit), 10)
|
||||
}
|
||||
|
||||
// Divisibility test to determine gapfulness
|
||||
function is_gapful (number) {
|
||||
return number % gapfulness_divisor(number) == 0
|
||||
return number % gapfulness_divisor(number) == 0
|
||||
}
|
||||
|
||||
// Function to search for the least gapful number greater than a given integer
|
||||
function next_gapful (number) {
|
||||
do {
|
||||
++number
|
||||
} while (!is_gapful(number))
|
||||
return number
|
||||
do {
|
||||
++number
|
||||
} while (!is_gapful(number))
|
||||
return number
|
||||
}
|
||||
|
||||
// Constructor for a list of gapful numbers starting from given lower bound
|
||||
function gapful_numbers (start, amount) {
|
||||
var list = [], count = 0, number = start
|
||||
if (amount > 0 && is_gapful(start)) {
|
||||
list.push(start)
|
||||
}
|
||||
while (list.length < amount) {
|
||||
number = next_gapful(number)
|
||||
list.push(number)
|
||||
}
|
||||
return list
|
||||
var list = [], count = 0, number = start
|
||||
if (amount > 0 && is_gapful(start)) {
|
||||
list.push(start)
|
||||
}
|
||||
while (list.length < amount) {
|
||||
number = next_gapful(number)
|
||||
list.push(number)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// Formatter for a comma-separated list of gapful numbers
|
||||
function single_line_gapfuls (start, amount) {
|
||||
var list = gapful_numbers(start, amount)
|
||||
return list.join(", ")
|
||||
var list = gapful_numbers(start, amount)
|
||||
return list.join(", ")
|
||||
}
|
||||
|
||||
// Windows console output wrapper
|
||||
function print(message) {
|
||||
WScript.StdOut.WriteLine(message)
|
||||
WScript.StdOut.WriteLine(message)
|
||||
}
|
||||
|
||||
// Main algorithm
|
||||
|
||||
function print_gapfuls_with_header(start, amount) {
|
||||
print("First " + start + " gapful numbers starting at " + amount)
|
||||
print(single_line_gapfuls(start, amount))
|
||||
print("First " + start + " gapful numbers starting at " + amount)
|
||||
print(single_line_gapfuls(start, amount))
|
||||
}
|
||||
|
||||
print_gapfuls_with_header(100, 30)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">starts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1e2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1e6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1e7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1e9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7123</span><span style="color: #0000FF;">},</span>
|
||||
<span style="color: #000000;">counts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">25</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">starts</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">counts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
|
||||
<span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">starts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
|
||||
<span style="color: #000000;">pow</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">100</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">*</span><span style="color: #000000;">10</span> <span style="color: #008080;">do</span> <span style="color: #000000;">pow</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">10</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</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;">"First %d gapful numbers starting at %,d: "</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">fl</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">/</span><span style="color: #000000;">pow</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">10</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fl</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">0</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 "</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">count</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">j</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">10</span><span style="color: #0000FF;">*</span><span style="color: #000000;">pow</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">pow</span> <span style="color: #0000FF;">*=</span> <span style="color: #000000;">10</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</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;">"\n"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<!--
|
||||
constant starts = {1e2, 1e6, 1e7, 1e9, 7123},
|
||||
counts = {30, 15, 15, 10, 25}
|
||||
for i=1 to length(starts) do
|
||||
integer count = counts[i],
|
||||
j = starts[i],
|
||||
pow = 100
|
||||
while j>=pow*10 do pow *= 10 end while
|
||||
printf(1,"First %d gapful numbers starting at %,d: ", {count, j})
|
||||
while count do
|
||||
integer fl = floor(j/pow)*10 + remainder(j,10)
|
||||
if remainder(j,fl)==0 then
|
||||
printf(1,"%d ", j)
|
||||
count -= 1
|
||||
end if
|
||||
j += 1
|
||||
if j>=10*pow then
|
||||
pow *= 10
|
||||
end if
|
||||
end while
|
||||
printf(1,"\n")
|
||||
end for
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
function Get-FirstDigit {
|
||||
param ( [int] $Number )
|
||||
[int]$Number.ToString().Substring(0,1)
|
||||
}
|
||||
|
||||
function Get-LastDigit {
|
||||
param ( [int] $Number )
|
||||
$Number % 10
|
||||
}
|
||||
|
||||
function Get-BookendNumber {
|
||||
param ( [Int] $Number )
|
||||
10 * (Get-FirstDigit $Number) + (Get-LastDigit $Number)
|
||||
}
|
||||
|
||||
function Test-Gapful {
|
||||
param ( [Int] $Number )
|
||||
100 -lt $Number -and 0 -eq $Number % (Get-BookendNumber $Number)
|
||||
}
|
||||
|
||||
function Find-Gapfuls {
|
||||
param ( [Int] $Start, [Int] $Count )
|
||||
$result = @()
|
||||
|
||||
While ($result.Count -lt $Count) {
|
||||
If (Test-Gapful $Start) {
|
||||
$result += @($Start)
|
||||
}
|
||||
$Start += 1
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
function Search-Range {
|
||||
param ( [Int] $Start, [Int] $Count )
|
||||
Write-Output "The first $Count gapful numbers >= $($Start):"
|
||||
Write-Output( (Find-Gapfuls $Start $Count) -join ",")
|
||||
Write-Output ""
|
||||
}
|
||||
|
||||
Search-Range 1 30
|
||||
Search-Range 1000000 15
|
||||
Search-Range 1000000000 10
|
||||
|
|
@ -1,24 +1,29 @@
|
|||
first-digit() {
|
||||
#!/bin/bash
|
||||
|
||||
# Additional translation of dashes to underscores in variable names
|
||||
# was performed later [RBE]
|
||||
|
||||
first_digit() {
|
||||
printf '%s\n' "${1:0:1}"
|
||||
}
|
||||
|
||||
last-digit() {
|
||||
last_digit() {
|
||||
printf '%s\n' $(( $1 % 10 ))
|
||||
}
|
||||
|
||||
bookend-number() {
|
||||
printf '%s%s\n' "$(first-digit "$@")" "$(last-digit "$@")"
|
||||
bookend_number() {
|
||||
printf '%s%s\n' "$(first_digit "$@")" "$(last_digit "$@")"
|
||||
}
|
||||
|
||||
is-gapful() {
|
||||
(( $1 >= 100 && $1 % $(bookend-number "$1") == 0 ))
|
||||
is_gapful() {
|
||||
(( $1 >= 100 && $1 % $(bookend_number "$1") == 0 ))
|
||||
}
|
||||
|
||||
gapfuls-in-range() {
|
||||
gapfuls_in_range() {
|
||||
local gapfuls=()
|
||||
local -i i found
|
||||
for (( i=$1, found=0; found < $2; ++i )); do
|
||||
if is-gapful "$i"; then
|
||||
if is_gapful "$i"; then
|
||||
if (( found )); then
|
||||
printf ' ';
|
||||
fi
|
||||
|
|
@ -29,15 +34,15 @@ gapfuls-in-range() {
|
|||
printf '\n'
|
||||
}
|
||||
|
||||
report-ranges() {
|
||||
report_ranges() {
|
||||
local range
|
||||
local -i start size
|
||||
for range; do
|
||||
IFS=, read start size <<<"$range"
|
||||
printf 'The first %d gapful numbers >= %d:\n' "$size" "$start"
|
||||
gapfuls-in-range "$start" "$size"
|
||||
gapfuls_in_range "$start" "$size"
|
||||
printf '\n'
|
||||
done
|
||||
}
|
||||
|
||||
report-ranges 1,30 1000000,15 1000000000,10
|
||||
report_ranges 1,30 1000000,15 1000000000,10
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
func isgapful(n:number):boolean{
|
||||
set s:string = tostring(n);
|
||||
set d = toint(`{s::at(0)}{s::at(?s-1)}`);
|
||||
send (n%d)==0
|
||||
set s:string = tostring(n);
|
||||
set d = toint(`{s::at(0)}{s::at(?s-1)}`);
|
||||
send (n%d)==0
|
||||
}
|
||||
|
||||
func findGapfulNumbers(start,amount){
|
||||
set gapful=[];
|
||||
set ind = start;
|
||||
while(true){
|
||||
if(isgapful(ind)){
|
||||
gapful::insert(ind);
|
||||
}
|
||||
ind++;
|
||||
if((?gapful)>=amount){
|
||||
stop;
|
||||
}
|
||||
}
|
||||
log(`First {amount} gapful ints at {start}: {gapful::join(", ")}`);
|
||||
set gapful=[];
|
||||
set ind = start;
|
||||
while(true){
|
||||
if(isgapful(ind)){
|
||||
gapful::insert(ind);
|
||||
}
|
||||
ind++;
|
||||
if((?gapful)>=amount){
|
||||
stop;
|
||||
}
|
||||
}
|
||||
log(`First {amount} gapful ints at {start}: {gapful::join(", ")}`);
|
||||
}
|
||||
|
||||
findGapfulNumbers(100,30);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
sub is_gapful(n)
|
||||
m = n
|
||||
l = mod(n, 10)
|
||||
l = mod(n, 10)
|
||||
while (m >= 10)
|
||||
m = int(m / 10)
|
||||
wend
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
fcn gapfulW(start){ //--> iterator
|
||||
fcn gapfulW(start){ //--> iterator
|
||||
[start..].tweak(
|
||||
fcn(n){ if(n % (10*n.toString()[0] + n%10)) Void.Skip else n })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue