cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A372223 Numbers in a hexagonal tiling (seen as concentric rings) which have exactly three neighbors whose difference from it is prime.

This page as a plain text file.
%I A372223 #31 Jul 01 2024 14:36:18
%S A372223 1,2,8,19,20,37,61,128,217,271,398,919,1519,1520,2978,3170,4220,4447,
%T A372223 4681,5677,5941,6488,8269,9920,10621,12481,16651,17558,22448,26227,
%U A372223 29701,34028,34669,35317,35971,56719,60920,61777,74419,75367,80197,88238,93458
%N A372223 Numbers in a hexagonal tiling (seen as concentric rings) which have exactly three neighbors whose difference from it is prime.
%C A372223 A hexagonal tile with number 1 is surrounded by a ring of six hexagonal tiles, starting on the right and numbering the tiles 2 to 7 in a counterclockwise direction. New rings are added in the same fashion, with the next rings being numbered 8 to 19, 20 to 37, and so on (see the illustration below). By finding the difference between tile n and each of its six neighbors we shall define PD(n) to be the number of those differences which are prime. For example, working counter-clockwise around tile 8 the differences are 12, 13, 1, 6, 11, and 29. So PD(8)=3. In the same way, the differences around tile 17 are 1, 10, 11, 1, 16, and 17, hence PD(17) = 2. It can be shown that the maximum value of PD(n) is 3. This sequence lists all tiles for which PD(n)=3 in ascending order.
%C A372223 It can be shown that only the first and last tile of every ring need to be considered.
%H A372223 Antoine Mathys, <a href="/A372223/b372223.txt">Table of n, a(n) for n = 1..10000</a>
%H A372223 Project Euler, <a href="https://projecteuler.net/problem=128">Problem 128 - Hexagonal Tile Differences</a>.
%e A372223 For tile 1, the differences are 1,2,3,4,5,6, thus PD(1)=3 and a(1)=1.
%e A372223 For tile 2, the differences are 6,7,1,1,5,17, thus PD(2)=3 and a(2)=2.
%e A372223 For tile 3, the differences are 6,7,8,1,2,1, thus PD(3)=2 and 3 is not in the list.
%e A372223 Similarly, we see that PD(4)=2, PD(5)=0, PD(6)=2, PD(7)=2, and PD(8)=3. Thus the next term is a(3)=8.
%e A372223         26--25--24--23
%e A372223        /             \
%e A372223       27  12--11--10  22
%e A372223      /   /         \   \
%e A372223    28  13   4---3   9  21
%e A372223    /   /   /     \   \   \
%e A372223   29  14   5  1  2    8  20
%e A372223    \   \   \     /    /   /
%e A372223    30  15   6---7    19 37
%e A372223     \    \          /   /
%e A372223      31   16--17--18  36
%e A372223       \               /
%e A372223        32---33--34--35
%e A372223 .
%o A372223 (C++)
%o A372223 #include <iostream>
%o A372223 bool is_prime (long n)
%o A372223 {
%o A372223   if (n < 2) return false;
%o A372223   if ((n == 2) || (n == 3)) return true;
%o A372223   if ((n % 6 != 1) && (n % 6 != 5)) return false;
%o A372223   for (long x = 1; (6 * x - 1) * (6 * x - 1) <= n; x++) {
%o A372223     if (n % (6 * x - 1) == 0) return false;
%o A372223     if ((6 * x + 1) * (6 * x + 1) > n) break;
%o A372223     if (n % (6 * x + 1) == 0) return false;
%o A372223   }
%o A372223   return true;
%o A372223 }
%o A372223 int main ()
%o A372223 {
%o A372223   constexpr long MAX_INDEX = 10000;
%o A372223   if (MAX_INDEX >= 1) std::cout << "1 1\n";
%o A372223   if (MAX_INDEX >= 2) std::cout << "2 2\n";
%o A372223   // We count the rings starting at 0 (the one containing 1)
%o A372223   for (long r = 2, index = 2; index < MAX_INDEX; r++) {
%o A372223     if (!is_prime (6 * r - 1)) continue;
%o A372223     // first cell
%o A372223     if (!is_prime (6 * r + 1)) goto LAST;
%o A372223     if (!is_prime (12 * r + 5)) goto LAST;
%o A372223     index++;
%o A372223     std::cout << index << " " << 3 * (r - 1) * r + 2 << '\n';
%o A372223     if (index == MAX_INDEX) break;
%o A372223 LAST:
%o A372223     // last cell
%o A372223     if (!is_prime (6 * r + 5)) continue;
%o A372223     if (!is_prime (12 * (r - 1) + 5)) continue;
%o A372223     index++;
%o A372223     std::cout << index << " " << 3 * r * (r + 1) + 1 << '\n';
%o A372223   }
%o A372223 }
%K A372223 nonn
%O A372223 1,2
%A A372223 _Antoine Mathys_, Apr 22 2024