22
\$\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\$
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – DJMcMayhem May 1 at 14:28

16 Answers 16

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\$
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:09
  • \$\begingroup\$ @ØrjanJohansen This should be fixed now. let me know if it fails for anything else \$\endgroup\$ – Jo King Apr 26 at 2:34
  • \$\begingroup\$ -2 by removing the unneeded spaces \$\endgroup\$ – Grimmy Apr 26 at 16:20
  • \$\begingroup\$ @Grimy Thanks! I could have sworn I tried that... \$\endgroup\$ – Jo King Apr 26 at 16:26
7
\$\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
    \$\begingroup\$ This is wrong for f(2,2,20,2,20,2) \$\endgroup\$ – H.PWiz Apr 25 at 10:24
  • \$\begingroup\$ Fixed, using your suggestion to @Arnauld answer ;) \$\endgroup\$ – digEmAll Apr 25 at 10:51
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:11
  • 1
    \$\begingroup\$ Fails for both 1^20^20 == 1^1^1 and 1^1^1 == 1^20^20. \$\endgroup\$ – Olivier Grégoire Apr 26 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\$
  • 1
    \$\begingroup\$ You second version can be εć.²š]P`› \$\endgroup\$ – Emigna Apr 25 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\$ – Kevin Cruijssen Apr 25 at 10:04
  • \$\begingroup\$ This seems to be incorrect (because Arnauld's answer was incorrect until the recent fix). \$\endgroup\$ – Anush Apr 25 at 10:32
  • \$\begingroup\$ @Anush Fixed and 4 bytes saved by taking the inputs in a different order now. :) \$\endgroup\$ – Kevin Cruijssen Apr 25 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\$
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:08
  • \$\begingroup\$ @ØrjanJohansen Fixed \$\endgroup\$ – Olivier Grégoire Apr 26 at 6:48
4
\$\begingroup\$

Wolfram Language (Mathematica), 23 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ This doesn't terminate for a1=20, a2=20, a3=20. \$\endgroup\$ – Anush Apr 25 at 9:42
  • \$\begingroup\$ @Anush fixed... \$\endgroup\$ – J42161217 Apr 25 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\$ – Greg Martin Apr 26 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\$
  • 1
    \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:01
  • \$\begingroup\$ @ØrjanJohansen Fixed. \$\endgroup\$ – Οurous Apr 26 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\$
  • \$\begingroup\$ ^ is called ** in Python. And with that changed, you won't be able to run all the OP's test cases. \$\endgroup\$ – Ørjan Johansen Apr 26 at 1:03
  • \$\begingroup\$ Should be all fixed now, 66 bytes though. \$\endgroup\$ – Artemis Fowl Apr 26 at 1:37
  • \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:01
  • \$\begingroup\$ @ØrjanJohansen should be fixed \$\endgroup\$ – Artemis Fowl Apr 26 at 2:16
  • \$\begingroup\$ Seems like it. Apart from the logarithmic base change for the fix, this looks like Arnauld's method. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:30
2
\$\begingroup\$

05AB1E, 13 bytes

Uses the method from Arnauld's JS answer

2F.²IIm*ˆ}¯`›

Try it online!

\$\endgroup\$
  • \$\begingroup\$ This doesn't terminate for a1=20, a2=20, a3=20. \$\endgroup\$ – Anush Apr 25 at 9:43
  • 1
    \$\begingroup\$ @Anush: Seems to terminate in less than a second to me. \$\endgroup\$ – Emigna Apr 25 at 9:45
  • \$\begingroup\$ you have to set all the variables to 20. See tio.run/##yy9OTMpM/f9f79Du3GK9Q6tzHzXs@v8/2shAB4xiuRBMAA \$\endgroup\$ – Anush Apr 25 at 9:46
  • \$\begingroup\$ @Anush: Ah, you meant b1=b2=b3=20 ,yeah that doesn't terminate. \$\endgroup\$ – Emigna Apr 25 at 9:46
  • 1
    \$\begingroup\$ @Anush: It is fixed now. Thanks for pointing out my mistake :) \$\endgroup\$ – Emigna Apr 25 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\$
  • \$\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\$ – Acccumulation Apr 25 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\$
  • \$\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\$ – Ørjan Johansen Apr 29 at 0:24
  • \$\begingroup\$ @Ørjan Johansen Moved l(h) to the right, and maybe it works now? Edit: Wait, it doesn't. \$\endgroup\$ – Naruyoko Apr 29 at 0:58
  • \$\begingroup\$ Added equality tolerance 0.01. \$\endgroup\$ – Naruyoko Apr 29 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\$ – Ørjan Johansen Apr 29 at 2:24
  • \$\begingroup\$ @Ørjan Johansen Ok, thanks! \$\endgroup\$ – Naruyoko Apr 29 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\$
  • \$\begingroup\$ I love a bc answer! Just need one in bash now :) \$\endgroup\$ – Anush Apr 26 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\$
  • \$\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\$ – Ørjan Johansen Apr 26 at 2:50
  • \$\begingroup\$ @ØrjanJohansen: good catch! I guess I have to use the pow method then. \$\endgroup\$ – Neil A. Apr 26 at 2:53
  • \$\begingroup\$ The alternate one has the 2^3^12 == 8^3^11 problem I've pointed out for others. \$\endgroup\$ – Ørjan Johansen Apr 26 at 2:54
  • \$\begingroup\$ @ØrjanJohansen: well, I guess I'm using your fixed formula then. \$\endgroup\$ – Neil A. Apr 26 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\$ – Ørjan Johansen Apr 26 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\$
  • 1
    \$\begingroup\$ I believe this fails for 2^3^12 == 8^3^11. \$\endgroup\$ – Ørjan Johansen Apr 26 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\$ – Kevin Cruijssen Apr 26 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\$ – Nick Kennedy Apr 26 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\$
  • \$\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\$ – Nick Kennedy Apr 25 at 21:36
  • \$\begingroup\$ @NickKennedy Yes, you are correct about that! I'll update the post to account for this. \$\endgroup\$ – Tau Apr 25 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, privacy policy and cookie policy

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