24
\$\begingroup\$

Input

Integers a1, a2, a3, b1, b2, b3 each in the range 1 to 20.

Output

True if a1^(a2^a3) > b1^(b2^b3) and False otherwise.

^ is exponentiation in this question.

Rules

This is code-golf. Your code must terminate correctly within 10 seconds for any valid input on a standard desktop PC.

You can output anything Truthy for True and anything Falsey for False.

You can assume any input order you like as long as its specified in the answer and always the same.

For this question your code should always be correct. That is it should not fail because of floating point inaccuracies. Due to the limited range of the input this should not be too hard to achieve.

Test cases

3^(4^5) > 5^(4^3)
1^(2^3) < 3^(2^1)
3^(6^5) < 5^(20^3)
20^(20^20) > 20^(20^19)
20^(20^20) == 20^(20^20)
2^2^20 > 2^20^2
2^3^12 == 8^3^11
1^20^20 == 1^1^1
1^1^1 == 1^20^20
\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – DJMcMayhem
    Commented May 1, 2019 at 14:28

17 Answers 17

16
\$\begingroup\$

Perl 6, 31 29 bytes

-2 bytes thanks to Grimy

*.log10* * ***>*.log10* * ***

Try it online!

Believe it or not, this is not an esolang, even if it is composed of mostly asterisks. This uses Arnauld's formula, with log10 instead of ln.

\$\endgroup\$
4
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ Commented Apr 26, 2019 at 2:09
  • \$\begingroup\$ @ØrjanJohansen This should be fixed now. let me know if it fails for anything else \$\endgroup\$
    – Jo King
    Commented Apr 26, 2019 at 2:34
  • \$\begingroup\$ -2 by removing the unneeded spaces \$\endgroup\$
    – Grimmy
    Commented Apr 26, 2019 at 16:20
  • \$\begingroup\$ @Grimy Thanks! I could have sworn I tried that... \$\endgroup\$
    – Jo King
    Commented Apr 26, 2019 at 16:26
8
\$\begingroup\$

R, 39 bytes

function(x,y,z)rank(log2(x)*(y^z))[1]<2

Try it online!

Returns FALSE when a > b and TRUE if b < a

\$\endgroup\$
4
  • 4
    \$\begingroup\$ This is wrong for f(2,2,20,2,20,2) \$\endgroup\$
    – H.PWiz
    Commented Apr 25, 2019 at 10:24
  • \$\begingroup\$ Fixed, using your suggestion to @Arnauld answer ;) \$\endgroup\$
    – digEmAll
    Commented Apr 25, 2019 at 10:51
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ Commented Apr 26, 2019 at 2:11
  • 1
    \$\begingroup\$ Fails for both 1^20^20 == 1^1^1 and 1^1^1 == 1^20^20. \$\endgroup\$ Commented Apr 26, 2019 at 8:05
6
\$\begingroup\$

05AB1E, 11 9 11 7 bytes

.²Šm*`›

Port of @Arnauld's JavaScript and @digEmAll's R approaches (I saw them post around the same time)
-2 bytes thanks to @Emigna
+2 bytes as bug-fix after @Arnauld's and @digEmAll's answers contained an error
-4 bytes now that a different input order is allowed after @LuisMendo's comments

Input as [a1,b1], [a3,b3], [a2,b2] as three separated inputs.

Try it online or verify all test cases.

Explanation:

.²       # Take the logarithm with base 2 of the implicit [a1,b1]-input
  Š      # Triple-swap a,b,c to c,a,b with the implicit inputs
         #  The stack order is now: [log2(a1),log2(b1)], [a2,b2], [a3,b3]
   m     # Take the power, resulting in [a2**a3,b2**b3]
    *    # Multiply it with the log2-list, resulting in [log2(a1)*a2**a3,log2(b1)*b2**b3]
     `   # Push both values separated to the stack
      ›  # And check if log2(a1)*a2**a3 is larger than log2(b1)*b2**b3
         # (after which the result is output implicitly)
\$\endgroup\$
4
  • 1
    \$\begingroup\$ You second version can be εć.²š]P`› \$\endgroup\$
    – Emigna
    Commented Apr 25, 2019 at 10:02
  • \$\begingroup\$ @Emigna Ah nice, I was looking at an approach with ć, but completely forgot about using š (not sure why now that I see it, haha). Thanks! \$\endgroup\$ Commented Apr 25, 2019 at 10:04
  • \$\begingroup\$ This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix). \$\endgroup\$
    – user9207
    Commented Apr 25, 2019 at 10:32
  • \$\begingroup\$ @Anush Fixed and 4 bytes saved by taking the inputs in a different order now. :) \$\endgroup\$ Commented Apr 25, 2019 at 11:18
5
\$\begingroup\$

Java (JDK), 56 bytes

(a,b,c,d,e,f)->a>Math.pow(d,Math.pow(e,f)/Math.pow(b,c))

Try it online!

Credits

\$\endgroup\$
2
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ Commented Apr 26, 2019 at 2:08
  • \$\begingroup\$ @ØrjanJohansen Fixed \$\endgroup\$ Commented Apr 26, 2019 at 6:48
4
\$\begingroup\$

Wolfram Language (Mathematica), 23 bytes

#2^#3Log@#>#5^#6Log@#4&

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ This doesn't terminate for a1=20, a2=20, a3=20. \$\endgroup\$
    – user9207
    Commented Apr 25, 2019 at 9:42
  • \$\begingroup\$ @Anush fixed... \$\endgroup\$
    – ZaMoC
    Commented Apr 25, 2019 at 10:11
  • 1
    \$\begingroup\$ Too bad about overflow, otherwise ##>0&@@(##^1&@@@#)& is only 19 bytes and even more mind-bogglingly un-Mathematica-like than the code above. (infput format {{a,b,c},{d,e,f}}) \$\endgroup\$ Commented Apr 26, 2019 at 8:37
3
\$\begingroup\$

J, 11 9 bytes

>&(^.@^/)

Try it online!

Arguments given as lists.

  • > is the left one bigger?
  • &(...) but first, transform each argument thusly:
  • ^.@^/ reduce it from the right to the left with exponention. But because ordinary exponentiation will limit error even for extended numbers, we take the logs of both sides
\$\endgroup\$
3
\$\begingroup\$

Clean, 44 bytes

import StdEnv
$a b c d e f=b^c/e^f>ln d/ln a

Try it online!

Uses an adaptation of Arnauld's formula.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ Commented Apr 26, 2019 at 2:01
  • \$\begingroup\$ @ØrjanJohansen Fixed. \$\endgroup\$
    – Οurous
    Commented Apr 26, 2019 at 2:25
3
\$\begingroup\$

Python 3, 68 bytes

lambda a,b,c,d,e,f:log(a,2)*(b**c)>log(d,2)*(e**f)
from math import*

Try it online!

Port of @Arnualds answer, but with the base for log changed.

\$\endgroup\$
7
  • \$\begingroup\$ ^ is called ** in Python. And with that changed, you won't be able to run all the OP's test cases. \$\endgroup\$ Commented Apr 26, 2019 at 1:03
  • \$\begingroup\$ Should be all fixed now, 66 bytes though. \$\endgroup\$
    – Miriam
    Commented Apr 26, 2019 at 1:37
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ Commented Apr 26, 2019 at 2:01
  • \$\begingroup\$ @ØrjanJohansen should be fixed \$\endgroup\$
    – Miriam
    Commented Apr 26, 2019 at 2:16
  • \$\begingroup\$ Seems like it. Apart from the logarithmic base change for the fix, this looks like Arnauld's method. \$\endgroup\$ Commented Apr 26, 2019 at 2:30
3
\$\begingroup\$

Vyxal, 11 bytes

2(?9•??e*)>

I'm beginning to understand Vyxal.

Try it Online!

\$\endgroup\$
4
  • \$\begingroup\$ 11 bytes \$\endgroup\$
    – lyxal
    Commented May 8, 2021 at 12:25
  • \$\begingroup\$ @lyxal Why did I not think of that. \$\endgroup\$
    – emanresu A
    Commented May 8, 2021 at 12:26
  • \$\begingroup\$ 9 bytes \$\endgroup\$ Commented Jul 12, 2021 at 19:32
  • \$\begingroup\$ @AaronMiller That doesn't work because time complexity. \$\endgroup\$
    – emanresu A
    Commented Jul 12, 2021 at 21:30
2
\$\begingroup\$

05AB1E, 13 bytes

Uses the method from Arnauld's JS answer

2F.²IIm*ˆ}¯`›

Try it online!

\$\endgroup\$
10
  • \$\begingroup\$ This doesn't terminate for a1=20, a2=20, a3=20. \$\endgroup\$
    – user9207
    Commented Apr 25, 2019 at 9:43
  • 1
    \$\begingroup\$ @Anush: Seems to terminate in less than a second to me. \$\endgroup\$
    – Emigna
    Commented Apr 25, 2019 at 9:45
  • \$\begingroup\$ you have to set all the variables to 20. See tio.run/##yy9OTMpM/f9f79Du3GK9Q6tzHzXs@v8/2shAB4xiuRBMAA \$\endgroup\$
    – user9207
    Commented Apr 25, 2019 at 9:46
  • \$\begingroup\$ @Anush: Ah, you meant b1=b2=b3=20 ,yeah that doesn't terminate. \$\endgroup\$
    – Emigna
    Commented Apr 25, 2019 at 9:46
  • 1
    \$\begingroup\$ @Anush: It is fixed now. Thanks for pointing out my mistake :) \$\endgroup\$
    – Emigna
    Commented Apr 25, 2019 at 9:59
2
\$\begingroup\$

Excel, 28 bytes

=B1^C1*LOG(A1)>E1^F1*LOG(D1)

Excel implementation of the same formula already used.

\$\endgroup\$
1
  • \$\begingroup\$ My understanding is that Excel has 15 digits of precision, so there may be cases where rounding result in this returning the wrong answer. \$\endgroup\$ Commented Apr 25, 2019 at 20:26
2
\$\begingroup\$

JavaScript, 51 bytes

f=(a,b,c,h,i,j)=>(l=Math.log)(a)*b**c-l(h)*i**j>1e-8

Surprisingly, the test cases doesn't show any floating-point error. I don't know if it ever does at this size.

This just compares the logarithm of the numbers.

Equality tolerance is equal to 1e-8.

\$\endgroup\$
5
  • \$\begingroup\$ Welcome to PPCG! Alas this does fail with my 2^3^12 == 8^3^11 test case. In fact your answer is very similar to the original answer by Arnauld (sadly deleted rather than fixed) that inspired most of those which failed it. \$\endgroup\$ Commented Apr 29, 2019 at 0:24
  • \$\begingroup\$ @Ørjan Johansen Moved l(h) to the right, and maybe it works now? Edit: Wait, it doesn't. \$\endgroup\$
    – Naruyoko
    Commented Apr 29, 2019 at 0:58
  • \$\begingroup\$ Added equality tolerance 0.01. \$\endgroup\$
    – Naruyoko
    Commented Apr 29, 2019 at 1:12
  • \$\begingroup\$ I did a quick search and a tolerance should work, but this is a bit too high. The highest you need to exclude is (5.820766091346741e-11,(8.0,3.0,11,2.0,3.0,12)) (my test case), and the lowest you need to include is (9.486076692724055e-4,(17.0,19.0,1,3.0,7.0,2)) (3^7^2 > 17^19^1.) So something like 1e-8 should be safely in the middle and the same byte length. \$\endgroup\$ Commented Apr 29, 2019 at 2:24
  • \$\begingroup\$ @Ørjan Johansen Ok, thanks! \$\endgroup\$
    – Naruyoko
    Commented Apr 29, 2019 at 17:04
1
\$\begingroup\$

bc -l, 47 bytes

l(read())*read()^read()>l(read())*read()^read()

with the input read from STDIN, one integer per line.

bc is pretty fast; it handles a=b=c=d=e=f=1,000,000 in a little over a second on my laptop.

\$\endgroup\$
1
  • \$\begingroup\$ I love a bc answer! Just need one in bash now :) \$\endgroup\$
    – user9207
    Commented Apr 26, 2019 at 5:32
1
\$\begingroup\$

C++ (gcc), 86 bytes

Thanks to @ØrjanJohansen for pointing out a flaw in this and @Ourous for giving a fix.

#import<cmath>
int a(int i[]){return pow(i[1],i[2])/pow(i[4],i[5])>log(i[3])/log(*i);}

Try it online!

Takes input as a 6-integer array. Returns 1 if \$a^{b^c} > d^{e^f}\$, 0 otherwise.

\$\endgroup\$
8
  • \$\begingroup\$ The formula after taking log twice should be i[2]*log(i[1])+log(log(*i)). E.g. the current one will fail for 2^2^20 > 4^2^18. \$\endgroup\$ Commented Apr 26, 2019 at 2:50
  • \$\begingroup\$ @ØrjanJohansen: good catch! I guess I have to use the pow method then. \$\endgroup\$
    – Neil A.
    Commented Apr 26, 2019 at 2:53
  • \$\begingroup\$ The alternate one has the 2^3^12 == 8^3^11 problem I've pointed out for others. \$\endgroup\$ Commented Apr 26, 2019 at 2:54
  • \$\begingroup\$ @ØrjanJohansen: well, I guess I'm using your fixed formula then. \$\endgroup\$
    – Neil A.
    Commented Apr 26, 2019 at 2:58
  • \$\begingroup\$ Oh, I'm afraid that formula is only mathematically correct. It still has a floating point error problem, just with a different case, 2^3^20 == 8^3^19. In fact on average the power method fails for fewer, probably because it tends to multiply by powers of two exactly. Others have managed to make it work by just tweaking it slightly. \$\endgroup\$ Commented Apr 26, 2019 at 3:11
1
\$\begingroup\$

Jelly, 8 bytes

l⁵×*/}>/

Try it online!

Based on Arnauld’s JS answer. Expects as input [a1, b1] as left argument and [[a2, b2], [a3, b3]] as right argument.

Now changed to use log to the base 10 which as far as correctly handles all the possible inputs in the range specified. Thanks to Ørjan Johansen for finding the original problem!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ Commented Apr 26, 2019 at 2:06
  • \$\begingroup\$ Your Python TIO is incorrect.. You have 8* instead of 8**. @ØrjanJohansen is indeed correct that 2**(3**12) > 8**(3**11) is falsey, since they are equal. \$\endgroup\$ Commented Apr 26, 2019 at 7:31
  • \$\begingroup\$ @KevinCruijssen oops. Yes they are indeed equal. The reason the original two are marked as different relates to floating point error. \$\endgroup\$ Commented Apr 26, 2019 at 7:54
1
\$\begingroup\$

TI-BASIC, 27 31 bytes

ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4

Input is a list of length \$6\$ in Ans.
Outputs true if the first big number is greater than the second big number. Outputs false otherwise.

Examples:

{3,4,5,5,4,3
   {3 4 5 5 4 3}
prgmCDGF16
               1
{20,20,20,20,20,19       ;these two lines go off-screen
{20 20 20 20 20 19}
prgmCDGF16
               1
{3,6,5,5,20,3
  {3 6 5 5 20 3}
prgmCDGF16
               0

Explanation:

ln(Ans(1))Ans(2)^Ans(3)>Ans(5)^Ans(6)(ln(Ans(4   ;full program
                                                 ;elements of input denoted as:
                                                 ; {#1 #2 #3 #4 #5 #6}

ln(Ans(1))Ans(2)^Ans(3)                          ;calculate ln(#1)*(#2^#3)
                        Ans(5)^Ans(6)(ln(Ans(4   ;calculate (#5^#6)*ln(#4)
                       >                         ;is the first result greater than the
                                                 ; second result?
                                                 ; leave answer in "Ans"
                                                 ;implicit print of "Ans"

Note: TI-BASIC is a tokenized language. Character count does not equal byte count.

\$\endgroup\$
2
  • \$\begingroup\$ I’m not that familiar with TI-BASIC, but this seems to be log(x) × y × z rather than log(x) × y ^ z. This won’t necessarily lead to the same ordering as the original inequality. \$\endgroup\$ Commented Apr 25, 2019 at 21:36
  • \$\begingroup\$ @NickKennedy Yes, you are correct about that! I'll update the post to account for this. \$\endgroup\$ Commented Apr 25, 2019 at 23:10
1
\$\begingroup\$

APL(NARS), chars 36, bytes 72

{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}

Here below the function z in (a b c )z(x y t) would return 1 if a^(b^c)>x^(y^t) else would return 0; test

  z←{>/{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b}¨⍺⍵}
  3 4 5 z 5 4 3
1
  1 2 3 z 3 2 1
0
  3 6 5 z 5 20 3
0
  20 20 20 z 20 20 19
1
  20 20 20 z 20 20 20
0
  2 2 20 z 2 20 2
1
  2 3 12 z 8 3 11
0
  1 20 20 z 1 1 1
0
  1 1 1 z 1 20 20
0
  1 4 5 z 2 1 1
0

{(a b c)←⍵⋄a=1:¯1⋄(⍟⍟a)+c×⍟b} is the function p(a,b,c)=log(log(a))+c*log(b)=log(log(a^b^c)) and if aa=a^(b^c) with a,b,c >0 and a>1 bb=x^(y^t) with x,y,t >0 and x>1 than

aa>bb <=> log(log(a^b^c))>log(log(x^y^t))  <=>  p(a,b,c)>p(x,y,t)

There is a problem with the function p: When a is 1, log log 1 not exist so I choose to represent that with the number -1; when a=2 so log log a is a negative number but > -1 .

PS. Seen the function in its bigger set in which is defined

p(a,b,c)=log(log(a))+c*log(b)

appear range for a,b,c in 1..20 is too few... If one see when it overflow with log base 10, the range for a,b,c could be 1..10000000 or bigger for a 64 bit float type.

\$\endgroup\$

Your Answer

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