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

Java 8, 181 157 156 149149 147 bytes

(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f%9/8)for(f=t=9;M[R][c]==8&t-->0;)try{f-=M[R+t/3-1][c+t%3-1]%9/8;}catch(Exception e)finally{continue;}return z;}

-24 bytes thanks to @OlivierGrégoire
-2 bytes thanks to @ceilingcat.

Try it online.Try it online.

(M,R,C)->{                    // Method with integer-matrix as parameter & integer return
  int z=0,                    //  Result-counter, starting at 0
      c,f,t;                  //  Temp-integers, starting uninitialized
  for(;R-->0;)                //  Loop over the rows:
    for(c=C;c-->0             //   Inner loop over the columns:
           ;                  //     After every iteration:
            z+=f%9/8)         //      If the digit in this cell is 8:
                              //       Increase the result-counter by 1
                              //      Else: leave it the same
      for(f=t=9;              //    Reset the flag to 9
          M[R][c]==8&         //    If the current cell contains an 8:
            t-->0;)           //     Inner loop `t` in the range (9, 0]:
        try{f-=               //      Decrease the flag by:
               M[R+t/3-1]     //       If `t` is 0, 1, or 2: Look at the previous row
                              //       Else-if `t` is 3, 4, or 5: Look at the current row
                              //       Else (`t` is 6, 7, or 8): Look at the next row
                [c+t%3-1]     //       If `t` is 0, 3, or 6: Look at the previous column
                              //       Else-if `t` is 1, 4, or 7: Look at the current column
                              //       Else (`t` is 2, 5, or 8): Look at the next column
                %9/8;         //       And if the digit in this cell is 8:
                              //        Decrease the flag-integer by 1
                              //       Else: leave it the same
        }catch(Exception e)finally{continue;} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                              //      (try-catchfinally saves bytes in comparison to if-checks)
  return z;}                  //  And finally return the counter

Java 8, 181 157 156 149 bytes

(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f%9/8)for(f=t=9;M[R][c]==8&t-->0;)try{f-=M[R+t/3-1][c+t%3-1]%9/8;}catch(Exception e){}return z;}

-24 bytes thanks to @OlivierGrégoire.

Try it online.

(M,R,C)->{                    // Method with integer-matrix as parameter & integer return
  int z=0,                    //  Result-counter, starting at 0
      c,f,t;                  //  Temp-integers, starting uninitialized
  for(;R-->0;)                //  Loop over the rows:
    for(c=C;c-->0             //   Inner loop over the columns:
           ;                  //     After every iteration:
            z+=f%9/8)         //      If the digit in this cell is 8:
                              //       Increase the result-counter by 1
                              //      Else: leave it the same
      for(f=t=9;              //    Reset the flag to 9
          M[R][c]==8&         //    If the current cell contains an 8:
            t-->0;)           //     Inner loop `t` in the range (9, 0]:
        try{f-=               //      Decrease the flag by:
               M[R+t/3-1]     //       If `t` is 0, 1, or 2: Look at the previous row
                              //       Else-if `t` is 3, 4, or 5: Look at the current row
                              //       Else (`t` is 6, 7, or 8): Look at the next row
                [c+t%3-1]     //       If `t` is 0, 3, or 6: Look at the previous column
                              //       Else-if `t` is 1, 4, or 7: Look at the current column
                              //       Else (`t` is 2, 5, or 8): Look at the next column
                %9/8;         //       And if the digit in this cell is 8:
                              //        Decrease the flag-integer by 1
                              //       Else: leave it the same
        }catch(Exception e){} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                              //      (try-catch saves bytes in comparison to if-checks)
  return z;}                  //  And finally return the counter

Java 8, 181 157 156 149 147 bytes

(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f%9/8)for(f=t=9;M[R][c]==8&t-->0;)try{f-=M[R+t/3-1][c+t%3-1]%9/8;}finally{continue;}return z;}

-24 bytes thanks to @OlivierGrégoire
-2 bytes thanks to @ceilingcat.

Try it online.

(M,R,C)->{                  // Method with integer-matrix as parameter & integer return
  int z=0,                  //  Result-counter, starting at 0
      c,f,t;                //  Temp-integers, starting uninitialized
  for(;R-->0;)              //  Loop over the rows:
    for(c=C;c-->0           //   Inner loop over the columns:
           ;                //     After every iteration:
            z+=f%9/8)       //      If the digit in this cell is 8:
                            //       Increase the result-counter by 1
                            //      Else: leave it the same
      for(f=t=9;            //    Reset the flag to 9
          M[R][c]==8&       //    If the current cell contains an 8:
            t-->0;)         //     Inner loop `t` in the range (9, 0]:
        try{f-=             //      Decrease the flag by:
               M[R+t/3-1]   //       If `t` is 0, 1, or 2: Look at the previous row
                            //       Else-if `t` is 3, 4, or 5: Look at the current row
                            //       Else (`t` is 6, 7, or 8): Look at the next row
                [c+t%3-1]   //       If `t` is 0, 3, or 6: Look at the previous column
                            //       Else-if `t` is 1, 4, or 7: Look at the current column
                            //       Else (`t` is 2, 5, or 8): Look at the next column
                %9/8;       //       And if the digit in this cell is 8:
                            //        Decrease the flag-integer by 1
                            //       Else: leave it the same
        }finally{continue;} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                            //      (try-finally saves bytes in comparison to if-checks)
  return z;}                //  And finally return the counter
added 19 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Java 8, 181 157 156156 149 bytes

(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f>1?0:f>0;z+=f%9/8)for(f=0,t=9;M[R][c]==8&tf=t=9;M[R][c]==8&t-->0;)try{f+=M[R+tf-=M[R+t/3-1][c+t%3-1]==8?1:0;1]%9/8;}catch(Exception e){}return z;}

Try it online.Try it online.

(M,R,C)->{                    // Method with integer-matrix as parameter & integer return
  int z=0,                    //  Result-counter, starting at 0
      c,f,t;                  //  Temp-integers, starting uninitialized
  for(;R-->0;)                //  Loop over the rows:
    for(c=C;c-->0             //   Inner loop over the columns:
           ;                  //     After every iteration:
            z+=f==1? z+=f%9/8)         //      If the flag-integerdigit isin largerthis thancell 1is 8:
                0              //       LeaveIncrease the result-counter the same by adding 01
               :               //      Else:
                f)            //      leave Addit the flag-integer (either 0 or 1)same
      for(f=0,  f=t=9;              //    Reset the flag to 09
          t=9;M[R][c]==8&M[R][c]==8&         //    If the current cell contains an 8:
              t-->0;)           //     Inner loop `t` in the range (9, 0]:
        try{f+=f-=               //      IncreaseDecrease the flag by:
               M[R+t/3-1]     //       If `t` is 0, 1, or 2: Look at the previous row
                              //       Else-if `t` is 63, 74, or 85: Look at the nextcurrent row
                              //       Else (`t` is 36, 47, or 58): Look at the currentnext row
                [c+t%3-1]     //       If `t` is 0, 3, or 6: Look at the previous column
                              //       Else-if `t` is 21, 54, or 87: Look at the nextcurrent column
                              //       Else (`t` is 12, 45, or 78): Look at the currentnext column
                ==8? %9/8;         //       And if the digit in this cell is 8:
                 1             //        IncreaseDecrease the flag-integer by 1
                :0;              //       Else: leave it the same
        }catch(Exception e){} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                              //      (try-catch saves bytes in comparison to if-checks)
  return z;}                  //  And finally return the counter

Java 8, 181 157 156 bytes

(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f>1?0:f)for(f=0,t=9;M[R][c]==8&t-->0;)try{f+=M[R+t/3-1][c+t%3-1]==8?1:0;}catch(Exception e){}return z;}

Try it online.

(M,R,C)->{                    // Method with integer-matrix as parameter & integer return
  int z=0,                    //  Result-counter, starting at 0
      c,f,t;                  //  Temp-integers, starting uninitialized
  for(;R-->0;)                //  Loop over the rows:
    for(c=C;c-->0             //   Inner loop over the columns:
           ;                  //     After every iteration:
            z+=f==1?          //      If the flag-integer is larger than 1:
                0             //       Leave the result-counter the same by adding 0
               :              //      Else:
                f)            //       Add the flag-integer (either 0 or 1)
      for(f=0,                //    Reset the flag to 0
          t=9;M[R][c]==8&     //    If the current cell contains an 8:
              t-->0;)         //     Inner loop `t` in the range (9, 0]:
        try{f+=               //      Increase the flag by:
               M[R+t/3-1]     //       If `t` is 0, 1, or 2: Look at the previous row
                              //       Else-if `t` is 6, 7, or 8: Look at the next row
                              //       Else (`t` is 3, 4, or 5): Look at the current row
                [c+t%3-1]     //       If `t` is 0, 3, or 6: Look at the previous column
                              //       Else-if `t` is 2, 5, or 8: Look at the next column
                              //       Else (`t` is 1, 4, or 7): Look at the current column
                ==8?          //       And if the digit in this cell is 8:
                 1            //        Increase the flag-integer by 1
                :0;           //       Else: leave it the same
        }catch(Exception e){} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                              //      (try-catch saves bytes in comparison to if-checks)
  return z;}                  //  And finally return the counter

Java 8, 181 157 156 149 bytes

(M,R,C)->{int z=0,c,f,t;for(;R-->0;)for(c=C;c-->0;z+=f%9/8)for(f=t=9;M[R][c]==8&t-->0;)try{f-=M[R+t/3-1][c+t%3-1]%9/8;}catch(Exception e){}return z;}

Try it online.

(M,R,C)->{                    // Method with integer-matrix as parameter & integer return
  int z=0,                    //  Result-counter, starting at 0
      c,f,t;                  //  Temp-integers, starting uninitialized
  for(;R-->0;)                //  Loop over the rows:
    for(c=C;c-->0             //   Inner loop over the columns:
           ;                  //     After every iteration:
            z+=f%9/8)         //      If the digit in this cell is 8:
                              //       Increase the result-counter by 1
                              //      Else: leave it the same
      for(f=t=9;              //    Reset the flag to 9
          M[R][c]==8&         //    If the current cell contains an 8:
            t-->0;)           //     Inner loop `t` in the range (9, 0]:
        try{f-=               //      Decrease the flag by:
               M[R+t/3-1]     //       If `t` is 0, 1, or 2: Look at the previous row
                              //       Else-if `t` is 3, 4, or 5: Look at the current row
                              //       Else (`t` is 6, 7, or 8): Look at the next row
                [c+t%3-1]     //       If `t` is 0, 3, or 6: Look at the previous column
                              //       Else-if `t` is 1, 4, or 7: Look at the current column
                              //       Else (`t` is 2, 5, or 8): Look at the next column
                %9/8;         //       And if the digit in this cell is 8:
                              //        Decrease the flag-integer by 1
                              //       Else: leave it the same
        }catch(Exception e){} //      Catch and ignore ArrayIndexOutOfBoundsExceptions
                              //      (try-catch saves bytes in comparison to if-checks)
  return z;}                  //  And finally return the counter
Commonmark migration
Source Link

#Java 8, 181 157 156 bytes

Java 8, 181 157 156 bytes

#Java 8, 181 157 156 bytes

Java 8, 181 157 156 bytes

deleted 167 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
added 2279 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading