| Bytes | Lang | Time | Link |
|---|---|---|---|
| 079 | Jelly | 240920T015019Z | Unrelate |
| 100 | Python 3 | 230805T211307Z | xnor |
| 053 | Jelly | 231022T082422Z | Nick Ken |
| nan | Wolfram Language Mathematica | 230806T005138Z | 138 Aspe |
| 104 | JavaScript Node.js | 230809T094524Z | l4m2 |
| 133 | CellTail | 230809T090817Z | The Empt |
| 053 | 05AB1E | 230808T082121Z | Kevin Cr |
| 078 | dc | 230806T114900Z | Toby Spe |
| 048 | Vyxal | 230806T110246Z | emanresu |
| nan | Nibbles | 230806T092519Z | Dominic |
| 052 | Vyxal Ṫ | 230806T083648Z | The Empt |
| 052 | Charcoal | 230805T201323Z | Neil |
| 086 | Ruby | 230805T211154Z | Level Ri |
| 080 | Python 3 | 230805T225534Z | dingledo |
| 052 | Thunno 2 j | 230805T203226Z | The Thon |
| 109 | Python 3 | 230805T203117Z | The Thon |
Jelly, 82 79 bytes
“£pÆȤḋð“)i.Iʂ'“ẈỴɼṇṣṢ“¡mƓ<ȷŀỌ“ẏ0P|Ẓ+’NÐe“ßƇlOƘẸḄ/ƒ79ẊkBṀṖ.ṁnʋıGȧ⁷:Pẉịȷ^»ŒV¤ṛÆr‘
-3 with a slightly better Python snippet
Not exactly competitive, but this M solution porting one of xnor's formulas would be if I could figure out how to make it actually output the digits... M doesn't have ŒV or any other way to access sympy.evalf, and trying to get at it obliquely runs out of precision, so I've tried a few ways to manually compute each digit but it's not promising.
So instead, here's SymPy math inside normal Jelly.
The polynomial roots builtin is implemented as:
'Ær': attrdict(
arity = 1,
ldepth = 1,
call = lambda z: jellify(from_base(z[::-1], sympy.poly('x')).all_roots())
),
which already uses SymPy, just to convert it back to native Python types at the end. This can be fixed. “ßƇlOƘẸḄ/ƒ79ẊkBṀṖ.ṁnʋıGȧ⁷:Pẉịȷ^» decompresses to global jellify; jellify= lambda A:A[0].evalf(113), which ŒV then execs (after failing to eval it), replacing the jellify function for the entire interpreter with one which evaluates a symbolic expression to a SymPy float with the desired number of digits (after taking it from the first element of a list--evalf does not automatically vectorize). The resulting SymPy float successfully infiltrates Jelly's internals, and results in another one when incremented--translating the quartic 1 to the left then adding 1 to its least root saves 2 bytes over storing the verbatim quartic coefficients given in the challenge/on OEIS.
The extraneous spaces in global jellify; jellify= lambda A:A[0].evalf(113) actually make it compress better; this saves no bytes, but it did save 1 byte with the old version which used global jellify; jellify= lambda A:sympy.N(A[0],113).
Python 3, 100 bytes
from sympy import*
r=sqrt(2)
print(N((4-3/((7*r-3-sqrt(59-24*r))*(23-9*r)*16/9/(33-20*r)+r))/3,113))
This is longer than compressed hardcoding and definitely golfable, but I want to share a formula I simplified from one in this thumbnail of this video:
$$\begin{aligned} v &= \frac{16 \cdot (7\sqrt{2}-3-\sqrt{59-24\sqrt{2}}) \cdot (23-9\sqrt{2})}{9 \cdot (33-20\sqrt{2})} \\ \text{ratio} &= \frac{4}{3}-\frac{1}{v+\sqrt{2}} \end{aligned} $$
92 bytes
from sympy import*
r=5-sqrt(8)
print(N((4-6/((29-7*r-sqrt(48*r-4))*(8/r/9+8)/r+5-r))/3,113))
95 bytes (@dingledooper)
from sympy import*
r=sqrt(2)
print(N((4-3/((7*r-3-sqrt(59-24*r))*(6384+2608*r)/2601+r))/3,113))
Jelly, 53 bytes
“µŻ5(_PṛØY⁺Ɲ>Ŀḣ¦ḲḶaİçẸẒḋƙ⁷\ø%Sfø*ḤÑ[F]€ȮĠṆ5]Ẇ⁶rȦ’⁾1.;
Straightforward hardcoding of the digits after the decimal point as a base-250 integer, then prepend "1."
Any calculation would have to be done using integers and fixed point arithmetic which is almost certainly longer than this.
Alternatively, Python and sympy can be used within Jelly. Here’s one version using @xnor’s Python code:
Jelly, 99 bytes
“YSZprint(ZN((4-3/((7*Y-3-S59-24*Y))*(23-9*Y)*16/9/(33-20*Y)+Y))/3,113))“S2)“Zsqrt(“sympy.”ṣḢ$j¥/ŒV
And here’s an approach that uses sympy to solve the aquatic equation in the OEIS, as suggested by @UnrelatedString:
Jelly, 113 bytes
“ẏ0P|Ẓ+“¥j^⁸øżk“½ÇṂY;Sṙ“®ẋ~⁽h`¹“£]iyi7ṭ’NÐeŒṘ“print(sympy.N(from_base(“,sympy.poly('x')).all_roots()[0],113))”jŒV
Wolfram Language (Mathematica), 69 62 57 bytes
Saved so many bytes thanks to the comment of @Greg Martin and the comment of @att
r=√2;4/3-1`99/(r+(7r-3-√(59-24r))(23/9-r)16/(33-20r))
JavaScript (Node.js), 104 bytes
a=>'1.'+0x3a4898772b89091168fc7c6102ed1580a718bf8643e9be1c097cfadb7db934a09ad75c14a79b0262ce77978b500e9n
Quite but not completely trivial
CellTail, 133 Bytes
I=1,219010337,829452184,570024869,930988566,595012333,319564573,717095598,126738932,453440900,697025685,812058867,615169596,6441;O=N;
Outputs as a list of numbers, starting with the integer component.
05AB1E, 53 bytes
•4₅XïMáô|û¡Žü%ÔÖ7àþ}iÙ°fàp!LÙÔ‡ĀΣH₁ù¸ê_+0×B<È„u•„1.ì
Explanation:
Straight-forward hard-coded approach. 05AB1E also only has 16 bits floating point precision anyway.
•4₅XïMáô|û¡Žü%ÔÖ7àþ}iÙ°fàp!LÙÔ‡ĀΣH₁ù¸ê_+0×B<È„u•
# Push compressed integer 2190103378294521845700248699309885665950123333195645737170955981267389324534409006970256858120588676151695966441
„1.ì # Prepend "1." in front of it
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand how the compression works.
dc, 78 bytes
16iFFk594DB3BD338 2v474E23564B*-2v4BBEB1DE8*37B8DC90+76 2v30*-v*-41946AB7E96/p
It's a straight calculation, but with the constants specified in hexadecimal for brevity
Explanation:
16i # input in base 16
FFx # 255-digit precision
594DB3BD338 2v474E23564B*- # 6136891429688 - 306253616715√2
2v4BBEB1DE8*37B8DC90+ # 934861968 + 20332617192√2
76 2v30*-v # √(118 - 48√2)
*- # complete the numerator
41946AB7E96/p # divide by 4506606337686 and print
Output:
1.2190103378294521845700248699309885665950123333195645737170955981267\
389324534409006970256858120588676151695966441384905283150985491649927\
585413642430469766180971720219688119745626955249584071432721758804516\
12949021847336692342653120129739301327854858381983
Vyxal, 48 bytes
»ʀ⌈S«A0ẇ⟨Ė^Ṗ*«)Πṙvp≈›≥›BĖ≥ẇ₈ḋẇβẋV¼»16↵τyNY∆Ph⁺°Ḟ
Solves the stated polynomial.
»...» # Giant number
τ # Decompress from base
16↵ # 10^16
yNY # Negate every other term to get coefficients
∆P # Solve polynomial
h # First root
⁺°Ḟ # Format to 113 decimal places
Nibbles, 50 bytes (100 nibbles)
"1."$ ~3a4898772b89091168fc7c6102ed1580a718bf8643e9be1c097cfadb7db934a09ad75c14a79b0262ce77978b500e9
Same approach as Neil's first Charcoal answer.
Nibbles can only handle integers, so outputting the initial 1. and the decimal digits separately is essential.
Vyxal Ṫ, 52 bytes
‛1.»⟑]"Ȯ⁋æ≥ǔ}¼√ḋ¾d¯₴÷≤„~-↳§*≤4_⌐↳¯→ḟS∆Y↵Ḃ¥zjλ…°qẆ∷9»
String sum magic! La la la!
Ties with Thunno 2 and Charcoal. This seems optimal.
Explanation
‛1.»⟑]"Ȯ⁋æ≥ǔ}¼√ḋ¾d¯₴÷≤„~-↳§*≤4_⌐↳¯→ḟS∆Y↵Ḃ¥zjλ…°qẆ∷9»
‛1. # The two character string "1.".
»⟑]"Ȯ⁋æ≥ǔ}¼√ḋ¾d¯₴÷≤„~-↳§*≤4_⌐↳¯→ḟS∆Y↵Ḃ¥zjλ…°qẆ∷9» # The compressed number 2190103378294521845700248699309885665950123333195645737170955981267389324534409006970256858120588676151695966441.
# Due to some niece witchcraft, the Ṫ flag sums the string and the number to get the constant and then implicitly prints the result. String sum magic! La la la!
💎
Created with the help of Luminespire.
Charcoal, 52 bytes
1.”)¶⌊G U9ι[abN↧Q∧≡⁻w⁼Ka5↧χ±ν∕§G\`U⊙Gφ2S4↖gλo0θ|Sψ◨N➙
Try it online! Link is to verbose version of code, for what it's worth. Explanation: Prints 1. separately, because that improves the string compression of the remaining 112 digits.
120 bytes to actually calculate the 113 digits:
≔Xχ¹¹²θ≔▷math.isqrt⊗×θθη1.✂I÷⁻⁻×I”)¶↷ωrNL@”θ×I”)⧴↧≔Mmχ”η÷×▷math.isqrt⁻×¹¹⁸×θθ×⁴⁸×θη⁺×I”)¶u⁰»~”θ×I”)¶↗v⌊Hq”ηθI”)″“▷←ι2⊖”¹
Attempt This Online! Link is to verbose version of code. Explanation:
≔Xχ¹¹²θ
Effectively set the calculation precision to 112 digits after the decimal point by multiplying everything by 10¹¹².
≔▷math.isqrt⊗×θθη
Calculate the square root of 2 to that precision.
1.
Output the 1. separately as it's easier.
✂I÷⁻⁻×I”...”θ×I”...”η÷×▷math.isqrt⁻×¹¹⁸×θθ×⁴⁸×θη⁺×I”...”θ×I”...”ηθI”...”¹
Calculate and output the 112 digits after the decimal point, using compressed strings for the large numbers.
105 96 81 80 72 71 bytes by importing sympy and using a golfed version of @xnor's original sympy answer:
≔⁻⁸▷sympy.sqrt¹⁸θ≔∕×⁻ײ⁰θ⁶¹⁺⁺⁶θX⁻×¹⁶θχ·⁵⁻×⁹⁶θ³²η▷sympy.N⟦∕∕⁺⁸η⁶⁺¹∕ηθ¹¹³
Try it online! Link is to verbose version of code. Explanation:
≔⁻⁸▷sympy.sqrt¹⁸θ
Save \$ 8 - \sqrt { 18 } \$ in a variable.
≔∕×⁻ײ⁰θ⁶¹⁺⁺⁶θX⁻×¹⁶θχ·⁵⁻×⁹⁶θ³²η
Save \$ \frac { 3 ( 33 - 20 \sqrt 2 ) ( 14 - 3 \sqrt 2 + \sqrt { 118 - 48 \sqrt 2 } ) } { 32 ( 23 - 9 \sqrt 2 ) } \$ in a variable. \$ 3 ( 33 - 20 \sqrt 2 ) = 20 ( 8 - \sqrt { 18 } ) - 61 \$, \$ 14 - 3 \sqrt 2 = 6 + 8 - \sqrt { 18 } \$, \$ 118 - 48 \sqrt 2 = 16 ( 8 - \sqrt { 18 } ) - 10 \$ and \$ 32 ( 23 - 9 \sqrt 2 ) = 96 ( 8 - \sqrt { 18 } ) - 32 \$. Also, I can use Power(, 0.5) instead of sympy.sqrt on an expression based on \$ \sqrt 2 \$.
▷sympy.N⟦∕∕⁺⁸η⁶⁺¹∕ηθ¹¹³
Calculate the desired result.
Ruby, 86 bytes
"%,}#:g6F.mR}}1o|7{n[TK%::,QFb`_xTj3br9F;As}^_2]S%}Soe()xyYB".bytes{|i|$><<(i-25)%100}
Prints the digits of the decimal expansion, in any format. I interpret that to mean the decimal point is not required. It would cost a few bytes to add it in.
This simply decodes the ASCII codes of each character in the magic string to a number between 35-25=10 and 125-25=100, takes a modulo to convert the 100 into 0 where necessary, and prints the output, concatenated.
Python 3, 80 bytes
Obligatory compressed hardcoding method. See @xnor's answer for an actual mathematical computation.
print(1.2,*b'Zg%R^4-F\0VcbUB;2{!_@9%F_;QIY -"(Z\0EFD:x:VL_`@)',sep='')
Thunno 2 j, 52 bytes
»¥\!ĖẸæṭṙ|«ɦ⁾‘cạḍ¬ṣ“},ịḤ)ṣ3_ßịạ⁷ƇR×XẏṢḋyi¡ẹ¿pĿ⁴8»`1.
Just a compressed number with 1. prepended.
Python 3, 109 bytes
print(f"1.{0x3a4898772b89091168fc7c6102ed1580a718bf8643e9be1c097cfadb7db934a09ad75c14a79b0262ce77978b500e9}")
Stores the decimal part in hex (thanks @xnor).