Skip to main content
Commonmark migration
Source Link

Java (JDK), 59 48 bytes

a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2

Try it online!

Returns an Object, which is the Integer 0 for invalid games and the Booleans true and false for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.

-2 bytes by inverting the end-of-match check.
-11 bytes by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen

##Ungolfed

Ungolfed

a->                      // Curried: Target type IntFunction<IntFunction<Object>>
    b->                  // Target type IntFunction<Object>
                         // Invalid if:
            b<0          //    Any score is negative
          | b > 29       //    Both scores above 29
          |   a > b + 2  //    Lead too big
            & a > 21     //        and leader has at least 21 points
          | a > 30       //    Anyone has 31 points
        ? 0              // If invalid, return 0 (autoboxed to Integer)
                         // If valid, return whether the game is ongoing (autoboxed to Boolean)
                         // Ongoing if:
        :   a < 21       //    Nobody has 21 points
          |   a < 30     //    Leader has fewer than 30 points
            & a < b + 2  //        and lead is small

Java (JDK), 59 48 bytes

a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2

Try it online!

Returns an Object, which is the Integer 0 for invalid games and the Booleans true and false for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.

-2 bytes by inverting the end-of-match check.
-11 bytes by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen

##Ungolfed

a->                      // Curried: Target type IntFunction<IntFunction<Object>>
    b->                  // Target type IntFunction<Object>
                         // Invalid if:
            b<0          //    Any score is negative
          | b > 29       //    Both scores above 29
          |   a > b + 2  //    Lead too big
            & a > 21     //        and leader has at least 21 points
          | a > 30       //    Anyone has 31 points
        ? 0              // If invalid, return 0 (autoboxed to Integer)
                         // If valid, return whether the game is ongoing (autoboxed to Boolean)
                         // Ongoing if:
        :   a < 21       //    Nobody has 21 points
          |   a < 30     //    Leader has fewer than 30 points
            & a < b + 2  //        and lead is small

Java (JDK), 59 48 bytes

a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2

Try it online!

Returns an Object, which is the Integer 0 for invalid games and the Booleans true and false for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.

-2 bytes by inverting the end-of-match check.
-11 bytes by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen

Ungolfed

a->                      // Curried: Target type IntFunction<IntFunction<Object>>
    b->                  // Target type IntFunction<Object>
                         // Invalid if:
            b<0          //    Any score is negative
          | b > 29       //    Both scores above 29
          |   a > b + 2  //    Lead too big
            & a > 21     //        and leader has at least 21 points
          | a > 30       //    Anyone has 31 points
        ? 0              // If invalid, return 0 (autoboxed to Integer)
                         // If valid, return whether the game is ongoing (autoboxed to Boolean)
                         // Ongoing if:
        :   a < 21       //    Nobody has 21 points
          |   a < 30     //    Leader has fewer than 30 points
            & a < b + 2  //        and lead is small
-11 bytes
Source Link
Sara J
  • 3.8k
  • 17
  • 36

Java (JDK), 5959 48 bytes

(a,b)->b<0||b>29||a>b+2&&a>21||a>30>b->b<0|b>29|a>b+2&a>21|a>30?0:a<21||a<30&&a<b+2?1:2a<21|a<30&a<b+2

Try it online!Try it online!

Returns an Object, which is the Integer 0 for invalid games, and the 1Booleans true and false for valid ongoing games, 2 and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.

-2 bytes by inverting the end-of-match check.
-11 bytes by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen

(a,b) ->                       // Invalid ifCurried: Target type IntFunction<IntFunction<Object>>
    b->            b<0      // Target type IntFunction<Object>
   //   either input negative
             || b > 29 // Invalid if:
            b<0          //   both inputsAny atscore leastis 30negative
          | b > ||29    a > b +// 2
   Both scores above 29
          &&| a > 21a > b + 2  //   past 21 points and leadLead too big
             ||& a > 30    21     //   anyone passed 30 points
   and leader has at least 21 points
  ? 0       | a > 30       // Output 0 if invalid
 Anyone has 31 points
        ? 0              // If invalid, return //0 Still(autoboxed ongoingto if:Integer)
           :      a < 21       // If valid, return nobodywhether hasthe 21game points
is ongoing (autoboxed to Boolean)
           ||    a < 30  
       // Ongoing if:
        :  && a < b21 + 2 //    small// lead, and nobody Nobody has 3021 points
             ? 1 |   a < 30     //    //Leader Outputhas 1fewer ifthan still30 ongoingpoints
             : 2& a < b + 2  //        //and Outputlead 2is otherwisesmall

Java (JDK), 59 bytes

(a,b)->b<0||b>29||a>b+2&&a>21||a>30?0:a<21||a<30&&a<b+2?1:2

Try it online!

Returns 0 for invalid games, 1 for valid ongoing games, 2 for valid finished games. Takes the score ordered, with the higher score first.

-2 bytes by inverting the end-of-match check.

(a,b) ->                       // Invalid if:
                b<0            //   either input negative
             || b > 29         //   both inputs at least 30
             ||    a > b + 2
                && a > 21      //   past 21 points and lead too big
             || a > 30         //   anyone passed 30 points
           ? 0                 // Output 0 if invalid
                               // Still ongoing if:
           :      a < 21       //    nobody has 21 points
               ||    a < 30  
                   && a < b + 2 //    small lead, and nobody has 30 points
             ? 1               // Output 1 if still ongoing
             : 2               // Output 2 otherwise

Java (JDK), 59 48 bytes

a->b->b<0|b>29|a>b+2&a>21|a>30?0:a<21|a<30&a<b+2

Try it online!

Returns an Object, which is the Integer 0 for invalid games and the Booleans true and false for valid ongoing games and for valid finished games respectively. Takes the score ordered (and curried), with the higher score first.

-2 bytes by inverting the end-of-match check.
-11 bytes by currying, using bitwise operators, and some return type autoboxing trickery - thanks to @KevinCruijssen

a->                      // Curried: Target type IntFunction<IntFunction<Object>>
    b->                  // Target type IntFunction<Object>
                         // Invalid if:
            b<0          //    Any score is negative
          | b > 29       //    Both scores above 29
          |   a > b + 2  //    Lead too big
            & a > 21     //        and leader has at least 21 points
          | a > 30       //    Anyone has 31 points
        ? 0              // If invalid, return 0 (autoboxed to Integer)
                         // If valid, return whether the game is ongoing (autoboxed to Boolean)
                         // Ongoing if:
        :   a < 21       //    Nobody has 21 points
          |   a < 30     //    Leader has fewer than 30 points
            & a < b + 2  //        and lead is small
Saved two bytes
Source Link
Sara J
  • 3.8k
  • 17
  • 36

Java (JDK), 6159 bytes

(a,b)->b<0||b>29||a>b+2&&a>21||a>30?0:a>20&&(a>29||a>b+1)a<21||a<30&&a<b+2?2:1:2

Try it online!Try it online!

Returns 0 for invalid games, 1 for valid ongoing games, 2 for valid finished games. Takes the score ordered, with the higher score first.

-2 bytes by inverting the end-of-match check.

##Ungolfed

(a,b) ->                       // Invalid if:
               b <b<0 0           // Invalid if either number isinput negative
             || b > 29          // Invalid if bboth overinputs 29at least 30
             ||    a > b + 2    
                && a > 21       // Invalid if apast should've21 alreadypoints wonand lead too big
             || a > 30          // Invalid if aanyone overpassed 30 points
           ? 0                  // ReturnOutput 0 if invalid
          :      a > 20        // Can only be a win if a// hasStill atongoing leastif:
 20 pts
         :     && (a < 21 a > 29    // If a is 30, anobody has won21 points
               ||   || a >< b30 + 1 
 // Otherwise a needs a 2 pt lead
          && a < b + 2 //  )  small lead, and nobody has 30 points
            ? 2? 1               // ReturnOutput 21 forif astill winongoing
            : 1: 2               // ReturnOutput 12 otherwise

Java (JDK), 61 bytes

(a,b)->b<0||b>29||a>b+2&&a>21||a>30?0:a>20&&(a>29||a>b+1)?2:1

Try it online!

Returns 0 for invalid games, 1 for valid ongoing games, 2 for valid finished games. Takes the score ordered, with the higher score first.

##Ungolfed

(a,b) ->
               b < 0           // Invalid if either number is negative
            || b > 29          // Invalid if b over 29
            ||    a > b + 2    
               && a > 21       // Invalid if a should've already won
            || a > 30          // Invalid if a over 30
          ? 0                  // Return 0 if invalid
          :      a > 20        // Can only be a win if a has at least 20 pts
              && (   a > 29    // If a is 30, a has won
                  || a > b + 1 // Otherwise a needs a 2 pt lead
                 )
            ? 2                // Return 2 for a win
            : 1                // Return 1 otherwise

Java (JDK), 59 bytes

(a,b)->b<0||b>29||a>b+2&&a>21||a>30?0:a<21||a<30&&a<b+2?1:2

Try it online!

Returns 0 for invalid games, 1 for valid ongoing games, 2 for valid finished games. Takes the score ordered, with the higher score first.

-2 bytes by inverting the end-of-match check.

##Ungolfed

(a,b) ->                       // Invalid if:
                b<0            //   either input negative
             || b > 29         //   both inputs at least 30
             ||    a > b + 2
                && a > 21      //   past 21 points and lead too big
             || a > 30         //   anyone passed 30 points
           ? 0                 // Output 0 if invalid
                               // Still ongoing if:
           :      a < 21       //    nobody has 21 points
               ||    a < 30   
                  && a < b + 2 //    small lead, and nobody has 30 points
             ? 1               // Output 1 if still ongoing
             : 2               // Output 2 otherwise
Removed a stray semicolon - it's not necessary, and was already not included in the bytecount
Source Link
Sara J
  • 3.8k
  • 17
  • 36
Loading
Source Link
Sara J
  • 3.8k
  • 17
  • 36
Loading