Produce n n-squares of integers with rotating *'s in consecuitive corners
Dyalog APL, 57 bytes
Requires ⎕IO←0
which is default on many systems.
Assuming double-spacing is permitted, as per the OP's first example.
{A←⊃∘⍕¨?10⍴⍨3⍴⍵⋄A[(⍳⍵),¨⍵⍴2↑¨1⍵(⍵ ⍵)(1⍵)-1]←'*'⋄⍉⎕FMT A}
TryAPL online!
Non-competing 49-byte solution (Dyalog APL 16.0):
{⍉⎕FMT'*'@((⍳⍵),¨⍵⍴2↑¨1⍵(⍵ ⍵)(1⍵)-1)⊃∘⍕¨?10⍴⍨3⍴⍵}
05AB1E, 50 49 bytes
3mF9Ý.R}J¹ô¹ävy`¦'*ìN4%©>ir}®iRr}®<iR})ˆ}¯øvyðý}»
Explanation
Examples for input = 4.
First we create a string of input^3 random numbers between 0 and 9.
3mF9Ý.R}J
producing
6799762549425893341317984133999075245812305412010122884262903656
Then we split that into pieces each the size of the input.
That is further split into input pieces.
¹ô¹ä
This gives us a matrix of numbers.
[['6799', '7625', '4942', '5893'],
['3413', '1798', '4133', '9990'],
['7524', '5812', '3054', '1201'],
['0122', '8842', '6290', '3656']]
We then loop over the rows of the matrix, inserting asterisks in the right places.
v } # for each row in matrix
y` # flatten list to stack
¦'*ì # replace the first digit of the last number with "*"
N4%©>ir} # if row-nr % 4 == 0, move the number with "*" to the front
®iRr} # if row-nr % 4 == 1, move the number with "*" to the front
# and reverse the number, moving "*" to the numbers right side
®<iR} # if row-nr % 4 == 2, reverse the number, moving "*"
# to the numbers right side
)ˆ # wrap row in a list and add to global array
Now we have the matrix with a "*" on each row, but we want an asterisk per column.
[['*893', '4942', '7625', '6799'],
['099*', '4133', '1798', '3413'],
['7524', '5812', '3054', '102*'],
['0122', '8842', '6290', '*656']]
So we zip this list turning rows into columns and vice versa.
[['*893', '099*', '7524', '0122'],
['4942', '4133', '5812', '8842'],
['7625', '1798', '3054', '6290'],
['6799', '3413', '102*', '*656']]
All that's left now is to format the output.
vyðý}»
Joining the rows on spaces and the columns on newlines gives us the final result.
*893 099* 7524 0122
4942 4133 5812 8842
7625 1798 3054 6290
6799 3413 102* *656
Try it online!
Old 50 byte solution
F¹Fõ¹F9Ý.R«}}¦'*ì})¹ävyN4%©>iR}®iíÁ}®<ií}})øvyðý}»
Java 7, 372 370 366 bytes
String c(int i){String s="*",a[][]=new String[i][i],t,r="";int j=0,k,z=i-1,m=(int)Math.pow(10,z);for(;j<i;j++)for(k=0;k<i;a[j][k++]=(new java.util.Random().nextInt((int)Math.pow(10,i)-m+1)+m)+"");for(j=0;j<i;k=j%4,t=a[m=k<2?0:z][k],a[m][j++]=k<1|k>2?s+t.substring(1,i):t.substring(0,z)+s);for(j=0;j<i;j++,r+="\n")for(k=0;k<i;r+=a[j][k++]+" ");return i<1?"":i<2?s:r;}
Can probably be golfed some more by placing the asterisks and creating the output at the same time, instead of one by one.
Ungolfed & test code:
Try it here.
class M{
static String c(int i){
String s = "*",
a[][] = new String[i][i],
t,
r = "";
int j = 0,
k,
z = i-1,
m = (int)Math.pow(10, z);
for(; j < i; j++){
for(k = 0; k < i; a[j][k++] = (new java.util.Random().nextInt((int)Math.pow(10, i) - m + 1) + m)+"");
}
for(j = 0; j < i; k = j % 4,
t = a[m = k < 2 ? 0 : z][k],
a[m][j++] = k < 1 | k > 2
? s + t.substring(1, i)
: t.substring(0, z) + s);
for(j = 0; j < i; j++,
r += "\n"){
for(k = 0; k < i; r += a[j][k++] + " ");
}
return i < 1
? ""
: i < 2
? s
: r;
}
public static void main(String[] a){
for (int i = 0; i < 6; i++) {
System.out.println(c(i));
System.out.println();
}
}
}
Possible output:
(empty)
*
*9 4*
92 47
*25 55* 754
910 197 108
635 439 35*
*512 407* 9646 5017
1663 3847 9772 3149
7796 2997 5494 1362
7283 9720 242* *539
*0726 7743* 52096 50958 *0726
60322 20914 76387 92716 41579
89994 18781 33379 84189 31777
11781 89323 12180 51814 63536
58411 32935 5168* *6597 43216