File: digit-groups.pl

package info (click to toggle)
libmath-planepath-perl 117-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,988 kB
  • ctags: 5,587
  • sloc: perl: 99,131; ansic: 299; sh: 233; lisp: 73; makefile: 4
file content (165 lines) | stat: -rw-r--r-- 4,682 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w

# Copyright 2011, 2012 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::PlanePath::Base::Digits 'digit_split_lowtohigh';

# uncomment this to run the ### lines
use Smart::Comments;


{
  # 2^64-1 base7 45012021522523134134601
  # decimal less first digit 2635249153387078802
  #                          2635249153387078656
  require Devel::Peek;
  my $n = ~0;
  my $radix = 7;
  my $digit = $n % $radix;
  ### $digit
  $n /= $radix;
  Devel::Peek::Dump($n);
  $n = int($n);
  Devel::Peek::Dump($n);

  require Math::PlanePath;
  my @digits = digit_split_lowtohigh(~0,$radix);
  ### @digits

  exit 0;
}

{
  # Diagonal
  require Math::BaseCnv;
  require Math::NumSeq::PlanePathN;
  my $seq = Math::NumSeq::PlanePathN->new (planepath=> 'DigitGroups',
                                           line_type => 'Diagonal');
  foreach my $i (0 .. 150) {
    my ($i,$value) = $seq->next;
    my $v2 = Math::BaseCnv::cnv($value,10,2);
    printf "%4d %20s\n", $value, $v2;
  }
  print "\n";
  exit 0;
}

{
  require Math::BaseCnv;
  require Math::PlanePath::DigitGroups;
  foreach my $radix (2 .. 7) {
    print "radix $radix\n";
    my $path = Math::PlanePath::DigitGroups->new (radix => $radix);
    foreach my $coord_max (0 .. 25) {
      my $n_max = $path->xy_to_n(0,0);
      my $x_max = 0;
      my $y_max = 0;
      foreach my $x (0 .. $coord_max) {
        foreach my $y (0 .. $coord_max) {
          my $n = $path->xy_to_n($x,$y);
          ### got: "$x,$y   $n"
          if ($n > $n_max) {
            $x_max = $x;
            $y_max = $y;
            $n_max = $n;
          }
        }
      }
      my $n_max_base = Math::BaseCnv::cnv($n_max,10,$radix);

      my ($n_lo, $n_hi) = $path->rect_to_n_range(0,0,$coord_max,$coord_max);
      my $n_hi_base = Math::BaseCnv::cnv($n_hi,10,$radix);

      print " $coord_max  $x_max,$y_max   n=$n_max [$n_max_base]     cf nhi=$n_hi [$n_hi_base]\n";
    }
    print "\n";
  }
  exit 0;
}

{
  require Math::BaseCnv;
  require Math::PlanePath::DigitGroups;
  foreach my $radix (2 .. 7) {
    print "radix $radix\n";
    my $path = Math::PlanePath::DigitGroups->new (radix => $radix);
    foreach my $exp (1 .. 5) {
      my $coord_min = $radix ** ($exp-1);
      my $coord_max = $radix ** $exp - 1;
      print " $coord_min $coord_max\n";
      my $x_min = $coord_min;
      my $y_min = $coord_min;
      my $n_min = $path->xy_to_n($x_min,$y_min);
      foreach my $x ($coord_min .. $coord_max) {
        foreach my $y ($coord_min .. $coord_max) {
          my $n = $path->xy_to_n($x,$y);
          ### got: "$x,$y   $n"
          if ($n < $n_min) {
            $x_min = $x;
            $y_min = $y;
            $n_min = $n;
          }
        }
      }
      my $n_min_base = Math::BaseCnv::cnv($n_min,10,$radix);

      my ($n_lo, $n_hi) = $path->rect_to_n_range(0,0,$coord_max,$coord_max);
      my $n_lo_base = Math::BaseCnv::cnv($n_lo,10,$radix);

      print " $exp  $x_min,$y_min   n=$n_min [$n_min_base]     cf nlo=$n_lo [$n_lo_base]\n";
    }
    print "\n";
  }
  exit 0;
}
{
  require Math::BaseCnv;
  require Math::PlanePath::DigitGroups;
  foreach my $radix (2 .. 7) {
    print "radix $radix\n";
    my $path = Math::PlanePath::DigitGroups->new (radix => $radix);
    foreach my $exp (1 .. 5) {
      my $coord_max = $radix ** $exp - 1;
      my $n_max = $path->xy_to_n(0,0);
      my $x_max = 0;
      my $y_max = 0;
      foreach my $x (0 .. $coord_max) {
        foreach my $y (0 .. $coord_max) {
          my $n = $path->xy_to_n($x,$y);
          ### got: "$x,$y   $n"
          if ($n > $n_max) {
            $x_max = $x;
            $y_max = $y;
            $n_max = $n;
          }
        }
      }
      my $n_max_base = Math::BaseCnv::cnv($n_max,10,$radix);

      my ($n_lo, $n_hi) = $path->rect_to_n_range(0,0,$coord_max,$coord_max);
      my $n_hi_base = Math::BaseCnv::cnv($n_hi,10,$radix);

      print " $exp  $x_max,$y_max   n=$n_max [$n_max_base]     cf nhi=$n_hi [$n_hi_base]\n";
    }
    print "\n";
  }
  exit 0;
}