显示OEIS序列


29

整数序列的在线百科全书(OEIS)是整数序列的在线数据库。它包含将近280000个数学感兴趣的序列。

序列示例:

您的任务是编写一个显示尽可能多的OEIS序列的程序或函数,其源代码最大为100字节。您的程序应接受序列ID(不带前缀A和零)作为输入,并输出该序列中的前20个数字。

您无权直接从OEIS网站获取数据;所有序列都必须由您的代码计算。

计分

分数是程序可以显示的OEIS序列的数量。答案必须列出其程序识别的序列的ID。

这是Java 8中的有效答案:

(int a) -> {
    for (int i = 0; i < 20; i++) {
        System.out.println(a==27?i+1:i*i); 
    }
};

该程序可以显示正整数(A000027-输入27)和平方(A000290-输入290),因此其得分为2。

注意

请避免刮擦整个OEIS网站:-)您可以下载序列名称(约3兆)或序列值(约9兆)。请注意,此下载受OEIS最终用户许可协议的保护


我们可以编写它以便它以前导0开头吗?
TrojanByAccident

2
哇!OEIS上的挑战!
JungHwan Min

1
@TrojanByAccident,如果您的想法是连接到OEIS,则PPCG不允许这样做
Nathan Merrill

@NathanMerrill我不确定在这种情况下是否算在内
TrojanByAccident

是否允许功能?
xnor

Answers:


25

CJam(2182 2780 3034序列)

{:ZA3#:Cb(40-z_!!:B-\+CbB)/)_mqmo:M+:NK{)[N0{N1$_*-@/M@+1$md@M@-}K*]<W%B{X0@{2$*+\}%}*ZB&=}%\C)<f*}

这为包含范围提供了正确答案

  • [A040000, A040003][A040005, A040008][A040011, A040013]A040015[A040019, A040022]A040024[A040029, A040033]A040035A040037[A040041, A040043]A040048A040052[A040055, A040057]A040059A040063[A040071, A040074]A040077A040080[A040090, A040091][A040093, A040094]A040097A040099[A040109, A040111]A040118A040120[A040131, A040135]A040137A040139[A040142, A040143]A040151[A040155, A040157]A040166A040168[A040181, A040183][A040185, A040968]
  • [A041006, A041011][A041014, A042937]
  • A006983[A011734, A011745][A023975, A023976][A025438, A025439][A025443, A025444]A025466A025469[A034422, A034423]A034427A034429A034432A034435[A034437, A034439]A034441A034443A034445A034447[A034449, A034459][A034461, A034462][A034464, A034469]A034471A034473[A034475, A034477][A034479, A034487][A034489, A034490][A034492, A034493],,,,,,,,,,,,,,,,,,,,,,,,,,,,,,A034495[A034497, A034512][A034514, A034516][A034518, A034523][A034525, A034582]A036861A047752A052375A055967A061858A065687A066035A067159A067168A070097A070202A070204[A070205, A070206]A072325A072769A076142A082998A083344A085974A085982A086007A086015A089458A093392A094382A105517A108322A111855A111859[A111898, A111899]A112802A122180A129947A137579A159708[A161277, A161280]A165766A167263A178780A178798A180472A180601A181340A181735A184946A185037A185203[A185237, A185238][A185245, A185246]A185255A185264A185284A191928A192541A197629A198255A200214A206499A210632A212619[A217148, A217149]A217151[A217155, A217156]A228953A230533A230686A235044A235358A236265A236417A236460A238403[A243831, A243836]A248805A250002A256974A260502A264668A276183A277165A280492A280815

A040???序列对应于非理性平方根的持续馏分从sqrt(2)sqrt(1000)(与对应于先前在OEIS出现,但方便地填充有随机序列的人的间隙)。该A041???序列对应于连分数的分子和分母渐近非理性平方根从sqrt(6)sqrt(1000)(与对应于所述间隙sqrt(10),在A005667 and A005668)。其他分类的序列的前二十个值均为零。

答案包含了GolfScript中我的两个较早答案的元素:

非常感谢xnor提供的简短封闭格式x -> x + round(sqrt(x))映射序列偏移量,该偏移量等于sqrt的值。与我之前的计算(生成非平方的列表并按索引选择)相比,节省的费用足以为大多数超出范围的索引提供全零的后备。


第n个非正方形由n + round(sqrt(n))?给出可能会很有用。
xnor

@xnor,很好。我试图找到一个不错的公式,sqrt(n)但我没有想到四舍五入而不是四舍五入。这样可以立即节省三个字节,这不足以添加后备功能,但可以使希望保持活力。
彼得·泰勒

35

Python 2,875序列

print', '.join('%020d'%(10**20/(input()-21004)))

适用于序列21016(小数位1/12)到21999(小数位1/995)中的875。

我发现了这种复杂的搜索算法,可以随意输入序列ID。范围中的某些序列不是这种格式,而是出现在其他位置(感谢Mitchell Spector指出这一点)。例如,21021不是1/17的扩展。

即使有中断,1 / n的序列也显示为id n+21004。其余的不移位,但是丢失的序列出现在其他位置。例如,1/17显示为7450

我使用下载的序列名称副本计算了匹配的对象。

不同的块给出了从16742848的序列 17664的

n=input()-16729
for i in range(20):k=n/12;a=int((8*k+1)**.5/2+.5);print(a*i+k-a*(a-1)/2)**(n%12+1)

这些都有形式n -> (a*n+b)^c,在哪里2≤a≤12, 0≤b<a, 1≤c≤12。该代码通过反三角数和模来提取系数。与以前一样,并非该范围内的所有序列都匹配。如果这两个表达式可以容纳100个字节,则将给出1723个序列。

有希望的块:

  • 1929个匹配序列:41006 42397,连续分数收敛的分子和分母。
  • 〜3300个匹配序列:147999151254:如果可以找到向量列表的排序方式,则Z ^ 3上的数。

通过删除所有数字(数字,减号,小数点)对OEIS序列名称进行分组,这是其他潜在块的类别。它们按出现次数排序。

3010    Number of walks within N^ (the first octant of Z^) starting at (,,) and consisting of n steps taken from {(, , ), (, , ), (, , ), (, , ), (, , )}
2302    Number of reduced words of length n in Coxeter group on  generators S_i with relations (S_i)^ = (S_i S_j)^ = I
979     Primes congruent to  mod 
969     Numerators of continued fraction convergents to sqrt()
967     Denominators of continued fraction convergents to sqrt()
966     Continued fraction for sqrt()
932     Decimal expansion of /
894     Duplicate of A
659     Partial sums of A
577     Divisors of 
517     Inverse of th cyclotomic polynomial
488     Expansion of /((x)(x)(x)(x))
480     Decimal expansion of th root of 
471     Number of nX  arrays with each element x equal to the number its horizontal and vertical neighbors equal to ,,,, for x=,,,,
455     First differences of A
448     Decimal expansion of log_ ()
380     Numbers n such that string , occurs in the base  representation of n but not of n+
378     Erroneous version of A
375     Numbers n such that string , occurs in the base  representation of n but not of n
340     Numbers n with property that in base  representation the numbers of 's and 's are  and , respectively

35个序列:

c=input()
for n in range(20):print[(c-1010)**n,(c-8582)*n][c>2e3]

8585(3的倍数)到8607(25的倍数)和1018的作品(8的幂)到1029(19的幂)有效。方便地,这些都按id排序在一个块中。

这仅使用了100个允许的字节中的65个,并且还没有完全被使用,因此我将寻找另一个不错的块。


哈哈,真好!
Maltysen

也较短:lambda n:range(0,(n-8582)*20,n-8582)
Maltysen

@Maltysen Spec说过程序,所以我同意了。我会问的。
xnor

2
好主意,但我不认为范围21016-21999完全由倒数组成。例如,A21021为1、33、727、13365、221431、3428733 ...,而不是1/17的十进制数字。我没有检查一下哪些序列是倒数,哪些不是。
米切尔·史佩克特

1
@xnor但是您会得到许多匹配项,您可以将其与我的答案相结合,以将另一个252添加到计数中:如果输入不在21016-21999范围内,则输出20 0。(我的252个序列中没有一个都在该范围内。)
Mitchell Spector

29

Bash + coreutils,252个序列

yes 0|head -20

在线尝试!

可在252个OEIS序列上工作:A000004,A006983,A011734,A011735,A011736,A011737,A011738,A011739,A011740,A011741,A011742,A011743,A011744,A011745,A023975,A023976,A025438,A025439,A025443,A025444,A025466, A034422,A034423,A034427,A034429,A034432,A034435,A034437,A034438,A034439,A034441,A034443,A034445,A034447,A034449,A034450,A034451,A034452,A034453,A034454,A034455,A034456,A034457,A034458,A034459, A034462,A034464,A034465,A034466,A034467,A034468,A034469,A034471,A034473,A034475,A034476,A034477,A034479,A034480,A034481,A034482,A034483,A034484,A034485,A034486,A034487,A034489,A034490,A034492, A034495,A034497,A034498,A034499,A034500,A034501,A034502,A034503,A034504,A034505,A034506,A034507,A034508,A034509,A034510,A034511,A034512,A034514,A034515,A034516,A034518,A034519,A034520,A034521,A034522,A034523,A034525,A034526,A034527,A034528,A034529,A034530,A034531,A034532,A034533,A034534,A034535,A034536,A034537,A034538,A034539,A034540,A034541,A034542, A034544,A034545,A034546,A034547,A034548,A034549,A034550,A034551,A034552,A034553,A034554,A034555,A034556,A034557,A034558,A034559,A034560,A034561,A034562,A034563,A034564,A034565,A034566,A034567, A034569,A034570,A034571,A034572,A034573,A034574,A034575,A034576,A034577,A034578,A034579,A034580,A034581,A034582,A036861,A047752,A052375,A055967,A061858,A065687,A066035,A067159,A067168,A070097 A070204,A070205,A070206,A072325,A072769,A076142,A082998,A083344,A085974,A085982,A086007,A086015,A089458,A093392,A094382,A105517,A108322,A111855,A111859,A111898,A111899,A112802,A122180,A129947,A137579,A159708,A161277,A161278,A161279,A161280,A165766,A167263,A178780,A178798,A180472,A180601,A181340,A181735,A184946,A185037,A185203,A185237,A185185246,A185245,A185245, A185255,A185264,A185284,A191928,A192541,A197629,A198255,A200214,A206499,A210632,A212619,A217148,A217149,A217151,A217155,A217156,A228953,A230533,A230686,A235044,A235358,A236265,A236417,A236460, A243831,A243832,A243833,A243834,A243835,A243836,A248805,A250002,A256974,A260502,A264668,A276183,A277165,A280492,A280815A198255,A200214,A206499,A210632,A212619,A217148,A217149,A217151,A217155,A217156,A228953,A230533,A230686,A235044,A235358,A236265,A236417,A236460,A238403,A243831,A243832,A243833,A243834,A243835, A248805,A250002,A256974,A260502,A264668,A276183,A277165,A280492,A280815A198255,A200214,A206499,A210632,A212619,A217148,A217149,A217151,A217155,A217156,A228953,A230533,A230686,A235044,A235358,A236265,A236417,A236460,A238403,A243831,A243832,A243833,A243834,A243835, A248805,A250002,A256974,A260502,A264668,A276183,A277165,A280492,A280815


4
嘿,好主意!
乔纳森·艾伦

12

Python(含sympy),144 146个序列

import sympy
f=lambda a,M=16627:[int(c)for c in str(sympy.log((a<M)*46.5+4+a-M).n(20))if'.'<c][-20:]

该功能f适用于146个序列A016578A016723(含)。

所有这些都是在repl.it上由测试工具输出的。

49个序列A016578通过A016626是log(3/2),log(5/2),log(7/2),...,log(99/2)的十进制扩展。

97个序列A016627通过A016723是log(4),log(5),log(6),...,log(100)的十进制扩展。

49的前两个从第一个小数位开始,因为它们的对数值小于1,因此对调用结果乘以20的小数点后两位到20位有效数字。将过滤出的小数位字符,石膏其余每个数字字符到一个整数(尽管也许不是必要的)。[-20:]...n(20)if'.'<cint(c)


10

果冻,1127年年 1975年序列

-目前结合了xnorMitchell Spector的发现,但在78个字节上仍有一定的增长空间。去给他们一些信用!

0x20
_21004µȷ20:DU¢oU
20Ḷ×⁸+µ*þ12
11R‘µẋ`€F$ç"Ḷ€F$;/
_108ị¢

“æÑØ‘×ȷ3¤>J×$S‘µĿ

TryItOnline!

1975年的顺序是:

  • 以二十个零开头的252(输入外部的行为 [16000,21999]);
  • 符合公式的848个序列位于1674217664范围内(a*n+b)**c(输入[16000,17999]);和
  • 875个序列,其范围为2101621999,与的十进制扩展名匹配1/n(输入的行为[18000,21999])。

怎么样?

0x20 - Link 1, TwentyZeros: no arguments
0    - zero
  20 - twenty
 x   - repeat

_21004µȷ20:DU¢oU - Link 2, DecimalExpansionOfReciprocal: oeisIndexNumber
      µ          - monadic chain separation
       ȷ20       - 1e20
_21004           - subtract 21004 from oeisNumber to get the n value
          :      - integer division, i.e. 1e20 // n
           D     - decimal list
            U    - reverse
             ¢   - call last link (1) as a nilad, i.e. get twenty zeros
              o  - logical or, i.e. pad the right of the reversed list to twenty with zeros
               U - reverse again

20Ḷ×⁸+µ*þ12 - Link 3, BlockOf12abcFormulaResults: a, b
20Ḷ         - lowered range of 20 [0,1,...,19] i.e. the values of n in (a*n+b)**c
    ⁸       - left argument, a
   ×        - multiply
     +      - add b
      µ     - monadic chain separation
        þ12 - outer product with [1,2,...,12] of... i.e. the values of c in (a*n+b)**c
       *    -     exponentiation

11R‘µẋ`€F$ç"Ḷ€F$;/ - link 4, AllabcFormulaResults: no aguments
11R                - range of 11 [1,2,...,11]
   ‘               - increment   [2,3,...12] i.e. the values of a in (a*n+b)**c
    µ              - monadic chain separation
         $         - last two links as a monad
     ẋ`€           - repeat list with repeated arguments for €ach [[2,2],[3,3,3],...,[12,12,12,12,12,12,12,12,12,12,12,12]]
        F          - flatten into one list
               $   - last two links as a monad
            Ḷ€     - lowered range of €ach [[0,1],[0,1,2],...,[0,1,2,3,4,5,6,7,8,9,10,11]]
              F    - flatten into one list
          ç"       - zip with (") last link (3) as a dydad (ç) i.e. get all the results
                 / - reduce with
                ;  - concatenation i.e. make the list of lists of lists one list of lists.

_108ị¢ - Link 5, abcFormulaResult: oeisIndexNumber
_108   - subtract 108 from the oeisNumber (indexes in Jelly are modular and there are 924 entries, this is shorter than _16740)
     ¢ - call last link (4) as a nilad
    ị  - index into i.e. get the one relevant result of 20 terms

 - Link 6, an empty link (cheaper in bytes than the %6 alternative in the main link)

“æÑØ‘×ȷ3¤>J×$S‘µĿ - Main link: oeisIndexNumber           e.g. 1-15999; 16000-17999; 18000-21999; 22000+
        ¤         - nilad followed by link(s) as a nilad
“æÑØ‘             - codePage indexes [22,16,18]
      ȷ3          - 1e3
     ×            - multiply [22000,16000,18000]
         >        - greater than (vectorises)            e.g. [1,1,1]; [1,0,1];     [1,0,0];     [0,0,0]
            $     - last two links as a monad
          J       - range(length) [1,2,3]
           ×      - multiply                             e.g. [1,2,3]; [1,0,3];     [1,0,0];     [0,0,0]
             S    - sum                                  e.g. 6;       4;           1;           0
              ‘   - increment                            e.g. 7;       5;           2;           1
               µ  - monadic chain separation
                Ŀ - call link(index) as a monad with the oeisIndexNumber
                        link indexing is 1-based and modular so 7 calls link 1
              ><        hence the empty link 6 replacing a %6 here

8

Mathematica,39 173 189个序列

If[l=0~Range~19;#<4^7,l,If[#<3^9,#&@@RealDigits[Log[j=16627;#-j+If[#<j,49.5,4]],10,20],#-22956-l]]&

受到乔纳森·艾伦回答的启发

效劳于:

  • 147728374830,和8554(这些第一20项是 {0, 1, 2, ... , 19}
  • 1657816626(log(3/2)的十进制扩展,log(5/2)的十进制扩展,... log(99/2)的十进制扩展)
  • 1662716723(log(4)的十进制扩展,log(5)的十进制扩展,... log(100)的十进制扩展)
  • 2295822996(2-n,3-n,... 40-n)

6

CJam,1831个序列

{168680-:Zz1320b900b48md:R;H+:QB+2*,:!1_tQWtQ)WtK{[WQW*_(]+1$f=[1R2+R~R4+*2/WR-X$-].*1b+}/J~>ZW>f*}

这样可以正确地输出199个开始的0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0序列以及包含范围在内的所有序列,[A168680, A169579]并且[A170000, A170731]。它主要处理这两个范围,并在第一个范围开始之前回退全零。

有问题的两个范围具有以下形式

减少的长度字数 ñ 在Coxeter小组中 P 发电机 小号一世 与关系 小号一世2=小号一世小号Ĵ=一世

对于的值 P350 和值 1750。它们的生成函数完全没有效率地给出:我发现将分子和分母乘以Ť-1个 给gf

Ť+1个+Ť-Ť-1个1个2P-2P-1个Ť+1个-1个2P-2P+1个Ť+P-1个Ť-1个
尽管出于打高尔夫球的目的,我实际上正在与 [R=P+3

1

批处理,62个序列

@for /l %%i in (1,1,20)do @set/a"n=(n=22956-%1)*(n>>=16)+%%i*(n|%1-8582)"&call echo %%n%%

仅实现一个序列块很困难,但是我以89个字节管理了两个!说明:对于%18585-8607 的参数,22956-%1>>16返回零,导致(22956-%1)表达式被忽略,我们最终将循环变量分别乘以3-25,而对于22958-22996的参数,它返回负一,导致表达式为否定,则将n|乘数替换为减一,从而有效地减去循环变量。


1
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.