1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
|
#!/usr/bin/perl -w
# Copyright 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Kevin Ryde
# This file is part of Math-PlanePath.
#
# Math-PlanePath is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# Math-PlanePath is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
use 5.004;
use strict;
use Math::BaseCnv 'cnv';
use Math::BigInt try => 'GMP';
use Math::PlanePath::AlternatePaper 124; # v.124 for n_to_n_list()
use List::Util 'min';
use Test;
plan tests => 36;
use lib 't','xt';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings(); }
use MyOEIS;
my $paper = Math::PlanePath::AlternatePaper->new;
#------------------------------------------------------------------------------
# A007088 -- N on X axis in base 4
MyOEIS::compare_values
(anum => 'A007088',
max_value => 2**28,
func => sub {
my ($count) = @_;
my @got;
for (my $x = 0; @got < $count; $x++) {
my $n = $paper->xy_to_n ($x,0);
push @got, cnv($n,10,4);
}
return \@got;
});
# A169965 -- N on X=Y diagonal in base 4
MyOEIS::compare_values
(anum => 'A169965',
max_value => 2**28,
func => sub {
my ($count) = @_;
my @got;
for (my $i = 0; @got < $count; $i++) {
my $n = $paper->xy_to_n ($i,$i);
push @got, cnv($n,10,4);
}
return \@got;
});
#------------------------------------------------------------------------------
# A004277 -- num visits in column X
MyOEIS::compare_values
(anum => 'A004277',
func => sub {
my ($count) = @_;
my @got;
for (my $x = 0; @got < $count; $x++) {
my $total = 0;
for (my $y = 0; ; $y++) {
my @n_list = $paper->xy_to_n_list ($x,$y) or last;
$total += scalar(@n_list);
}
push @got, $total;
}
return \@got;
});
#------------------------------------------------------------------------------
# A151666 -- predicate N on X axis
MyOEIS::compare_values
(anum => 'A151666',
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, $y==0 ? 1 : 0;
}
return \@got;
});
# A270803 -- predicate segment N on X=Y leading diagonal, except not N=0
MyOEIS::compare_values
(anum => 'A270803',
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start; @got < $count; $n++) {
my ($x,$y) = $paper->n_to_xy ($n);
my ($x1,$y1) = $paper->n_to_xy ($n+1);
push @got, $n!=0 && $x==$y || $x1==$y1 ? 1 : 0;
}
return \@got;
});
# A270804 -- N segments of diagonal stair step
MyOEIS::compare_values
(anum => 'A270804',
func => sub {
my ($count) = @_;
my @got;
for (my $i = 0; @got < $count; $i++) {
# i+1,i+1
# |
# i,i -- i+1,i
push @got, $paper->xyxy_to_n ($i,$i, $i+1,$i);
@got < $count or last;
push @got, $paper->xyxy_to_n ($i+1,$i, $i+1,$i+1);
}
return \@got;
});
#------------------------------------------------------------------------------
# A052955 single-visited points to N=2^k
MyOEIS::compare_values
(anum => 'A052955',
max_value => 1000,
func => sub {
my ($count) = @_;
my @got = (1); # extra initial 1
for (my $k = 0; @got < $count; $k++) {
push @got, MyOEIS::path_n_to_singles ($paper, 2**$k);
}
return \@got;
});
# A052940 single-visited points to N=4^k
MyOEIS::compare_values
(anum => 'A052940',
max_value => 1000,
func => sub {
my ($count) = @_;
my @got = (1); # initial 1 instead of 2
for (my $k = 1; @got < $count; $k++) {
push @got, MyOEIS::path_n_to_singles ($paper, 4**$k);
}
return \@got;
});
#------------------------------------------------------------------------------
# A068915 Y when N even, X when N odd
MyOEIS::compare_values
(anum => 'A068915',
func => sub {
my ($count) = @_;
my @got;
for (my $n = 0; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, ($n%2==0 ? $y : $x);
}
return \@got;
});
# also equivalent to X when N even, Y when N odd, starting from N=1
MyOEIS::compare_values
(anum => q{A068915},
func => sub {
my ($count) = @_;
my @got;
for (my $n = 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, ($n%2==0 ? $x : $y);
}
return \@got;
});
#------------------------------------------------------------------------------
# A080079 X-Y of last time on X+Y=s anti-diagonal
MyOEIS::compare_values
(anum => 'A080079',
func => sub {
my ($count) = @_;
my @got;
my @occur;
my $target = 1;
for (my $n = $paper->n_start + 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
my $s = $x + $y;
$occur[$s]++;
if ($occur[$s] == $s) {
push @got, $x-$y;
$target++;
}
}
return \@got;
});
# A020991 N-1 of last time on X+Y=s anti-diagonal
MyOEIS::compare_values
(anum => 'A020991',
func => sub {
my ($count) = @_;
my @got;
my @occur;
my $target = 1;
for (my $n = $paper->n_start + 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
my $s = $x + $y;
$occur[$s]++;
if ($occur[$s] == $s) {
push @got, $n-1;
$target++;
}
}
return \@got;
});
# A053645 Y of last time on X+Y=s anti-diagonal
MyOEIS::compare_values
(anum => 'A053645',
max_count => 500, # because simple linear search
func => sub {
my ($count) = @_;
my @got;
my @occur;
my $target = 1;
for (my $n = $paper->n_start + 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
my $s = $x + $y;
$occur[$s]++;
if ($occur[$s] == $s) {
push @got, $y;
$target++;
}
}
return \@got;
});
# A053644 X of last time on X+Y=s anti-diagonal
MyOEIS::compare_values
(anum => 'A053644',
max_count => 500, # because simple linear search
func => sub {
my ($count) = @_;
my @got;
my @occur = (-1); # hack for s=0 occurring 1 time
my $target = 0;
for (my $n = $paper->n_start; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
my $s = $x + $y;
$occur[$s]++;
if ($occur[$s] == $s) {
push @got, $x;
$target++;
}
}
return \@got;
});
#------------------------------------------------------------------------------
# A212591 N-1 of first time on X+Y=s anti-diagonal
# seq 0, 1, 2, 5, 8, 9, 10, 21, 32, 33, 34, 37, 40, 41, 42, 85
# N 0 1 2 3 6, 9, 10, 11, 22, ...
MyOEIS::compare_values
(anum => 'A212591',
max_count => 1000, # because simple linear search
func => sub {
my ($count) = @_;
my @got;
my $target = 1;
for (my $n = $paper->n_start + 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
my $s = $x + $y;
if ($s == $target) {
push @got, $n-1;
$target++;
}
}
return \@got;
});
# A047849 N of first time on X+Y=2^k anti-diagonal
MyOEIS::compare_values
(anum => 'A047849',
max_count => 10, # because simple linear search
func => sub {
my ($count) = @_;
my @got;
for (my $k=0; @got < $count; $k++) {
my $s = 2**$k;
my @n_list;
foreach my $y (0 .. $s) {
my $x = $s - $y;
$x+$y == $s or die;
push @n_list, $paper->xy_to_n_list($x,$y);
}
push @got, min(@n_list);
}
return \@got;
});
#------------------------------------------------------------------------------
# Skd segments in direction
foreach my $elem (['A005418', 1,0, 1], # East
['A051437', 0,1, 2], # North
['A122746', -1,0, 3], # West
['A007179', 0,-1, 1], # South
) {
my ($anum, $want_dx,$want_dy, $initial_k) = @$elem;
MyOEIS::compare_values
(anum => $anum,
max_count => 14,
func => sub {
my ($count) = @_;
my $path = Math::PlanePath::AlternatePaper->new;
my @got;
for (my $k = $initial_k||0; @got < $count; $k++) {
my ($n_lo,$n_hi) = $path->level_to_n_range($k);
push @got, scalar(grep {
my ($dx,$dy) = $path->n_to_dxdy($_);
$dx==$want_dx && $dy==$want_dy
} $n_lo .. $n_hi-1);
}
return \@got;
});
}
# A122746 - also area increment to N=2^k
MyOEIS::compare_values
(anum => q{A122746},
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got;
for (my $k = 2; @got < $count; $k++) {
push @got, (MyOEIS::path_enclosed_area($paper, 2**($k+1))
- MyOEIS::path_enclosed_area($paper, 2**$k));
}
return \@got;
});
#------------------------------------------------------------------------------
# A126684 - N single-visited points
MyOEIS::compare_values
(anum => 'A126684',
func => sub {
my ($count) = @_;
my $path = Math::PlanePath::AlternatePaper->new;
my @got;
for (my $n = 0; @got < $count; $n++) {
my @n_list = $path->n_to_n_list($n);
if (@n_list == 1) {
push @got, $n;
}
}
return \@got;
});
# A176237 - N double-visited points
MyOEIS::compare_values
(anum => 'A176237',
func => sub {
my ($count) = @_;
my $path = Math::PlanePath::AlternatePaper->new;
my @got;
for (my $n = 0; @got < $count; $n++) {
my @n_list = $path->n_to_n_list($n);
if (@n_list == 2) {
push @got, $n;
}
}
return \@got;
});
#------------------------------------------------------------------------------
# A274230 - area = doubles to N=2^k
MyOEIS::compare_values
(anum => 'A274230',
max_count => 14,
func => sub {
my ($count) = @_;
my $path = Math::PlanePath::AlternatePaper->new;
my @got;
for (my $k = 0; @got < $count; $k++) {
my ($n_lo,$n_hi) = $path->level_to_n_range($k);
push @got, scalar(grep {
my @n_list = $path->n_to_n_list($_);
@n_list == 2; # double-visited
} $n_lo .. $n_hi);
}
return \@got;
});
#------------------------------------------------------------------------------
# A181666 - n XOR other(n) occurring
MyOEIS::compare_values
(anum => 'A181666',
func => sub {
my ($count) = @_;
require Math::PlanePath::Base::Digits;
my $path = Math::PlanePath::AlternatePaper->new;
my %seen;
my @got;
my $target_n = 256;
for (my $n = 0; @got < $count || $n < $target_n; $n++) {
my @n_list = $path->n_to_n_list($n);
@n_list >= 2 or next;
my $xor = $n_list[0] ^ $n_list[1];
next if $seen{$xor}++;
push @got, $xor/4;
($target_n) = Math::PlanePath::Base::Digits::round_up_pow($n,2);
}
@got = sort {$a<=>$b} @got;
$#got = $count-1;
return \@got;
});
#------------------------------------------------------------------------------
# A001196 - N on X axis, base 4 digits 0,3 only
MyOEIS::compare_values
(anum => 'A001196',
func => sub {
my ($count) = @_;
my $path = Math::PlanePath::AlternatePaper->new (arms => 3);
my @got;
for (my $x = Math::BigInt->new(0); @got < $count; $x++) {
my $n = $path->xy_to_n($x,0);
push @got, $n;
}
return \@got;
});
#------------------------------------------------------------------------------
# A077957 -- Y at N=2^k, being alternately 0 and 2^(k/2)
MyOEIS::compare_values
(anum => 'A077957',
max_count => 200,
func => sub {
my ($count) = @_;
my @got;
for (my $n = Math::BigInt->new(2); @got < $count; $n *= 2) {
my ($x,$y) = $paper->n_to_xy($n);
push @got, $y;
}
return \@got;
});
#------------------------------------------------------------------------------
# A028399 boundary to N=2*4^k
MyOEIS::compare_values
(anum => 'A028399',
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got = (0);
for (my $k = 0; @got < $count; $k++) {
push @got, MyOEIS::path_boundary_length($paper, 2*4**$k);
}
return \@got;
});
# A131128 boundary to N=4^k
MyOEIS::compare_values
(anum => 'A131128',
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got = (1);
for (my $k = 0; @got < $count; $k++) {
push @got, MyOEIS::path_boundary_length($paper, 4**$k);
}
return \@got;
});
# A027383 boundary/2 to N=2^k
# is also boundary length verticals or horizontals since boundary is half
# verticals and half horizontals
MyOEIS::compare_values
(anum => 'A027383',
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got;
for (my $k = 0; @got < $count; $k++) {
push @got, MyOEIS::path_boundary_length($paper, 2**$k) / 2;
}
return \@got;
});
#------------------------------------------------------------------------------
# A060867 area to N=2*4^k
MyOEIS::compare_values
(anum => 'A060867',
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got;
for (my $k = 1; @got < $count; $k++) {
push @got, MyOEIS::path_enclosed_area($paper, 2*4**$k);
}
return \@got;
});
# A134057 area to N=4^k
MyOEIS::compare_values
(anum => 'A134057',
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got;
for (my $k = 0; @got < $count; $k++) {
push @got, MyOEIS::path_enclosed_area($paper, 4**$k);
}
return \@got;
});
# A027556 area*2 to N=2^k
MyOEIS::compare_values
(anum => 'A027556',
max_value => 10_000,
func => sub {
my ($count) = @_;
my @got;
for (my $k = 0; @got < $count; $k++) {
push @got, MyOEIS::path_enclosed_area($paper, 2**$k) * 2;
}
return \@got;
});
#------------------------------------------------------------------------------
# A106665 -- turn 1=left, 0=right
# OFFSET=0 cf first turn at N=1 here
MyOEIS::compare_values
(anum => 'A106665',
func => sub {
my ($count) = @_;
require Math::NumSeq::PlanePathTurn;
my $seq = Math::NumSeq::PlanePathTurn->new (planepath => 'AlternatePaper',
turn_type => 'Left');
my @got;
while (@got < $count) {
my ($i,$value) = $seq->next;
push @got, $value;
}
return \@got;
});
#------------------------------------------------------------------------------
# A090678 "non-squashing partitions" A088567 mod 2
# and A121241 which is 1,-1
# almost but not quite arms=2 turn_type=Left
# A121241 1,-1
# A110036 2,0,-2
# A110037 1,0,-1
# MyOEIS::compare_values
# (anum => 'A090678',
# func => sub {
# my ($count) = @_;
# require Math::NumSeq::PlanePathTurn;
# my $seq = Math::NumSeq::PlanePathTurn->new (planepath => 'AlternatePaper,arms=2',
# turn_type => 'Left');
# my @got = (1,1,1,0,0,1,0,1,0,1,1,0,1,0,0,1,0,1);
# while (@got < $count) {
# my ($i,$value) = $seq->next;
# push @got, $value;
# }
# return \@got;
# });
#------------------------------------------------------------------------------
# A020985 - Golay/Rudin/Shapiro is dX and dY alternately
# also is dSum in Math::NumSeq::PlanePathDelta
MyOEIS::compare_values
(anum => q{A020985}, # catalogued
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start; @got < $count; ) {
{
my ($dx, $dy) = $paper->n_to_dxdy ($n++);
push @got, $dx;
}
last unless @got < $count;
{
my ($dx, $dy) = $paper->n_to_dxdy ($n++);
push @got, $dy;
}
}
return \@got;
});
# A020987 GRS as 0,1
MyOEIS::compare_values
(anum => 'A020987',
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start; @got < $count; ) {
{
my ($dx, $dy) = $paper->n_to_dxdy ($n++);
push @got, $dx > 0 ? 1 : 0;
}
last unless @got < $count;
{
my ($dx, $dy) = $paper->n_to_dxdy ($n++);
push @got, $dy > 0 ? 1 : 0;
}
}
return \@got;
});
#------------------------------------------------------------------------------
# A093573+1 - triangle of positions where cumulative=k
# cumulative A020986 starts n=0 for GRS(0)=0 (A020985)
# 0,
# 1, 3,
# 2, 4, 6,
# 5, 7, 13, 15,
# 8, 12, 14, 16, 26,
# 9, 11, 17, 19, 25, 27
#
# cf diagonals
# 0
# 1
# 2, 4
# 3,7, 5
# 8, 6,14, 16
# 9,13, 15,27, 17
MyOEIS::compare_values
(anum => 'A093573',
func => sub {
my ($count) = @_;
my @got;
OUTER: for (my $sum = 1; ; $sum++) {
my @n_list;
foreach my $y (0 .. $sum) {
my $x = $sum - $y;
push @n_list, $paper->xy_to_n_list($x,$y);
}
@n_list = sort {$a<=>$b} @n_list;
foreach my $n (@n_list) {
last OUTER if @got >= $count;
push @got, $n-1;
}
}
return \@got;
});
#------------------------------------------------------------------------------
# A020986 - GRS cumulative
# X+Y, starting from N=1 (doesn't have X+Y=0 for N=0)
MyOEIS::compare_values
(anum => 'A020986',
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start + 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, $x+$y;
}
return \@got;
});
# is X coord undoubled, starting from N=2 (doesn't have X=0 for N=0)
MyOEIS::compare_values
(anum => q{A020986},
func => sub {
my ($count) = @_;
my @got;
for (my $n = 2; @got < $count; $n += 2) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, $x;
}
return \@got;
});
#------------------------------------------------------------------------------
# A022155 - positions of -1, is S,W steps
MyOEIS::compare_values
(anum => 'A022155',
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start; @got < $count; $n++) {
my ($dx,$dy) = $paper->n_to_dxdy($n);
if ($dx < 0 || $dy < 0) {
push @got, $n;
}
}
return \@got;
});
#------------------------------------------------------------------------------
# A203463 - positions of 1, is N,E steps
MyOEIS::compare_values
(anum => 'A203463',
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start; @got < $count; $n++) {
my ($dx,$dy) = $paper->n_to_dxdy($n);
if ($dx > 0 || $dy > 0) {
push @got, $n;
}
}
return \@got;
});
#------------------------------------------------------------------------------
# A020990 - Golay/Rudin/Shapiro * (-1)^k cumulative, is Y coord undoubled,
# except N=0
MyOEIS::compare_values
(anum => 'A020990',
func => sub {
my ($count) = @_;
my @got;
for (my $n = 2; @got < $count; $n += 2) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, $y;
}
return \@got;
});
MyOEIS::compare_values
(anum => q{A020990}, # checking again
func => sub {
my ($count) = @_;
my @got;
for (my $n = $paper->n_start + 1; @got < $count; $n++) {
my ($x, $y) = $paper->n_to_xy ($n);
push @got, $x-$y;
}
return \@got;
});
#------------------------------------------------------------------------------
exit 0;
|