Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Java 8, (削除) 283 (削除ここまで) 270 bytes

Java 8, (削除) 283 (削除ここまで) 270 bytes

#Java 8, (削除) 283 (削除ここまで) 270 bytes

Java 8, (削除) 283 (削除ここまで) 270 bytes

added 479 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#Java 8, 283(削除) 283 (削除ここまで) 270 bytes

s->{String[]a=s.split("\\d"),b=s.split("\\D+");int i=0,r=1,x,y;for(;i<a.length-1;y=new Byte(b[++i]),r-=a[i].equals("==")&x!=y|a[i].equals("!=")&x==y|a[i].equals(">")&x<=y|a[i].equals(">=")&x<y|a[i].equals("<")&x>=y|a[i].equals("<=")&x>y?1:0)x=new Byte(b[i]);return r>0;}
s->{String[]a=s.split("\\d"),b=s.split("\\D+");int i=0,r=1,x,y;for(;i<a.length-1;)if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))|(a[i].equals("!=")&x==y)|(a[i].equals(">")&x<=y)|(a[i].equals(">=")&x<y)|(a[i].equals("<")&x>=y)|(a[i].equals("<=")&x>y))r--;return r>0;}

-13 bytes thanks to @ceilingcat.

Try it here. Try it here.

s->{ // Method with String parameter and boolean return-type
 String[]a=s.split("\\d"), // All the inequalities
 b=s.split("\\D+"); // All the digits
 int i=0, // Index-integer (starting at 0)
 r=1, // Flag integer for the result, starting at 1
 x,y; // Temp integer `x` and `y`
 for(;i<a.length-1;) // Loop from 0 to the length - 1
 if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))
 // If "==" and `x` and `y` as int are not equal:
 |(a[i].equals("!=")&x==y) // Or "!=" and `x` and `y` are equal
 |(a[i].equals(">")&x<=y) // Or ">" and `x` is smaller or equal to `y`
 |(a[i].equals(">=")&x<y) // Or ">=" and `x` is smaller than `y`
 |(a[i].equals("<")&x>=y) // Or "<" and `x` is larger or equal to `y`
 |(a[i].equals("<=")&x>y)) // Or "<=" and `x` is larger than `y`
 r--; // Decrease `r` by 1
 // End of loop (implicit / single-line body)
 return r>0; // Return if `r` is still 1
} // End of method
s->{ // Method with String parameter and boolean return-type
 String[]a=s.split("\\d"), // All the inequalities
 b=s.split("\\D+"); // All the digits
 int i=0, // Index-integer (starting at 0)
 r=1, // Flag integer for the result, starting at 1
 x,y; // Temp integer `x` and `y`
 for(;i<a.length-1 // Loop `i` in the range [0, length]:
 ; // After every iteration:
 y=new Byte(b[++i]), // Convert the `i+1`'th digit from String to integer,
 // and store it in `y`
 r-= // Decrease the result by:
 a[i].equals("==")&x!=y // If "==" and `x` and `y` are not equal
 |a[i].equals("!=")&x==y// or if "!=" and `x` and `y` are equal
 |a[i].equals(">")&x<=y // or if ">" and `x` is smaller than or equal to `y`
 |a[i].equals(">=")&x<y // or if ">=" and `x` is smaller than `y`
 |a[i].equals("<")&x>=y // or if "<" and `x` is larger than o equal to `y`
 |a[i].equals("<=")&x>y // or if "<=" and `x` is larger than `y`:
 1 // Decrease the result by 1
 :0; // Else: keep it the same by decreasing with 0
 x=new Byte(b[i]); // Convert the `i`'th digit from String to integer,
 // and store it in `x`
 return r>0;} // Return whether the result is still 1

#Java 8, 283 bytes

s->{String[]a=s.split("\\d"),b=s.split("\\D+");int i=0,r=1,x,y;for(;i<a.length-1;)if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))|(a[i].equals("!=")&x==y)|(a[i].equals(">")&x<=y)|(a[i].equals(">=")&x<y)|(a[i].equals("<")&x>=y)|(a[i].equals("<=")&x>y))r--;return r>0;}

Try it here.

s->{ // Method with String parameter and boolean return-type
 String[]a=s.split("\\d"), // All the inequalities
 b=s.split("\\D+"); // All the digits
 int i=0, // Index-integer (starting at 0)
 r=1, // Flag integer for the result, starting at 1
 x,y; // Temp integer `x` and `y`
 for(;i<a.length-1;) // Loop from 0 to the length - 1
 if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))
 // If "==" and `x` and `y` as int are not equal:
 |(a[i].equals("!=")&x==y) // Or "!=" and `x` and `y` are equal
 |(a[i].equals(">")&x<=y) // Or ">" and `x` is smaller or equal to `y`
 |(a[i].equals(">=")&x<y) // Or ">=" and `x` is smaller than `y`
 |(a[i].equals("<")&x>=y) // Or "<" and `x` is larger or equal to `y`
 |(a[i].equals("<=")&x>y)) // Or "<=" and `x` is larger than `y`
 r--; // Decrease `r` by 1
 // End of loop (implicit / single-line body)
 return r>0; // Return if `r` is still 1
} // End of method

#Java 8, (削除) 283 (削除ここまで) 270 bytes

s->{String[]a=s.split("\\d"),b=s.split("\\D+");int i=0,r=1,x,y;for(;i<a.length-1;y=new Byte(b[++i]),r-=a[i].equals("==")&x!=y|a[i].equals("!=")&x==y|a[i].equals(">")&x<=y|a[i].equals(">=")&x<y|a[i].equals("<")&x>=y|a[i].equals("<=")&x>y?1:0)x=new Byte(b[i]);return r>0;}

-13 bytes thanks to @ceilingcat.

Try it here.

s->{ // Method with String parameter and boolean return-type
 String[]a=s.split("\\d"), // All the inequalities
 b=s.split("\\D+"); // All the digits
 int i=0, // Index-integer (starting at 0)
 r=1, // Flag integer for the result, starting at 1
 x,y; // Temp integer `x` and `y`
 for(;i<a.length-1 // Loop `i` in the range [0, length]:
 ; // After every iteration:
 y=new Byte(b[++i]), // Convert the `i+1`'th digit from String to integer,
 // and store it in `y`
 r-= // Decrease the result by:
 a[i].equals("==")&x!=y // If "==" and `x` and `y` are not equal
 |a[i].equals("!=")&x==y// or if "!=" and `x` and `y` are equal
 |a[i].equals(">")&x<=y // or if ">" and `x` is smaller than or equal to `y`
 |a[i].equals(">=")&x<y // or if ">=" and `x` is smaller than `y`
 |a[i].equals("<")&x>=y // or if "<" and `x` is larger than o equal to `y`
 |a[i].equals("<=")&x>y // or if "<=" and `x` is larger than `y`:
 1 // Decrease the result by 1
 :0; // Else: keep it the same by decreasing with 0
 x=new Byte(b[i]); // Convert the `i`'th digit from String to integer,
 // and store it in `x`
 return r>0;} // Return whether the result is still 1
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#Java 8, 283 bytes

s->{String[]a=s.split("\\d"),b=s.split("\\D+");int i=0,r=1,x,y;for(;i<a.length-1;)if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))|(a[i].equals("!=")&x==y)|(a[i].equals(">")&x<=y)|(a[i].equals(">=")&x<y)|(a[i].equals("<")&x>=y)|(a[i].equals("<=")&x>y))r--;return r>0;}

Explanation:

Try it here.

s->{ // Method with String parameter and boolean return-type
 String[]a=s.split("\\d"), // All the inequalities
 b=s.split("\\D+"); // All the digits
 int i=0, // Index-integer (starting at 0)
 r=1, // Flag integer for the result, starting at 1
 x,y; // Temp integer `x` and `y`
 for(;i<a.length-1;) // Loop from 0 to the length - 1
 if((x=new Byte(b[i]))!=(y=new Byte(b[++i]))&(a[i].equals("=="))
 // If "==" and `x` and `y` as int are not equal:
 |(a[i].equals("!=")&x==y) // Or "!=" and `x` and `y` are equal
 |(a[i].equals(">")&x<=y) // Or ">" and `x` is smaller or equal to `y`
 |(a[i].equals(">=")&x<y) // Or ">=" and `x` is smaller than `y`
 |(a[i].equals("<")&x>=y) // Or "<" and `x` is larger or equal to `y`
 |(a[i].equals("<=")&x>y)) // Or "<=" and `x` is larger than `y`
 r--; // Decrease `r` by 1
 // End of loop (implicit / single-line body)
 return r>0; // Return if `r` is still 1
} // End of method

AltStyle によって変換されたページ (->オリジナル) /