Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
|
|
@ -32,15 +32,12 @@ BEGIN
|
|||
( number = described number )
|
||||
END; # SELFDESCRIBING #
|
||||
|
||||
main: (
|
||||
|
||||
FOR i TO 100 000 000
|
||||
FOR i TO 100 000 000
|
||||
DO
|
||||
IF SELFDESCRIBING i
|
||||
THEN
|
||||
print( ( i, " is self describing", newline ) )
|
||||
FI
|
||||
OD
|
||||
)
|
||||
|
||||
END
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
SDN ← (∧≡/)'0'-˜•Fmt
|
||||
|
||||
SDN¨⊸/ ↕21212
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
b ← 10 # Base
|
||||
m ← 20 # Maximum number of digits
|
||||
S ← {(≡⟜∨¨/⊢)⟜((𝕨↑/⁼)¨) 𝕨↑¨𝕩} # Get solutions from partitions 𝕩 of 𝕨
|
||||
p ← ∾¨ ∾⟜(<-⟜↕∘≠{𝕨∾¨∾(-𝕨⌊≠𝕩)↑𝕩}¨⊢)⍟m ⋈⋈⋈↕0 # Partitions of 0...m
|
||||
d ← ∾ 1 ↓ (↕≠p) S¨ (∧´¨b⊸>)⊸/¨ p # Digits of self-describing numbers
|
||||
b⊸×⊸+˜´∘⌽¨ d
|
||||
|
|
@ -1,5 +1,94 @@
|
|||
1210
|
||||
2020
|
||||
21200
|
||||
3211000
|
||||
42101000
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BASE_MIN 2
|
||||
#define BASE_MAX 94
|
||||
|
||||
void selfdesc(unsigned long);
|
||||
|
||||
const char *ref = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
char *digs;
|
||||
unsigned long *nums, *inds, inds_sum, inds_val, base;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int used[BASE_MAX];
|
||||
unsigned long digs_n, i;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage is %s <digits>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
digs = argv[1];
|
||||
digs_n = strlen(digs);
|
||||
if (digs_n < BASE_MIN || digs_n > BASE_MAX) {
|
||||
fprintf(stderr, "Invalid number of digits\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (i = 0; i < BASE_MAX; i++) {
|
||||
used[i] = 0;
|
||||
}
|
||||
for (i = 0; i < digs_n && strchr(ref, digs[i]) && !used[digs[i]-*ref]; i++) {
|
||||
used[digs[i]-*ref] = 1;
|
||||
}
|
||||
if (i < digs_n) {
|
||||
fprintf(stderr, "Invalid digits\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
nums = calloc(digs_n, sizeof(unsigned long));
|
||||
if (!nums) {
|
||||
fprintf(stderr, "Could not allocate memory for nums\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
inds = malloc(sizeof(unsigned long)*digs_n);
|
||||
if (!inds) {
|
||||
fprintf(stderr, "Could not allocate memory for inds\n");
|
||||
free(nums);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
inds_sum = 0;
|
||||
inds_val = 0;
|
||||
for (base = BASE_MIN; base <= digs_n; base++) {
|
||||
selfdesc(base);
|
||||
}
|
||||
free(inds);
|
||||
free(nums);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void selfdesc(unsigned long i) {
|
||||
unsigned long diff_sum, upper_min, j, lower, upper, k;
|
||||
if (i) {
|
||||
diff_sum = base-inds_sum;
|
||||
upper_min = inds_sum ? diff_sum:base-1;
|
||||
j = i-1;
|
||||
if (j) {
|
||||
lower = 0;
|
||||
upper = (base-inds_val)/j;
|
||||
}
|
||||
else {
|
||||
lower = diff_sum;
|
||||
upper = diff_sum;
|
||||
}
|
||||
if (upper < upper_min) {
|
||||
upper_min = upper;
|
||||
}
|
||||
for (inds[j] = lower; inds[j] <= upper_min; inds[j]++) {
|
||||
nums[inds[j]]++;
|
||||
inds_sum += inds[j];
|
||||
inds_val += inds[j]*j;
|
||||
for (k = base-1; k > j && nums[k] <= inds[k] && inds[k]-nums[k] <= i; k--);
|
||||
if (k == j) {
|
||||
selfdesc(i-1);
|
||||
}
|
||||
inds_val -= inds[j]*j;
|
||||
inds_sum -= inds[j];
|
||||
nums[inds[j]]--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (j = 0; j < base; j++) {
|
||||
putchar(digs[inds[j]]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BASE_MIN 2
|
||||
#define BASE_MAX 94
|
||||
|
||||
void selfdesc(unsigned long);
|
||||
|
||||
const char *ref = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
char *digs;
|
||||
unsigned long *nums, *inds, inds_sum, inds_val, base;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int used[BASE_MAX];
|
||||
unsigned long digs_n, i;
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage is %s <digits>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
digs = argv[1];
|
||||
digs_n = strlen(digs);
|
||||
if (digs_n < BASE_MIN || digs_n > BASE_MAX) {
|
||||
fprintf(stderr, "Invalid number of digits\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for (i = 0; i < BASE_MAX; i++) {
|
||||
used[i] = 0;
|
||||
}
|
||||
for (i = 0; i < digs_n && strchr(ref, digs[i]) && !used[digs[i]-*ref]; i++) {
|
||||
used[digs[i]-*ref] = 1;
|
||||
}
|
||||
if (i < digs_n) {
|
||||
fprintf(stderr, "Invalid digits\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
nums = calloc(digs_n, sizeof(unsigned long));
|
||||
if (!nums) {
|
||||
fprintf(stderr, "Could not allocate memory for nums\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
inds = malloc(sizeof(unsigned long)*digs_n);
|
||||
if (!inds) {
|
||||
fprintf(stderr, "Could not allocate memory for inds\n");
|
||||
free(nums);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
inds_sum = 0;
|
||||
inds_val = 0;
|
||||
for (base = BASE_MIN; base <= digs_n; base++) {
|
||||
selfdesc(base);
|
||||
}
|
||||
free(inds);
|
||||
free(nums);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void selfdesc(unsigned long i) {
|
||||
unsigned long diff_sum, upper_min, j, lower, upper, k;
|
||||
if (i) {
|
||||
diff_sum = base-inds_sum;
|
||||
upper_min = inds_sum ? diff_sum:base-1;
|
||||
j = i-1;
|
||||
if (j) {
|
||||
lower = 0;
|
||||
upper = (base-inds_val)/j;
|
||||
}
|
||||
else {
|
||||
lower = diff_sum;
|
||||
upper = diff_sum;
|
||||
}
|
||||
if (upper < upper_min) {
|
||||
upper_min = upper;
|
||||
}
|
||||
for (inds[j] = lower; inds[j] <= upper_min; inds[j]++) {
|
||||
nums[inds[j]]++;
|
||||
inds_sum += inds[j];
|
||||
inds_val += inds[j]*j;
|
||||
for (k = base-1; k > j && nums[k] <= inds[k] && inds[k]-nums[k] <= i; k--);
|
||||
if (k == j) {
|
||||
selfdesc(i-1);
|
||||
}
|
||||
inds_val -= inds[j]*j;
|
||||
inds_sum -= inds[j];
|
||||
nums[inds[j]]--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (j = 0; j < base; j++) {
|
||||
putchar(digs[inds[j]]);
|
||||
}
|
||||
puts("");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
$ time ./selfdesc.exe 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
1210
|
||||
2020
|
||||
21200
|
||||
3211000
|
||||
42101000
|
||||
521001000
|
||||
6210001000
|
||||
72100001000
|
||||
821000001000
|
||||
9210000001000
|
||||
A2100000001000
|
||||
B21000000001000
|
||||
C210000000001000
|
||||
D2100000000001000
|
||||
E21000000000001000
|
||||
F210000000000001000
|
||||
G2100000000000001000
|
||||
H21000000000000001000
|
||||
I210000000000000001000
|
||||
J2100000000000000001000
|
||||
K21000000000000000001000
|
||||
L210000000000000000001000
|
||||
M2100000000000000000001000
|
||||
N21000000000000000000001000
|
||||
O210000000000000000000001000
|
||||
P2100000000000000000000001000
|
||||
Q21000000000000000000000001000
|
||||
R210000000000000000000000001000
|
||||
S2100000000000000000000000001000
|
||||
T21000000000000000000000000001000
|
||||
U210000000000000000000000000001000
|
||||
V2100000000000000000000000000001000
|
||||
W21000000000000000000000000000001000
|
||||
|
||||
real 0m0.094s
|
||||
user 0m0.046s
|
||||
sys 0m0.030s
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Split, dupe, check size of number before generating it.
|
||||
IsSdn ← ⨬(/↧=≡(/+=)⊙¤°⊏|0)>10/+..≡⋕°⋕
|
||||
▽⊸≡IsSdn ⇡5e6
|
||||
Loading…
Add table
Add a link
Reference in a new issue