Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Some functions for triangular numbers in Mathematica, sorted by byte count
- 15: ((2#+1)^2-1)/8&
- 17: Tr[Range@#^3]^.5&
- 17: ⌊(2#+1)^2/8⌋&
- 18: ((#+1)^3-#^3-1)/6&
- 19: Sqrt@Tr[Range@#^3]&
- 19: -StirlingS1[#+1,#]&
- 19: Sum[1,{i,#},{j,i}]&
- 20: f@0=0;f@i_:=i+f[i-1]
- 20: Tr[{#+1,-#,-1}^3/6]&
- 22: ⌊(#+1)^3/(#+2)⌋/2&
- 23: Tr@Table[i^3,{i,#}]^.5&
- 26: Sqrt@Sum[i*j,{i,#},{j,#}]&
- 27: Sum[i^2(-1)^i,{i,#}](-1)^#&
- 28: D[x/(1-x)^3,{x,#}]/#!/.x->0&
- 28: (For[i=n=0,i<#,n+=i,i++];n)&
- 29: n=0;(Do[n+=i,{i,#}];Print@n)&
- 29: EdgeCount@CompleteGraph[#+1]&
- 29: Length@Expand[(x+y+z)^(#-1)]& (note: doesn't work for 1)
- 29: Coefficient[(1+x)^(#+1),x^2]&
- 29: ⌊(#+1)/(Exp[2/(#+1)]-1)⌋&
- 30: Nest[#+(1+Sqrt[1+8#])/2&,0,#]&
- 31: Sum[EulerPhi@k⌊#/k⌋,{k,#}]&
- 33: Series[x/(1-x)^3,{x,0,#}][[3,#]]&
- 34: Boole[#2>=#]&~Array~{#,#}~Total~2& (thanks to Mark S., https://codegolf.stackexchange.com/questions/133109/sum-of-all-integers-from-1-to-n/133160#comment339998_133160)
- 37: SeriesCoefficient[x/(1-x)^3,{x,0,#}]&
- 37: Det@Array[Binomial[1+##,#]&,{#,#}-1]& (note: doesn't work for 1)
- 39: Length@Solve[0<a<=b<=#,{a,b},Integers]&
- 40: UpperTriangularize@Table[1,#,#]~Total~2&
- 42: Last@LinearRecurrence[{3,-3,1},{1,3,6},#]&
- 42: CellularAutomaton[50,{{1},0},#-1]~Total~2&
- 45: 1/Integrate[4Sin@x^(2#-1)Cos@x^3,{x,0,Pi/2}]&
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement