#Java 10, (削除) 262 (削除ここまで)(削除) 260 (削除ここまで)(削除) 248 (削除ここまで) 239 bytes
Java 10, (削除) 262 (削除ここまで)(削除) 260 (削除ここまで)(削除) 248 (削除ここまで) 239 bytes
#Java 10, (削除) 262 (削除ここまで)(削除) 260 (削除ここまで)(削除) 248 (削除ここまで) 239 bytes
Java 10, (削除) 262 (削除ここまで)(削除) 260 (削除ここまで)(削除) 248 (削除ここまで) 239 bytes
#Java 810, (削除) 262 (削除ここまで) 260(削除) 260 (削除ここまで)(削除) 248 (削除ここまで) 239 bytes
v->{int a[][]=new int[7][7],i=7i=49,j,k;for(;i-->0;)for(j=7;j-->0;)a[i][j]=(int)(Matha[i/7][i%7]+=Math.random()*9+1);String*9+1;var r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")if(i%2+j%2>1i*j%2>0)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}
-12 bytes thanks to @ceilingcat.
Explanation:
v->{ // Method with empty unused parameter and String return-type
int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
i=7i=49,j,k; // Index integers (`i` starting at 749)
for(;i-->0;) // Loop (1) from 6 down to 0 (inclusive)
for(j=7;j-->0;) // `i` in Innerthe looprange (2) from 6 down to 049, (inclusive)0]:
a[i][j]=(int)(Matha[i/7][j%7]+=Math.random()*9+1);*9+1;
// Fill the current cell with a random 1-..9 integer
// End of inner loop (2) (implicit / single-line body)
var r=""; // End of loop (1) (implicit / singleResult-line body)
String r=""; //, starting Result-Stringempty
for(;++i<7; // Loop (3)`i` fromin 0the torange 7[0, (exclusive7):
r+="\n") // After every iteration: append a new-line to the result
for(j=0;j<7; // Inner loop (4)`j` fromin 0the torange 7[0, (exclusive7):
r+= // After every iteration: append the result-String with:
(k=a[i][j])>9 // If the current number has 2 digits,
|j++%2<1? // or it's an even column (indexesindices 0/2/4/6)
k+" " // Append the current number +appended with one space
: // Else:
k+" ") // Append the current number +appended with two spaces
if(i%2+j%2>1i*j%2>1) // If both indexes `i` and `j` are odd
for(a[i][j]=k=0; // Reset both the current item and index `k` to 0
k<9;k++) // Inner loop (5)`k` fromin 0the torange 9[0, (exlusive9):
a[i][j]+= // Sum the item at that location `i,j` with:
k!=4? // If `k` is not 4 (the current item itself)
a[i+k/3-1][j+k%3-1]
// Sum it with the numbers surrounding it
: // Else:
0; // Leave it the same by adding 0
// End of inner loop (5) (implicit / single-line body)
// End of inner loop (4) (implicit / single-line body)
// End of loop (3) (implicit / single-line body)
return r;} // Return the result-String
} // End of method
#Java 8, (削除) 262 (削除ここまで) 260 bytes
v->{int a[][]=new int[7][7],i=7,j,k;for(;i-->0;)for(j=7;j-->0;)a[i][j]=(int)(Math.random()*9+1);String r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")if(i%2+j%2>1)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}
Explanation:
v->{ // Method with empty unused parameter and String return-type
int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
i=7,j,k; // Index integers (`i` starting at 7)
for(;i-->0;) // Loop (1) from 6 down to 0 (inclusive)
for(j=7;j-->0;) // Inner loop (2) from 6 down to 0 (inclusive)
a[i][j]=(int)(Math.random()*9+1);
// Fill the current cell with a random 1-9 integer
// End of inner loop (2) (implicit / single-line body)
// End of loop (1) (implicit / single-line body)
String r=""; // Result-String
for(;++i<7; // Loop (3) from 0 to 7 (exclusive)
r+="\n") // After every iteration: append a new-line to the result
for(j=0;j<7; // Inner loop (4) from 0 to 7 (exclusive)
r+= // After every iteration: append the result-String with:
(k=a[i][j])>9 // If the current number has 2 digits,
|j++%2<1? // or it's an even column (indexes 0/2/4/6)
k+" " // Append the current number + one space
: // Else:
k+" ") // Append the current number + two spaces
if(i%2+j%2>1) // If both indexes `i` and `j` are odd
for(a[i][j]=k=0; // Reset both the current item and index `k` to 0
k<9;k++) // Inner loop (5) from 0 to 9 (exlusive)
a[i][j]+= // Sum the item at that location with:
k!=4? // If `k` is not 4 (the current item itself)
a[i+k/3-1][j+k%3-1]
// Sum it with the numbers surrounding it
: // Else:
0; // Leave it the same by adding 0
// End of inner loop (5) (implicit / single-line body)
// End of inner loop (4) (implicit / single-line body)
// End of loop (3) (implicit / single-line body)
return r; // Return the result-String
} // End of method
#Java 10, (削除) 262 (削除ここまで) (削除) 260 (削除ここまで)(削除) 248 (削除ここまで) 239 bytes
v->{int a[][]=new int[7][7],i=49,j,k;for(;i-->0;)a[i/7][i%7]+=Math.random()*9+1;var r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")if(i*j%2>0)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}
-12 bytes thanks to @ceilingcat.
Explanation:
v->{ // Method with empty unused parameter and String return-type
int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
i=49,j,k; // Index integers (`i` starting at 49)
for(;i-->0;) // Loop `i` in the range (49, 0]:
a[i/7][j%7]+=Math.random()*9+1;
// Fill the current cell with a random 1..9 integer
var r=""; // Result-String, starting empty
for(;++i<7; // Loop `i` in the range [0, 7):
r+="\n") // After every iteration: append a new-line to the result
for(j=0;j<7; // Inner loop `j` in the range [0, 7):
r+= // After every iteration: append the result-String with:
(k=a[i][j])>9 // If the current number has 2 digits,
|j++%2<1? // or it's an even column (indices 0/2/4/6)
k+" " // Append the current number appended with one space
: // Else:
k+" ") // Append the current number appended with two spaces
if(i*j%2>1) // If both indexes `i` and `j` are odd
for(a[i][j]=k=0; // Reset both the current item and index `k` to 0
k<9;k++) // Inner loop `k` in the range [0, 9):
a[i][j]+= // Sum the item at location `i,j` with:
k!=4? // If `k` is not 4 (the current item itself)
a[i+k/3-1][j+k%3-1]
// Sum it with the numbers surrounding it
: // Else:
0; // Leave it the same by adding 0
return r;} // Return the result-String
#Java 8, 262(削除) 262 (削除ここまで) 260 bytes
v->{int a[][]=new int[7][7],i=7,j,k;for(;i-->0;)for(j=7;j-->0;)a[i][j]=(int)(Math.random()*9+1);String r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")if(i%2>0&j%2>0i%2+j%2>1)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}
v->{ // Method with empty unused parameter and String return-type
int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
i=7,j,k; // Index integers (`i` starting at 7)
for(;i-->0;) // Loop (1) from 6 down to 0 (inclusive)
for(j=7;j-->0;) // Inner loop (2) from 6 down to 0 (inclusive)
a[i][j]=(int)(Math.random()*9+1);
// Fill the current cell with a random 1-9 integer
// End of inner loop (2) (implicit / single-line body)
// End of loop (1) (implicit / single-line body)
String r=""; // Result-String
for(;++i<7; // Loop (3) from 0 to 7 (exclusive)
r+="\n") // After every iteration: append a new-line to the result
for(j=0;j<7; // Inner loop (4) from 0 to 7 (exclusive)
r+= // After every iteration: append the result-String with:
(k=a[i][j])>9 // If the current number has 2 digits,
|j++%2<1? // or it's an oddeven column (1stindexes 0/3rd2/5th4/6)
k+" " // Append the current number + one space
: // Else:
k+" ") // Append the current number + two spaces
if(i%2>0&j%2>0i%2+j%2>1) // If both indexes `i` and `j` are odd
for(a[i][j]=k=0; // Reset both the current item and index `k` to 0
k<9;k++) // Inner loop (5) from 0 to 9 (exlusive)
a[i][j]+= // Sum the item at that location with:
k!=4? // If `k` is not 4 (the current item itself)
a[i+k/3-1][j+k%3-1]
// Sum it with the numbers surrounding it
: // Else:
0; // Leave it the same by adding 0
// End of inner loop (5) (implicit / single-line body)
// End of inner loop (4) (implicit / single-line body)
// End of loop (3) (implicit / single-line body)
return r; // Return the result-String
} // End of method
#Java 8, 262 bytes
v->{int a[][]=new int[7][7],i=7,j,k;for(;i-->0;)for(j=7;j-->0;)a[i][j]=(int)(Math.random()*9+1);String r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")if(i%2>0&j%2>0)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}
v->{ // Method with empty unused parameter and String return-type
int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
i=7,j,k; // Index integers (`i` starting at 7)
for(;i-->0;) // Loop (1) from 6 down to 0 (inclusive)
for(j=7;j-->0;) // Inner loop (2) from 6 down to 0 (inclusive)
a[i][j]=(int)(Math.random()*9+1);
// Fill the current cell with a random 1-9 integer
// End of inner loop (2) (implicit / single-line body)
// End of loop (1) (implicit / single-line body)
String r=""; // Result-String
for(;++i<7; // Loop (3) from 0 to 7 (exclusive)
r+="\n") // After every iteration: append a new-line to the result
for(j=0;j<7; // Inner loop (4) from 0 to 7 (exclusive)
r+= // After every iteration: append the result-String with:
(k=a[i][j])>9 // If the current number has 2 digits,
|j++%2<1? // or it's an odd column (1st/3rd/5th)
k+" " // Append the current number + one space
: // Else:
k+" ") // Append the current number + two spaces
if(i%2>0&j%2>0) // If both indexes `i` and `j` are odd
for(a[i][j]=k=0; // Reset both the current item and index `k` to 0
k<9;k++) // Inner loop (5) from 0 to 9 (exlusive)
a[i][j]+= // Sum the item at that location with:
k!=4? // If `k` is not 4 (the current item itself)
a[i+k/3-1][j+k%3-1]
// Sum it with the numbers surrounding it
: // Else:
0; // Leave it the same by adding 0
// End of inner loop (5) (implicit / single-line body)
// End of inner loop (4) (implicit / single-line body)
// End of loop (3) (implicit / single-line body)
return r; // Return the result-String
} // End of method
#Java 8, (削除) 262 (削除ここまで) 260 bytes
v->{int a[][]=new int[7][7],i=7,j,k;for(;i-->0;)for(j=7;j-->0;)a[i][j]=(int)(Math.random()*9+1);String r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")if(i%2+j%2>1)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}
v->{ // Method with empty unused parameter and String return-type
int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
i=7,j,k; // Index integers (`i` starting at 7)
for(;i-->0;) // Loop (1) from 6 down to 0 (inclusive)
for(j=7;j-->0;) // Inner loop (2) from 6 down to 0 (inclusive)
a[i][j]=(int)(Math.random()*9+1);
// Fill the current cell with a random 1-9 integer
// End of inner loop (2) (implicit / single-line body)
// End of loop (1) (implicit / single-line body)
String r=""; // Result-String
for(;++i<7; // Loop (3) from 0 to 7 (exclusive)
r+="\n") // After every iteration: append a new-line to the result
for(j=0;j<7; // Inner loop (4) from 0 to 7 (exclusive)
r+= // After every iteration: append the result-String with:
(k=a[i][j])>9 // If the current number has 2 digits,
|j++%2<1? // or it's an even column (indexes 0/2/4/6)
k+" " // Append the current number + one space
: // Else:
k+" ") // Append the current number + two spaces
if(i%2+j%2>1) // If both indexes `i` and `j` are odd
for(a[i][j]=k=0; // Reset both the current item and index `k` to 0
k<9;k++) // Inner loop (5) from 0 to 9 (exlusive)
a[i][j]+= // Sum the item at that location with:
k!=4? // If `k` is not 4 (the current item itself)
a[i+k/3-1][j+k%3-1]
// Sum it with the numbers surrounding it
: // Else:
0; // Leave it the same by adding 0
// End of inner loop (5) (implicit / single-line body)
// End of inner loop (4) (implicit / single-line body)
// End of loop (3) (implicit / single-line body)
return r; // Return the result-String
} // End of method