Skip to main content
deleted 252 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Java 8, 116116 99 bytes

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat-17 bytes thanks to @Neil by taking four loose integer inputs instead of an integer-array.

Try it online.Try it online.

Explanation:

(a,b,c,d)->{         // Method with four integer-array parameterparameters and integer return-type
 int r=0,    //  Result-index, starting at 0
     i=-1,   //  Index-integer, starting at -1
     m=0,    //  Max value, starting at 0
     t;      //  Temp-integer, uninitialized
     ++i<4   //  Loop `i` in the range (-1,4) (or [0,3]):
     ;       //    After every iteration:
      a=new int[]{a[2]t=a,a[0]a=c,a[3]c=d,a[1]}d=b,b=t)
             //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]t=a/a[2]c-a[1]b/a[3]d)
             //    Set `t` to a//c-b//d
      >m){   //    And if `t` is larger than `m`:
     m=t;    //     Set maximum `m` to this `t`
     r=i;}   //     And update the result with the current index `i`
  return r;} //  Finally, return the result-index `r`

Java 8, 116 bytes

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat integer-array.

Try it online.

Explanation:

a->{         // Method with integer-array parameter and integer return-type
 int r=0,    //  Result-index, starting at 0
     i=-1,   //  Index-integer, starting at -1
     m=0,    //  Max value, starting at 0
     t;      //  Temp-integer, uninitialized
     ++i<4   //  Loop `i` in the range (-1,4) (or [0,3]):
     ;       //    After every iteration:
      a=new int[]{a[2],a[0],a[3],a[1]})
             //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]/a[2]-a[1]/a[3])
             //    Set `t` to a//c-b//d
      >m){   //    And if `t` is larger than `m`:
     m=t;    //     Set maximum `m` to this `t`
     r=i;}   //     And update the result with the current index `i`
  return r;} //  Finally, return the result-index `r`

Java 8, 116 99 bytes

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

-17 bytes thanks to @Neil by taking four loose integer inputs instead of an integer-array

Try it online.

Explanation:

(a,b,c,d)->{ // Method with four integer parameters and integer return-type
 int r=0,    //  Result-index, starting at 0
     i=-1,   //  Index-integer, starting at -1
     m=0,    //  Max value, starting at 0
     t;      //  Temp-integer, uninitialized
     ++i<4   //  Loop `i` in the range (-1,4) (or [0,3]):
     ;       //    After every iteration:
      t=a,a=c,c=d,d=b,b=t)
             //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a/c-b/d)
             //    Set `t` to a//c-b//d
      >m){   //    And if `t` is larger than `m`:
     m=t;    //     Set maximum `m` to this `t`
     r=i;}   //     And update the result with the current index `i`
  return r;} //  Finally, return the result-index `r`
deleted 793 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Java 8, 123116 bytes

a->{int r=0,i=-1;for(float m=0,t;++i<4;a=new float[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat float-array.

Try it online.

If OP clarifies that we should integer-divide instead of using a regular divide (which would explain the [5,6,7,8]=0 test case), it could be a bit shorter (116 bytes):

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat integer-array.

Try it online.Try it online.

Explanation:

a->{            // Method with floatinteger-array parameter and integer return-type
 int r=0,       //  Result-index, starting at 0
     i=-1;   1,   //  Index-integer, starting at -1
 for(float    m=0,    //  Max-float value, starting at 0
        t;   t;   //  Temp-floatinteger, uninitialized
     ++i<4      //  Loop `i` in the range (-1,4) (or [0,3]):
     ;          //    After every iteration:
      a=new float[]int[]{a[2],a[0],a[3],a[1]})
                //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]/a[2]-a[1]/a[3])
                //    Set `t` to a//c-b//d
      >m){      //    And if `t` is larger than `m`:
     m=t;       //     Set maximum `m` to this `t`
     r=i;}      //     And update the result with the current index `i`
  return r;}    //  Finally, return the result-index `r`

Java 8, 123 bytes

a->{int r=0,i=-1;for(float m=0,t;++i<4;a=new float[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat float-array.

Try it online.

If OP clarifies that we should integer-divide instead of using a regular divide (which would explain the [5,6,7,8]=0 test case), it could be a bit shorter (116 bytes):

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat integer-array.

Try it online.

Explanation:

a->{            // Method with float-array parameter and integer return-type
 int r=0,       //  Result-index, starting at 0
     i=-1;      //  Index-integer, starting at -1
 for(float m=0, //  Max-float, starting at 0
           t;   //  Temp-float, uninitialized
     ++i<4      //  Loop `i` in the range (-1,4) (or [0,3]):
     ;          //    After every iteration:
      a=new float[]{a[2],a[0],a[3],a[1]})
                //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]/a[2]-a[1]/a[3])
                //    Set `t` to a/c-b/d
      >m){      //    And if `t` is larger than `m`:
     m=t;       //     Set maximum `m` to this `t`
     r=i;}      //     And update the result with the current index `i`
  return r;}    //  Finally, return the result-index `r`

Java 8, 116 bytes

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat integer-array.

Try it online.

Explanation:

a->{         // Method with integer-array parameter and integer return-type
 int r=0,    //  Result-index, starting at 0
     i=-1,   //  Index-integer, starting at -1
     m=0,    //  Max value, starting at 0
     t;      //  Temp-integer, uninitialized
     ++i<4   //  Loop `i` in the range (-1,4) (or [0,3]):
     ;       //    After every iteration:
      a=new int[]{a[2],a[0],a[3],a[1]})
             //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]/a[2]-a[1]/a[3])
             //    Set `t` to a//c-b//d
      >m){   //    And if `t` is larger than `m`:
     m=t;    //     Set maximum `m` to this `t`
     r=i;}   //     And update the result with the current index `i`
  return r;} //  Finally, return the result-index `r`
added 1651 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Java 8, 123 bytes

a->{int r=0,i=-1;for(float m=0,t;++i<4;a=new float[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat float-array.

Try it online.

If OP clarifies that we should integer-divide instead of using a regular divide (which would explain the [5,6,7,8]=0 test case), it could be a bit shorter (116 bytes):

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat integer-array.

Try it online.

Explanation:

a->{            // Method with float-array parameter and integer return-type
 int r=0,       //  Result-index, starting at 0
     i=-1;      //  Index-integer, starting at -1
 for(float m=0, //  Max-float, starting at 0
           t;   //  Temp-float, uninitialized
     ++i<4      //  Loop `i` in the range (-1,4) (or [0,3]):
     ;          //    After every iteration:
      a=new float[]{a[2],a[0],a[3],a[1]})
                //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]/a[2]-a[1]/a[3])
                //    Set `t` to a/c-b/d
      >m){      //    And if `t` is larger than `m`:
     m=t;       //     Set maximum `m` to this `t`
     r=i;}      //     And update the result with the current index `i`
  return r;}    //  Finally, return the result-index `r`

Java 8, 123 bytes

a->{int r=0,i=-1;for(float m=0,t;++i<4;a=new float[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Try it online.

Java 8, 123 bytes

a->{int r=0,i=-1;for(float m=0,t;++i<4;a=new float[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat float-array.

Try it online.

If OP clarifies that we should integer-divide instead of using a regular divide (which would explain the [5,6,7,8]=0 test case), it could be a bit shorter (116 bytes):

a->{int r=0,i=-1,m=0,t;for(;++i<4;a=new int[]{a[2],a[0],a[3],a[1]})if((t=a[0]/a[2]-a[1]/a[3])>m){m=t;r=i;}return r;}

Input as a flat integer-array.

Try it online.

Explanation:

a->{            // Method with float-array parameter and integer return-type
 int r=0,       //  Result-index, starting at 0
     i=-1;      //  Index-integer, starting at -1
 for(float m=0, //  Max-float, starting at 0
           t;   //  Temp-float, uninitialized
     ++i<4      //  Loop `i` in the range (-1,4) (or [0,3]):
     ;          //    After every iteration:
      a=new float[]{a[2],a[0],a[3],a[1]})
                //     Rotate: change a,b,c,d to c,a,d,b
   if((t=a[0]/a[2]-a[1]/a[3])
                //    Set `t` to a/c-b/d
      >m){      //    And if `t` is larger than `m`:
     m=t;       //     Set maximum `m` to this `t`
     r=i;}      //     And update the result with the current index `i`
  return r;}    //  Finally, return the result-index `r`
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading