9
\$\begingroup\$

This is the nepal flag.

Above is the picture of the flag of the country Nepal. Pretty cool.

What's cooler, is the aspect ratio, which is defined under the constitution as:

Aspect ratio.

That formula in copyable form:

$$ 1 : \frac{6136891429688-306253616715\sqrt{2}-\sqrt{118-48\sqrt{2}}(934861968+20332617192\sqrt{2})}{4506606337686} $$

Your task is to output at least the first 113 digits of the decimal expansion, in any format of your choosing. These digits are:

1.2190103378294521845700248699309885665950123333195645737170955981267389324534409006970256858120588676151695966441

These digits form can be found in sequence A230582.

This constant is algebraic, specifically quartic. In particular it is the least root of 243356742235044x⁴ - 1325568548812608x³ + 2700899847521244x² - 2439951444086880x + 824634725389225.

This is code-golf, so shortest answer wins.

Related: Let's draw the flag of Nepal

\$\endgroup\$
5
  • 6
    \$\begingroup\$ -1 For most languages (I think), the best solution is to print the number rather than calculating it, since the formula itself takes a lot of characters and few languages support 113-digit floating point numbers. Even for languages that are able to calculate 113 or more digits, I believe the formula can still be trivially implemented. \$\endgroup\$
    – Peter
    Commented Aug 5, 2023 at 20:14
  • 2
    \$\begingroup\$ I think the key may be that the formula isn't arbitrary, and there is a method of construction described here that leads to those values. \$\endgroup\$
    – xnor
    Commented Aug 5, 2023 at 20:16
  • \$\begingroup\$ gzip shortens it to 90 bytes, but I'm having a hard time getting my terminal to actually accept it, since the gzip output contains null bytes and unpaired CRs. \$\endgroup\$
    – Bbrk24
    Commented Aug 5, 2023 at 20:27
  • 6
    \$\begingroup\$ Here's a formula from the thumbnail of this video. \$\endgroup\$
    – xnor
    Commented Aug 5, 2023 at 20:28
  • 1
    \$\begingroup\$ I was the one who created the OEIS entry A235082. It was my first contribution there. \$\endgroup\$ Commented Aug 8, 2023 at 6:00

16 Answers 16

11
\$\begingroup\$

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))

Try it online!

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))

Try it online!

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))

Try it online!

\$\endgroup\$
10
  • \$\begingroup\$ 118-48*r can be 16*c-10, for instance. \$\endgroup\$
    – Neil
    Commented Aug 5, 2023 at 21:17
  • \$\begingroup\$ @Neil It can even be c*c+36 \$\endgroup\$
    – xnor
    Commented Aug 5, 2023 at 21:18
  • \$\begingroup\$ If you write 3*(33-20*r) as (20*c-61) then you can inline r into c. \$\endgroup\$
    – Neil
    Commented Aug 5, 2023 at 21:28
  • \$\begingroup\$ With both (20*c-61) and c*c+36 it also comes out at 104 bytes: Try it online! \$\endgroup\$
    – Neil
    Commented Aug 5, 2023 at 21:40
  • \$\begingroup\$ Although you can still save 2 more bytes by using (20*c-61) yourself. \$\endgroup\$
    – Neil
    Commented Aug 5, 2023 at 21:45
8
\$\begingroup\$

Vyxal, 48 bytes

»ʀ⌈S«A0ẇ⟨Ė^Ṗ*«)Πṙvp≈›≥›BĖ≥ẇ₈ḋẇβẋV¼»16↵τyNY∆Ph⁺°Ḟ

Try it Online!

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
\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

Wolfram Language (Mathematica), 69 62 57 bytes

Saved so many bytes thanks to the comment of @Greg Martin and the comment of @att

Try it online!

r=√2;4/3-1`99/(r+(7r-3-√(59-24r))(23/9-r)16/(33-20r))
\$\endgroup\$
3
  • \$\begingroup\$ You can save a few bytes by removing the * symbols and changing where the 9s are: r=√2;(4-3/(r+(7r-3-√(59-24r))(23/9-r)16/(33-20r)))/3 \$\endgroup\$ Commented Aug 6, 2023 at 7:25
  • 1
    \$\begingroup\$ @GregMartin It does look weird having the 16 between the ) and / instead of between the + and ( though... \$\endgroup\$
    – Neil
    Commented Aug 6, 2023 at 8:48
  • \$\begingroup\$ 57: r=√2;4/3-1`99/(r+(7r-3-√(59-24r))(23/9-r)16/(33-20r)) \$\endgroup\$
    – att
    Commented Oct 22, 2023 at 9:08
3
\$\begingroup\$

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='')

Try it online!

\$\endgroup\$
0
2
\$\begingroup\$

Ruby, 86 bytes

"%,}#:g6F.mR}}1o|7{n[TK%::,QFb`_xTj3br9F;As}^_2]S%}Soe()xyYB".bytes{|i|$><<(i-25)%100}

Try it online!

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.

\$\endgroup\$
2
\$\begingroup\$

Nibbles, 50 bytes (100 nibbles)

"1."$ ~3a4898772b89091168fc7c6102ed1580a718bf8643e9be1c097cfadb7db934a09ad75c14a79b0262ce77978b500e9

Attempt This Online!

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.

\$\endgroup\$
2
\$\begingroup\$

Jelly, 82 79 bytes

“£pÆȤḋð“)i.Iʂ'“ẈỴɼṇṣṢ“¡mƓ<ȷŀỌ“ẏ0P|Ẓ+’NÐe“ßƇlOƘẸḄ/ƒ79ẊkBṀṖ.ṁnʋıGȧ⁷:Pẉịȷ^»ŒV¤ṛÆr‘

Try it online!

-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).

\$\endgroup\$
1
\$\begingroup\$

Python 3, 109 bytes

print(f"1.{0x3a4898772b89091168fc7c6102ed1580a718bf8643e9be1c097cfadb7db934a09ad75c14a79b0262ce77978b500e9}")

Try it online!

Stores the decimal part in hex (thanks @xnor).

\$\endgroup\$
1
\$\begingroup\$

Thunno 2 j, 52 bytes

»¥\!ĖẸæṭṙ|«ɦ⁾‘cạḍ¬ṣ“},ịḤ)ṣ3_ßịạ⁷ƇR×XẏṢḋyi¡ẹ¿pĿ⁴8»`1.

Try it online!

Just a compressed number with 1. prepended.

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 53 bytes

•4₅XïMáô|û¡Žü%ÔÖ7àþ}iÙ°fàp!LÙÔ‡ĀΣH₁ù¸ê_+0×B<È„u•„1.ì

Try it online.

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.

\$\endgroup\$
1
\$\begingroup\$

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.

I="Try it online!";O=C;

\$\endgroup\$
1
\$\begingroup\$

Jelly, 53 bytes

“µŻ5(_PṛØY⁺Ɲ>Ŀḣ¦ḲḶaİçẸẒḋƙ⁷\ø%Sfø*ḤÑ[F]€ȮĠṆ5]Ẇ⁶rȦ’⁾1.;

Try it online!

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

Try it online!

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

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ I have no idea how to use sympy, but is there any chance using the quartic coefficients on the OEIS page could come out shorter with those being base compressed? \$\endgroup\$ Commented Oct 22, 2023 at 9:18
  • 1
    \$\begingroup\$ @UnrelatedString I’ve added an implementation of that (based on Jelly’s Ær code). I’ve base-250 encoded the coefficients, but there’s quite a lot of Python code required so it’s still quite long. Unfortunately, Ær itself converts to a standard Python float so can’t be used here for arbitrary precision calculations. \$\endgroup\$ Commented Oct 22, 2023 at 19:05
0
\$\begingroup\$

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.

Try it Online!

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.

\$\endgroup\$
0
\$\begingroup\$

JavaScript (Node.js), 104 bytes

a=>'1.'+0x3a4898772b89091168fc7c6102ed1580a718bf8643e9be1c097cfadb7db934a09ad75c14a79b0262ce77978b500e9n

Try it online!

Quite but not completely trivial

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.