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.

A332341 Prime scale sequence (see comments).

This page as a plain text file.
%I A332341 #21 May 12 2022 10:01:35
%S A332341 -2,-3,5,-7,-11,-13,31,-17,-19,-23,59,-29,-37,-41,107,-43,-47,-53,-61,
%T A332341 -67,271,-71,-73,-79,223,-83,-89,-97,269,-101,-103,-109,313,-113,-127,
%U A332341 -131,-137,-139,647,-149,-151,-157,457,-163,-167,-173,503,-179,-181,-191,-193,-197,941
%N A332341 Prime scale sequence (see comments).
%C A332341 Take a double-pan balance scale and name the pans "negative" and "positive". At each step, the question is: "Is there an unused prime that would balance the scale if added to the positive pan?" If the answer is positive, add that prime to the positive pan. Otherwise, add the smallest unused prime to the negative pan.
%C A332341 Is the number of primes in the positive pan infinite?
%H A332341 Michael S. Branicky, <a href="/A332341/b332341.txt">Table of n, a(n) for n = 1..10000</a>
%e A332341 2 and 3 unbalance the scale (and are negative), but 5 = 2 + 3 balances it (and is positive).
%t A332341 a[1]=-2;a[n_]:=a[n]=Module[{tab=Table[a[i],{i,1,n-1}],
%t A332341 totalN=Abs[Total[Select[Table[a[i],{i,1,n-1}],Negative]]],
%t A332341 totalP=Total[Select[Table[a[i],{i,1,n-1}],Positive]],
%t A332341 l=NextPrime[Last[Select[Table[a[i],{i,1,n-1}],Negative]],-1],
%t A332341 m=NextPrime[Abs[Last[Select[Table[a[i],{i,1,n-1}],Negative]]]]},
%t A332341 If[totalN==totalP,If[PrimePi[tab[[-1]]]-PrimePi[Abs[tab[[-2]]]]==1,-NextPrime[tab[[-1]]],
%t A332341 If[FreeQ[Abs[tab],m],-m,While[!FreeQ[Abs[tab],m],m=NextPrime[m]];-m]],
%t A332341 If[PrimeQ[totalN-totalP]&&FreeQ[Abs[tab],totalN-totalP],totalN-totalP,
%t A332341 If[FreeQ[Abs[tab],Abs[l]],l,While[!FreeQ[Abs[tab],Abs[l]],l=NextPrime[l,-1]];l]]]];a/@Range[53]
%o A332341 (Python)
%o A332341 from itertools import islice
%o A332341 from sympy import isprime, nextprime
%o A332341 def agen(): # generator of terms
%o A332341     used, d, nextp = set(), 0, 2
%o A332341     while True:
%o A332341         if d > 0 and d not in used and isprime(d):
%o A332341             used.add(d); yield d; d = 0
%o A332341         while nextp in used:
%o A332341             nextp = nextprime(nextp)
%o A332341         used.add(nextp); yield -nextp; d += nextp
%o A332341 print(list(islice(agen(), 53))) # _Michael S. Branicky_, May 12 2022
%Y A332341 Cf. A000040, A101544, A332787, A332788.
%K A332341 sign
%O A332341 1,1
%A A332341 _Ivan N. Ianakiev_, Feb 10 2020