Skip to main content
added 466 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 288 281 267 257 225225 214 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-3141 bytes thanks to user2390246 for reconfiguring the weights, and golfing down the indexing, and some more usual R tips

function(n){m=matrix(sample(el(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]]),n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=(n+1)K=n/22+.5
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-(x=!(L-K)%%3&L-1&L-n)&t(x)])}
m[K,K]=" "
m}

Try it online!Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

L=col(m) is a matrix indicating the column number of each element in the matrix. Hence we compute !(L-K)%%3 to get the possible columns (including the edges), i.e., those a multiple of 3 away from the center column. To remove the edges, we consider L-1 and L-n. L-1 is 0 (false) for the first column and L-n is 0 for the last column. Applying & (element-wise boolean AND) to these three yields a matrix with TRUE in those columns a multiple of three away from the center, excluding the edges. We store this result as x.

If we take the transpose of x, t(x), we get the same matrix, but for the rows, hence x&t(x) is a matrix we save as i containing: TRUE indices for the required cells, and FALSE everywhere else.

Then we use chartr to perform the required transformation on m[i] and save the result as m[i], change the center cell to a space, and return the matrix.

Importantly as user2390246 pointed out, we don't need to test n>=9 because for n<7, there aren't any cells a multiple of 3 away from the center (apart from the center which is changed to a space anyway), and for n==7, the only cells a multiple of 3 from the center are on the edge so they are excluded. Neat!

R, 288 281 267 257 225 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-31 bytes thanks to user2390246 for reconfiguring the weights, and golfing down the indexing

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-(x=!(L-K)%%3&L-1&L-n)&t(x)])}
m[K,K]=" "
m}

Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

L=col(m) is a matrix indicating the column number of each element in the matrix. Hence we compute !(L-K)%%3 to get the possible columns (including the edges), i.e., those a multiple of 3 away from the center column. To remove the edges, we consider L-1 and L-n. L-1 is 0 (false) for the first column and L-n is 0 for the last column. Applying & (element-wise boolean AND) to these three yields a matrix with TRUE in those columns a multiple of three away from the center, excluding the edges. We store this result as x.

If we take the transpose of x, t(x), we get the same matrix, but for the rows, hence x&t(x) is a matrix we save as i containing: TRUE indices for the required cells, and FALSE everywhere else.

Then we use chartr to perform the required transformation on m[i] and save the result as m[i], change the center cell to a space, and return the matrix.

R, 288 281 267 257 225 214 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-41 bytes thanks to user2390246 for reconfiguring the weights, golfing down the indexing, and some more usual R tips

function(n){m=matrix(sample(el(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")),n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=n/2+.5
L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-(x=!(L-K)%%3&L-1&L-n)&t(x)])
m[K,K]=" "
m}

Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

L=col(m) is a matrix indicating the column number of each element in the matrix. Hence we compute !(L-K)%%3 to get the possible columns (including the edges), i.e., those a multiple of 3 away from the center column. To remove the edges, we consider L-1 and L-n. L-1 is 0 (false) for the first column and L-n is 0 for the last column. Applying & (element-wise boolean AND) to these three yields a matrix with TRUE in those columns a multiple of three away from the center, excluding the edges. We store this result as x.

If we take the transpose of x, t(x), we get the same matrix, but for the rows, hence x&t(x) is a matrix we save as i containing: TRUE indices for the required cells, and FALSE everywhere else.

Then we use chartr to perform the required transformation on m[i] and save the result as m[i], change the center cell to a space, and return the matrix.

Importantly as user2390246 pointed out, we don't need to test n>=9 because for n<7, there aren't any cells a multiple of 3 away from the center (apart from the center which is changed to a space anyway), and for n==7, the only cells a multiple of 3 from the center are on the edge so they are excluded. Neat!

added 351 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 288 281 267 257 246225 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-1031 bytes thanks to user2390246 for reconfiguring the weights, and golfing down the indexing

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-!((x=!(L-K)%%3)|t(x)|L%in%c(1,%%3&L-1&L-n)|t(L)%in%c&t(1,n)x)])}
m[K,K]=" "
m}

Try it online!Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

computes the indices of theL=col(m) is a matrix whereindicating the row and column distances from the center are both multiplesnumber of 3 and not oneach element in the edgematrix. Hence we compute !(L-K)%%3 to get the possible columns (iincluding the edges), i.e., notthose a multiple of 3 away from the center column. To remove the edges, we consider L-1 orand L-n. L-1 is 0 (false), lowercases those, replaces for the first column and ?L-n withis !0, replaces for the centerlast column. Applying & (element-wise boolean AND) to these three yields a matrix with " "TRUE in those columns a multiple of three away from the center, and returnsexcluding the matrixedges. We store this result as x.

There's actually an R packageIf we take the transpose of x, ScrabbleScore that has Scrabble letter frequencies. Howevert(x), due towe get the way it's storedsame matrix, it's onlybut for the rows, hence x&t(x) is a 13 byte improvementmatrix we save as i containing: TRUE indices for the required cells, so it's not worth itand FALSE everywhere else. It is

Then we use chartr to perform the required transformation on m[i] and save the result as m[i], howeverchange the center cell to a space, probably helpful for Beatnik golfingand return the matrix.

R, 288 281 267 257 246 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-10 bytes thanks to user2390246 for reconfiguring the weights

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-!((x=(L-K)%%3)|t(x)|L%in%c(1,n)|t(L)%in%c(1,n))])}
m[K,K]=" "
m}

Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

computes the indices of the matrix where the row and column distances from the center are both multiples of 3 and not on the edge (i.e., not 1 or n), lowercases those, replaces ? with !, replaces the center with " ", and returns the matrix.

There's actually an R package, ScrabbleScore that has Scrabble letter frequencies. However, due to the way it's stored, it's only a 13 byte improvement, so it's not worth it. It is, however, probably helpful for Beatnik golfing.

R, 288 281 267 257 225 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-31 bytes thanks to user2390246 for reconfiguring the weights, and golfing down the indexing

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-(x=!(L-K)%%3&L-1&L-n)&t(x)])}
m[K,K]=" "
m}

Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

L=col(m) is a matrix indicating the column number of each element in the matrix. Hence we compute !(L-K)%%3 to get the possible columns (including the edges), i.e., those a multiple of 3 away from the center column. To remove the edges, we consider L-1 and L-n. L-1 is 0 (false) for the first column and L-n is 0 for the last column. Applying & (element-wise boolean AND) to these three yields a matrix with TRUE in those columns a multiple of three away from the center, excluding the edges. We store this result as x.

If we take the transpose of x, t(x), we get the same matrix, but for the rows, hence x&t(x) is a matrix we save as i containing: TRUE indices for the required cells, and FALSE everywhere else.

Then we use chartr to perform the required transformation on m[i] and save the result as m[i], change the center cell to a space, and return the matrix.

deleted 2 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105

R, 288 281 267 257 247246 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-10 bytes thanks to user2390246 for reconfiguring the weights

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),n,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-!((x=(L-K)%%3)|t(x)|L%in%c(1,n)|t(L)%in%c(1,n))])}
m[K,K]=" "
m}

Try it online!Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

computes the indices of the matrix where the row and column distances from the center are both multiples of 3 and not on the edge (i.e., not 1 or n), lowercases those, replaces ? with !, replaces the center with " ", and returns the matrix.

There's actually an R package, ScrabbleScore that has Scrabble letter frequencies. However, due to the way it's stored, it's only a 13 byte improvement, so it's not worth it. It is, however, probably helpful for Beatnik golfing.

R, 288 281 267 257 247 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-10 bytes thanks to user2390246 for reconfiguring the weights

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),n,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-!((x=(L-K)%%3)|t(x)|L%in%c(1,n)|t(L)%in%c(1,n))])}
m[K,K]=" "
m}

Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

computes the indices of the matrix where the row and column distances from the center are both multiples of 3 and not on the edge (i.e., not 1 or n), lowercases those, replaces ? with !, replaces the center with " ", and returns the matrix.

There's actually an R package, ScrabbleScore that has Scrabble letter frequencies. However, due to the way it's stored, it's only a 13 byte improvement, so it's not worth it. It is, however, probably helpful for Beatnik golfing.

R, 288 281 267 257 246 bytes

thanks to @cole for -1 byte, reordering the ? to collapse the 2 into rep(2,10)

-10 bytes realizing that row(m) == t(col(m))

-10 bytes thanks to user2390246 for reconfiguring the weights

function(n){m=matrix(sample(strsplit("EOAINRTLSUDGBCMPFHVW?YKJXQZ","")[[1]],n^2,T,rep(c(12,8,9,6,4:1),c(1,1:4,1,10,5))),,n)
K=(n+1)/2
if(n>8){L=col(m)
m[i]=chartr("A-Z?","a-z!",m[i<-!((x=(L-K)%%3)|t(x)|L%in%c(1,n)|t(L)%in%c(1,n))])}
m[K,K]=" "
m}

Try it online!

Returns a matrix. Fairly simple implementation; samples n^2 values with the proper distribution, stores as an nxn matrix.

K is the index of the center.

computes the indices of the matrix where the row and column distances from the center are both multiples of 3 and not on the edge (i.e., not 1 or n), lowercases those, replaces ? with !, replaces the center with " ", and returns the matrix.

There's actually an R package, ScrabbleScore that has Scrabble letter frequencies. However, due to the way it's stored, it's only a 13 byte improvement, so it's not worth it. It is, however, probably helpful for Beatnik golfing.

added 68 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading
added 309 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading
added 60 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading
added 76 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading
deleted 2 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading
Post Undeleted by Giuseppe
added 104 characters in body
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading
Post Deleted by Giuseppe
Source Link
Giuseppe
  • 28.8k
  • 3
  • 31
  • 105
Loading