Print a physical multiplication table
$begingroup$
Rectangles have this nice property - an $n times m$ rectangle consists of exactly $n times m$ characters!
A.. more interesting property is that the rectangles can be aligned nicely in a multiplication table - for example, a $3 times 3$ table:
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
Your challenge is to, given a number $n$ ($ n > 1$), output a formatted $n times n$ multiplication table.
Rules
- You can take the input one above or below $n$
- Default I/O rules apply
- You can choose any non-whitespace character to represent the blocks; every other character (though newlines are special) is considered whitespace. The chosen character can be different for different inputs, but must be the same throughout the input
- The result can have unneeded characters, as long as the table aligns up and there are no occurrences of the chosen character that aren't part of the required output
- The separators must be 1 character wide/tall, and the rectangles must be packed (i.e. no separators between their characters)
- The empty lines can be empty, padding isn't required
- The result can be a string, matrix, vector of lines, array of character arrays, or anything 2Dish
- You may alternatively output a matrix/vector-of-vectors/anything 2Dish of numbers, but the background & foreground must be 2 distinct numbers (which can vary input to input, but not throughout an output) and no other numbers can be present. Extra surrounding characters are allowed with this format too (though they must match the background number)
- This is code-golf, shortest answer in bytes, per-language, wins!
Examples
For the input 2
, a valid ascii-art output, with the character ∙
, is:
∙ ∙∙
Result: ∙ ∙∙.
∙ ∙∙
yes the period is there just to confuse you
Another valid answer as a number matrix, with 2 being the background number and 9 the foreground:
[[9,2,9,9,2,2],
[2,2,2,2,2,2],
[9,2,9,9,2,2],
[9,2,9,9,2,2]]
An invalid output example would be
# # #
# # #
# # #
as the rectangles have separators in between them.
Example outputs for $4 times 4$:
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
code-golf ascii-art array-manipulation
$endgroup$
add a comment |
$begingroup$
Rectangles have this nice property - an $n times m$ rectangle consists of exactly $n times m$ characters!
A.. more interesting property is that the rectangles can be aligned nicely in a multiplication table - for example, a $3 times 3$ table:
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
Your challenge is to, given a number $n$ ($ n > 1$), output a formatted $n times n$ multiplication table.
Rules
- You can take the input one above or below $n$
- Default I/O rules apply
- You can choose any non-whitespace character to represent the blocks; every other character (though newlines are special) is considered whitespace. The chosen character can be different for different inputs, but must be the same throughout the input
- The result can have unneeded characters, as long as the table aligns up and there are no occurrences of the chosen character that aren't part of the required output
- The separators must be 1 character wide/tall, and the rectangles must be packed (i.e. no separators between their characters)
- The empty lines can be empty, padding isn't required
- The result can be a string, matrix, vector of lines, array of character arrays, or anything 2Dish
- You may alternatively output a matrix/vector-of-vectors/anything 2Dish of numbers, but the background & foreground must be 2 distinct numbers (which can vary input to input, but not throughout an output) and no other numbers can be present. Extra surrounding characters are allowed with this format too (though they must match the background number)
- This is code-golf, shortest answer in bytes, per-language, wins!
Examples
For the input 2
, a valid ascii-art output, with the character ∙
, is:
∙ ∙∙
Result: ∙ ∙∙.
∙ ∙∙
yes the period is there just to confuse you
Another valid answer as a number matrix, with 2 being the background number and 9 the foreground:
[[9,2,9,9,2,2],
[2,2,2,2,2,2],
[9,2,9,9,2,2],
[9,2,9,9,2,2]]
An invalid output example would be
# # #
# # #
# # #
as the rectangles have separators in between them.
Example outputs for $4 times 4$:
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
code-golf ascii-art array-manipulation
$endgroup$
$begingroup$
Can we have extra row/columns of background characters in front, rather than at the end of the table?
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
@KirillL. sure, as long as the rows line up
$endgroup$
– dzaima
12 hours ago
add a comment |
$begingroup$
Rectangles have this nice property - an $n times m$ rectangle consists of exactly $n times m$ characters!
A.. more interesting property is that the rectangles can be aligned nicely in a multiplication table - for example, a $3 times 3$ table:
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
Your challenge is to, given a number $n$ ($ n > 1$), output a formatted $n times n$ multiplication table.
Rules
- You can take the input one above or below $n$
- Default I/O rules apply
- You can choose any non-whitespace character to represent the blocks; every other character (though newlines are special) is considered whitespace. The chosen character can be different for different inputs, but must be the same throughout the input
- The result can have unneeded characters, as long as the table aligns up and there are no occurrences of the chosen character that aren't part of the required output
- The separators must be 1 character wide/tall, and the rectangles must be packed (i.e. no separators between their characters)
- The empty lines can be empty, padding isn't required
- The result can be a string, matrix, vector of lines, array of character arrays, or anything 2Dish
- You may alternatively output a matrix/vector-of-vectors/anything 2Dish of numbers, but the background & foreground must be 2 distinct numbers (which can vary input to input, but not throughout an output) and no other numbers can be present. Extra surrounding characters are allowed with this format too (though they must match the background number)
- This is code-golf, shortest answer in bytes, per-language, wins!
Examples
For the input 2
, a valid ascii-art output, with the character ∙
, is:
∙ ∙∙
Result: ∙ ∙∙.
∙ ∙∙
yes the period is there just to confuse you
Another valid answer as a number matrix, with 2 being the background number and 9 the foreground:
[[9,2,9,9,2,2],
[2,2,2,2,2,2],
[9,2,9,9,2,2],
[9,2,9,9,2,2]]
An invalid output example would be
# # #
# # #
# # #
as the rectangles have separators in between them.
Example outputs for $4 times 4$:
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
code-golf ascii-art array-manipulation
$endgroup$
Rectangles have this nice property - an $n times m$ rectangle consists of exactly $n times m$ characters!
A.. more interesting property is that the rectangles can be aligned nicely in a multiplication table - for example, a $3 times 3$ table:
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
# ## ###
Your challenge is to, given a number $n$ ($ n > 1$), output a formatted $n times n$ multiplication table.
Rules
- You can take the input one above or below $n$
- Default I/O rules apply
- You can choose any non-whitespace character to represent the blocks; every other character (though newlines are special) is considered whitespace. The chosen character can be different for different inputs, but must be the same throughout the input
- The result can have unneeded characters, as long as the table aligns up and there are no occurrences of the chosen character that aren't part of the required output
- The separators must be 1 character wide/tall, and the rectangles must be packed (i.e. no separators between their characters)
- The empty lines can be empty, padding isn't required
- The result can be a string, matrix, vector of lines, array of character arrays, or anything 2Dish
- You may alternatively output a matrix/vector-of-vectors/anything 2Dish of numbers, but the background & foreground must be 2 distinct numbers (which can vary input to input, but not throughout an output) and no other numbers can be present. Extra surrounding characters are allowed with this format too (though they must match the background number)
- This is code-golf, shortest answer in bytes, per-language, wins!
Examples
For the input 2
, a valid ascii-art output, with the character ∙
, is:
∙ ∙∙
Result: ∙ ∙∙.
∙ ∙∙
yes the period is there just to confuse you
Another valid answer as a number matrix, with 2 being the background number and 9 the foreground:
[[9,2,9,9,2,2],
[2,2,2,2,2,2],
[9,2,9,9,2,2],
[9,2,9,9,2,2]]
An invalid output example would be
# # #
# # #
# # #
as the rectangles have separators in between them.
Example outputs for $4 times 4$:
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
# ## ### ####
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
1 0 1 1 0 1 1 1 0 1 1 1 1
code-golf ascii-art array-manipulation
code-golf ascii-art array-manipulation
edited 11 hours ago
dzaima
asked 14 hours ago
dzaimadzaima
15.5k21857
15.5k21857
$begingroup$
Can we have extra row/columns of background characters in front, rather than at the end of the table?
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
@KirillL. sure, as long as the rows line up
$endgroup$
– dzaima
12 hours ago
add a comment |
$begingroup$
Can we have extra row/columns of background characters in front, rather than at the end of the table?
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
@KirillL. sure, as long as the rows line up
$endgroup$
– dzaima
12 hours ago
$begingroup$
Can we have extra row/columns of background characters in front, rather than at the end of the table?
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Can we have extra row/columns of background characters in front, rather than at the end of the table?
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
@KirillL. sure, as long as the rows line up
$endgroup$
– dzaima
12 hours ago
$begingroup$
@KirillL. sure, as long as the rows line up
$endgroup$
– dzaima
12 hours ago
add a comment |
15 Answers
15
active
oldest
votes
$begingroup$
R, 56 54 43 36 30 bytes
x=!!sequence(2:scan())-1;x%o%x
Try it online!
Takes input one above $n$ (so returns 3x3 matrix for $n = 4$).
Returns a matrix of $1s$ (foreground), and $0s$ (background) with an extra row/column of zeroes in front.
Thanks to digEmAll for -7 bytes.
$endgroup$
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
add a comment |
$begingroup$
MATL, 14 10 bytes
:"@:Fv]g&*
This answer uses 1
for the blocks and 0
for the background
Try it at MATL Online
Explanation
% Implicitly grab the input as an integer, N
% STACK: { 3 }
: % Create an array from 1...N
% STACK: { [1, 2, 3] }
" % For each element M in this array
@: % Create an array from 1...M
% STACK (for 1st iteration): { [1] }
% STACK (for 2nd iteration): { [1; 0], [1, 2] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3] }
F % Push a zero to the stack
% STACK (for 1st iteration): { [1], 0 }
% STACK (for 2nd iteration): { [1; 0], [1, 2], 0 }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3], 0 }
v % Vertically concatenate everything on the stack
% STACK (for 1st iteration): { [1; 0] }
% STACK (for 2nd iteration): { [1; 0; 1; 2; 0] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0; 1; 2; 3; 0] }
]
g % Convert everything to be boolean (turns all non-zeros to 1)
% STACK: { [1; 0; 1; 1; 0; 1; 1; 1; 0] }
&* % Perform element-wise multiplication to expand this array out into the 2D grid
% Implicitly display the result
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1ẋⱮj0ȧþ`
Try it online!
$endgroup$
add a comment |
$begingroup$
Haskell, 49 bytes
f n=map=<<flip(map.max)$[0^i|x<-[1..n],i<-[0..x]]
Try it online!
Generates a pattern like [1,0,1,0,0,1,0,0,0,...]
, then makes a 2D by taking the min
of pairs. The pointfree weirdness saves 2 bytes over the more readable:
f n|l<-do x<-[1..n];0:(1<$[1..x])=[[a*b|a<-l]|b<-l]
Try it online!
$endgroup$
1
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 73 72 69 bytes
Returns a string made of 1's, spaces and line feeds.
n=>(g=s=>n-->0?g(s+`${p+=1} `):s[~n]?(+s[~n]?s:'')+`
`+g(s):'')(p='')
Try it online!
JavaScript (ES7), 87 83 82 bytes
Saved 3 bytes thanks to @dzaima
Returns a binary matrix, which is built cell by cell.
n=>[...Array(n*(n+3)/2)].map((_,y,a)=>a.map(h=(z,x)=>(17+8*x)**.5%1&&(z||h(1,y))))
Try it online!
How?
The width $w$ of the matrix is given by:
$$w=T_n+n-1={n+1choose 2}+n-1=frac{n(n + 3)}{2}-1$$
(NB: As allowed by the challenge rules, we output a matrix of width $w+1$ instead.)
Similarly, the cell located at $(X,Y)$ is empty if the following quadratic admits an integer root for either $k=X$ or $k=Y$:
$$frac{x(x+3)}{2}-1-k=0\
x^2+3x-2-2k=0
$$
whose determinant is:
$$Delta=9-4(-2-2k)=17+8k$$
$endgroup$
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
add a comment |
$begingroup$
APL (Dyalog Unicode), 12 10 12 bytesSBCS
∘.×⍨∊,,⎕⍴1
Try it online!
Edit: -2 bytes from ngn. +2 bytes because the previous answers were invalid (with idea thanks to ngn and dzaima).
Explanation
∘.×⍨∊,,⎕⍴1
⎕ Take input.
⍴1 An array of 1s of length our input. Example: 1 1 1
0, Prepend a 0. Example: 0 1 1 1
, Take all the prefixes and concatenate them. Example: 0 0 1 0 1 1 0 1 1 1
∊ Flatten the list. Example: 0 0 1 0 1 1 0 1 1 1
∘.×⍨ Turn the above list into a multiplication table of 0s and 1s
by multiplying the list with itself.
The output should look like:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
$endgroup$
1
$begingroup$
you could take input as⎕
to avoid the{
}
$endgroup$
– ngn
10 hours ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 41 bytes
a#&/@(a=Flatten@Array[{0,1~Table~#}&,#])&
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 67 bytes
s='';n=input()
while n:s='#'*n+' '+s;n-=1
for c in s:print(c>' ')*s
Try it online!
Prints blank lines for empty lines, which the challenge allows.
Same length (with input one above n
):
r=range(input())
for n in r:print(' '.join(i*'#'for i in r)+'n')*n
Try it online!
$endgroup$
add a comment |
$begingroup$
J, 17 bytes
[:*/~2=/[:I.2+i.
Try it online!
$endgroup$
$begingroup$
did not know about thisI.
trick!
$endgroup$
– Jonah
2 hours ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
add a comment |
$begingroup$
Haskell, 69 68 bytes
(a#b)0=
(a#b)n=(a#b)(n-1)++b:(a<$[1..n])
f n=((1#0)n#(0<$(1#0)n))n
Returns a matrix of numbers.
Try it online!
Variants of f
with the same byte count:
f n=((#)<*>(0<$)$(1#0)n)n
f n|l<-(1#0)n=(l#(0<$l))n
$endgroup$
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
1
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
add a comment |
$begingroup$
APL+WIN, 29 bytes
m/⍉(m←¯1↓∊(⍳n),¨¯1)/(n,n←⎕)⍴1
Explanation:
(n,n←⎕)⍴1 prompt for integer n and create a nxn matrix of 1s
(m←¯1↓∊(⍳n) replicate the columns by 1,2,.....n and insert 0s between each replication
m/⍉ repeat replication and 0 insertion for the rows from above
Example:
⎕:
3
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
$endgroup$
add a comment |
$begingroup$
Jelly, 7 bytes
‘RÄṬ|þ`
Try it online!
Outputs a digit matrix, using $0$ for the rectangles and $1$ for the padding between them. The TIO link contains a footer which formats a digit matrix in a human-readable way by lining up the rows and columns.
Explanation
‘RÄṬ|þ`
R Take a range from 1 to
‘ {the input} plus 1
Ä Cumulative sum; produces the first {input}+1 triangular numbers
Ṭ Produce an array with 1s at those indexes, 0s at other indexes
þ Create a table of {the array}
` with itself
| using bitwise OR
The number at cell $(x,y)$ of the resulting table will be $1$ if either $x$ or $y$ is a triangular number, or $0$ otherwise (because bitwise OR works like logical OR on 0 and 1). (We use R
, range from 1, because Jelly uses 1-based indexing, so we don't have to worry about column 0 being incorrectly full of 0s; we have to add 1 to the input because the array produced by Ṭ
stops at the largest element given in the input, so we need to draw a line on the right-hand side and the bottom.) The gaps between triangular numbers are the consecutive integers, so the rectangular blocks formed by the gaps between the lines end up as the sizes requested by the question; and the use of an OR operation (in this case, bitwise) allows the lines to cross each other correctly.
$endgroup$
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
add a comment |
$begingroup$
Charcoal, 18 bytes
≔⪫EN×#⊕ι θEθ⭆θ⌊⟦ιλ
Try it online! Link is to verbose version of code. Explanation:
N Input number
E Map over implicit range
ι Current value
⊕ Incremented
× Repetitions of
# Literal `#`
⪫ Join with spaces
≔ θ Assign to variable
θ Retrieve variable
E Map over characters
θ Retrieve variable
⭆ Replace characters with
⌊ Minimum of
⟦ List of
ι Row character
λ Column character
Implicitly print each row on its own line
$endgroup$
add a comment |
$begingroup$
Perl 6, 35 bytes
{[~](("
"~[~] *xx$_)xx$_)>>.say}
Try it online!
Anonymous code block that takes a number and prints the multiplication table with *
s and a leading newline.
$endgroup$
add a comment |
$begingroup$
Mouse-2002, 79 bytes
Abusing Mouse's macros to repeat functionality.
?1+n:#P,n,j,k,b#P,j,y,k,#P,n,i,' ,#P,i,x,35;;;;$P0 2%:(1%.2%.-^4%3%!'2%.1+2%:)@
Try it online!
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181582%2fprint-a-physical-multiplication-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
R, 56 54 43 36 30 bytes
x=!!sequence(2:scan())-1;x%o%x
Try it online!
Takes input one above $n$ (so returns 3x3 matrix for $n = 4$).
Returns a matrix of $1s$ (foreground), and $0s$ (background) with an extra row/column of zeroes in front.
Thanks to digEmAll for -7 bytes.
$endgroup$
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
add a comment |
$begingroup$
R, 56 54 43 36 30 bytes
x=!!sequence(2:scan())-1;x%o%x
Try it online!
Takes input one above $n$ (so returns 3x3 matrix for $n = 4$).
Returns a matrix of $1s$ (foreground), and $0s$ (background) with an extra row/column of zeroes in front.
Thanks to digEmAll for -7 bytes.
$endgroup$
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
add a comment |
$begingroup$
R, 56 54 43 36 30 bytes
x=!!sequence(2:scan())-1;x%o%x
Try it online!
Takes input one above $n$ (so returns 3x3 matrix for $n = 4$).
Returns a matrix of $1s$ (foreground), and $0s$ (background) with an extra row/column of zeroes in front.
Thanks to digEmAll for -7 bytes.
$endgroup$
R, 56 54 43 36 30 bytes
x=!!sequence(2:scan())-1;x%o%x
Try it online!
Takes input one above $n$ (so returns 3x3 matrix for $n = 4$).
Returns a matrix of $1s$ (foreground), and $0s$ (background) with an extra row/column of zeroes in front.
Thanks to digEmAll for -7 bytes.
edited 12 hours ago
answered 12 hours ago
Kirill L.Kirill L.
5,4731525
5,4731525
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
add a comment |
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
36 bytes using sequence (if I'm not missing something)
$endgroup$
– digEmAll
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Thanks, BTW it can probably even be 30, if the extra blank row can be in front, rather than at the end.
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
$begingroup$
Oh, can they? I missed that !
$endgroup$
– digEmAll
11 hours ago
add a comment |
$begingroup$
MATL, 14 10 bytes
:"@:Fv]g&*
This answer uses 1
for the blocks and 0
for the background
Try it at MATL Online
Explanation
% Implicitly grab the input as an integer, N
% STACK: { 3 }
: % Create an array from 1...N
% STACK: { [1, 2, 3] }
" % For each element M in this array
@: % Create an array from 1...M
% STACK (for 1st iteration): { [1] }
% STACK (for 2nd iteration): { [1; 0], [1, 2] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3] }
F % Push a zero to the stack
% STACK (for 1st iteration): { [1], 0 }
% STACK (for 2nd iteration): { [1; 0], [1, 2], 0 }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3], 0 }
v % Vertically concatenate everything on the stack
% STACK (for 1st iteration): { [1; 0] }
% STACK (for 2nd iteration): { [1; 0; 1; 2; 0] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0; 1; 2; 3; 0] }
]
g % Convert everything to be boolean (turns all non-zeros to 1)
% STACK: { [1; 0; 1; 1; 0; 1; 1; 1; 0] }
&* % Perform element-wise multiplication to expand this array out into the 2D grid
% Implicitly display the result
$endgroup$
add a comment |
$begingroup$
MATL, 14 10 bytes
:"@:Fv]g&*
This answer uses 1
for the blocks and 0
for the background
Try it at MATL Online
Explanation
% Implicitly grab the input as an integer, N
% STACK: { 3 }
: % Create an array from 1...N
% STACK: { [1, 2, 3] }
" % For each element M in this array
@: % Create an array from 1...M
% STACK (for 1st iteration): { [1] }
% STACK (for 2nd iteration): { [1; 0], [1, 2] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3] }
F % Push a zero to the stack
% STACK (for 1st iteration): { [1], 0 }
% STACK (for 2nd iteration): { [1; 0], [1, 2], 0 }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3], 0 }
v % Vertically concatenate everything on the stack
% STACK (for 1st iteration): { [1; 0] }
% STACK (for 2nd iteration): { [1; 0; 1; 2; 0] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0; 1; 2; 3; 0] }
]
g % Convert everything to be boolean (turns all non-zeros to 1)
% STACK: { [1; 0; 1; 1; 0; 1; 1; 1; 0] }
&* % Perform element-wise multiplication to expand this array out into the 2D grid
% Implicitly display the result
$endgroup$
add a comment |
$begingroup$
MATL, 14 10 bytes
:"@:Fv]g&*
This answer uses 1
for the blocks and 0
for the background
Try it at MATL Online
Explanation
% Implicitly grab the input as an integer, N
% STACK: { 3 }
: % Create an array from 1...N
% STACK: { [1, 2, 3] }
" % For each element M in this array
@: % Create an array from 1...M
% STACK (for 1st iteration): { [1] }
% STACK (for 2nd iteration): { [1; 0], [1, 2] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3] }
F % Push a zero to the stack
% STACK (for 1st iteration): { [1], 0 }
% STACK (for 2nd iteration): { [1; 0], [1, 2], 0 }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3], 0 }
v % Vertically concatenate everything on the stack
% STACK (for 1st iteration): { [1; 0] }
% STACK (for 2nd iteration): { [1; 0; 1; 2; 0] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0; 1; 2; 3; 0] }
]
g % Convert everything to be boolean (turns all non-zeros to 1)
% STACK: { [1; 0; 1; 1; 0; 1; 1; 1; 0] }
&* % Perform element-wise multiplication to expand this array out into the 2D grid
% Implicitly display the result
$endgroup$
MATL, 14 10 bytes
:"@:Fv]g&*
This answer uses 1
for the blocks and 0
for the background
Try it at MATL Online
Explanation
% Implicitly grab the input as an integer, N
% STACK: { 3 }
: % Create an array from 1...N
% STACK: { [1, 2, 3] }
" % For each element M in this array
@: % Create an array from 1...M
% STACK (for 1st iteration): { [1] }
% STACK (for 2nd iteration): { [1; 0], [1, 2] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3] }
F % Push a zero to the stack
% STACK (for 1st iteration): { [1], 0 }
% STACK (for 2nd iteration): { [1; 0], [1, 2], 0 }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0], [1, 2, 3], 0 }
v % Vertically concatenate everything on the stack
% STACK (for 1st iteration): { [1; 0] }
% STACK (for 2nd iteration): { [1; 0; 1; 2; 0] }
% STACK (for 3rd iteration): { [1; 0; 1; 2; 0; 1; 2; 3; 0] }
]
g % Convert everything to be boolean (turns all non-zeros to 1)
% STACK: { [1; 0; 1; 1; 0; 1; 1; 1; 0] }
&* % Perform element-wise multiplication to expand this array out into the 2D grid
% Implicitly display the result
edited 11 hours ago
answered 13 hours ago
SueverSuever
9,7721446
9,7721446
add a comment |
add a comment |
$begingroup$
Jelly, 8 bytes
1ẋⱮj0ȧþ`
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1ẋⱮj0ȧþ`
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 8 bytes
1ẋⱮj0ȧþ`
Try it online!
$endgroup$
Jelly, 8 bytes
1ẋⱮj0ȧþ`
Try it online!
answered 14 hours ago
Erik the OutgolferErik the Outgolfer
32.5k429105
32.5k429105
add a comment |
add a comment |
$begingroup$
Haskell, 49 bytes
f n=map=<<flip(map.max)$[0^i|x<-[1..n],i<-[0..x]]
Try it online!
Generates a pattern like [1,0,1,0,0,1,0,0,0,...]
, then makes a 2D by taking the min
of pairs. The pointfree weirdness saves 2 bytes over the more readable:
f n|l<-do x<-[1..n];0:(1<$[1..x])=[[a*b|a<-l]|b<-l]
Try it online!
$endgroup$
1
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
add a comment |
$begingroup$
Haskell, 49 bytes
f n=map=<<flip(map.max)$[0^i|x<-[1..n],i<-[0..x]]
Try it online!
Generates a pattern like [1,0,1,0,0,1,0,0,0,...]
, then makes a 2D by taking the min
of pairs. The pointfree weirdness saves 2 bytes over the more readable:
f n|l<-do x<-[1..n];0:(1<$[1..x])=[[a*b|a<-l]|b<-l]
Try it online!
$endgroup$
1
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
add a comment |
$begingroup$
Haskell, 49 bytes
f n=map=<<flip(map.max)$[0^i|x<-[1..n],i<-[0..x]]
Try it online!
Generates a pattern like [1,0,1,0,0,1,0,0,0,...]
, then makes a 2D by taking the min
of pairs. The pointfree weirdness saves 2 bytes over the more readable:
f n|l<-do x<-[1..n];0:(1<$[1..x])=[[a*b|a<-l]|b<-l]
Try it online!
$endgroup$
Haskell, 49 bytes
f n=map=<<flip(map.max)$[0^i|x<-[1..n],i<-[0..x]]
Try it online!
Generates a pattern like [1,0,1,0,0,1,0,0,0,...]
, then makes a 2D by taking the min
of pairs. The pointfree weirdness saves 2 bytes over the more readable:
f n|l<-do x<-[1..n];0:(1<$[1..x])=[[a*b|a<-l]|b<-l]
Try it online!
edited 11 hours ago
answered 11 hours ago
xnorxnor
92.3k18188446
92.3k18188446
1
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
add a comment |
1
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
1
1
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
$begingroup$
This can be shortened with my old triangular number trick: 43 bytes
$endgroup$
– Ørjan Johansen
5 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 73 72 69 bytes
Returns a string made of 1's, spaces and line feeds.
n=>(g=s=>n-->0?g(s+`${p+=1} `):s[~n]?(+s[~n]?s:'')+`
`+g(s):'')(p='')
Try it online!
JavaScript (ES7), 87 83 82 bytes
Saved 3 bytes thanks to @dzaima
Returns a binary matrix, which is built cell by cell.
n=>[...Array(n*(n+3)/2)].map((_,y,a)=>a.map(h=(z,x)=>(17+8*x)**.5%1&&(z||h(1,y))))
Try it online!
How?
The width $w$ of the matrix is given by:
$$w=T_n+n-1={n+1choose 2}+n-1=frac{n(n + 3)}{2}-1$$
(NB: As allowed by the challenge rules, we output a matrix of width $w+1$ instead.)
Similarly, the cell located at $(X,Y)$ is empty if the following quadratic admits an integer root for either $k=X$ or $k=Y$:
$$frac{x(x+3)}{2}-1-k=0\
x^2+3x-2-2k=0
$$
whose determinant is:
$$Delta=9-4(-2-2k)=17+8k$$
$endgroup$
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 73 72 69 bytes
Returns a string made of 1's, spaces and line feeds.
n=>(g=s=>n-->0?g(s+`${p+=1} `):s[~n]?(+s[~n]?s:'')+`
`+g(s):'')(p='')
Try it online!
JavaScript (ES7), 87 83 82 bytes
Saved 3 bytes thanks to @dzaima
Returns a binary matrix, which is built cell by cell.
n=>[...Array(n*(n+3)/2)].map((_,y,a)=>a.map(h=(z,x)=>(17+8*x)**.5%1&&(z||h(1,y))))
Try it online!
How?
The width $w$ of the matrix is given by:
$$w=T_n+n-1={n+1choose 2}+n-1=frac{n(n + 3)}{2}-1$$
(NB: As allowed by the challenge rules, we output a matrix of width $w+1$ instead.)
Similarly, the cell located at $(X,Y)$ is empty if the following quadratic admits an integer root for either $k=X$ or $k=Y$:
$$frac{x(x+3)}{2}-1-k=0\
x^2+3x-2-2k=0
$$
whose determinant is:
$$Delta=9-4(-2-2k)=17+8k$$
$endgroup$
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
add a comment |
$begingroup$
JavaScript (ES6), 73 72 69 bytes
Returns a string made of 1's, spaces and line feeds.
n=>(g=s=>n-->0?g(s+`${p+=1} `):s[~n]?(+s[~n]?s:'')+`
`+g(s):'')(p='')
Try it online!
JavaScript (ES7), 87 83 82 bytes
Saved 3 bytes thanks to @dzaima
Returns a binary matrix, which is built cell by cell.
n=>[...Array(n*(n+3)/2)].map((_,y,a)=>a.map(h=(z,x)=>(17+8*x)**.5%1&&(z||h(1,y))))
Try it online!
How?
The width $w$ of the matrix is given by:
$$w=T_n+n-1={n+1choose 2}+n-1=frac{n(n + 3)}{2}-1$$
(NB: As allowed by the challenge rules, we output a matrix of width $w+1$ instead.)
Similarly, the cell located at $(X,Y)$ is empty if the following quadratic admits an integer root for either $k=X$ or $k=Y$:
$$frac{x(x+3)}{2}-1-k=0\
x^2+3x-2-2k=0
$$
whose determinant is:
$$Delta=9-4(-2-2k)=17+8k$$
$endgroup$
JavaScript (ES6), 73 72 69 bytes
Returns a string made of 1's, spaces and line feeds.
n=>(g=s=>n-->0?g(s+`${p+=1} `):s[~n]?(+s[~n]?s:'')+`
`+g(s):'')(p='')
Try it online!
JavaScript (ES7), 87 83 82 bytes
Saved 3 bytes thanks to @dzaima
Returns a binary matrix, which is built cell by cell.
n=>[...Array(n*(n+3)/2)].map((_,y,a)=>a.map(h=(z,x)=>(17+8*x)**.5%1&&(z||h(1,y))))
Try it online!
How?
The width $w$ of the matrix is given by:
$$w=T_n+n-1={n+1choose 2}+n-1=frac{n(n + 3)}{2}-1$$
(NB: As allowed by the challenge rules, we output a matrix of width $w+1$ instead.)
Similarly, the cell located at $(X,Y)$ is empty if the following quadratic admits an integer root for either $k=X$ or $k=Y$:
$$frac{x(x+3)}{2}-1-k=0\
x^2+3x-2-2k=0
$$
whose determinant is:
$$Delta=9-4(-2-2k)=17+8k$$
edited 10 hours ago
answered 13 hours ago
ArnauldArnauld
78.8k795327
78.8k795327
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
add a comment |
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
$begingroup$
Not sure if it can save bytes, but the solution of that quadratic would be $frac{-3pmsqrt{17+8k}}2$, so there would be an integer root if $sqrtDelta$ is odd, that is, $Delta$ is an odd perfect square.
$endgroup$
– Erik the Outgolfer
9 hours ago
add a comment |
$begingroup$
APL (Dyalog Unicode), 12 10 12 bytesSBCS
∘.×⍨∊,,⎕⍴1
Try it online!
Edit: -2 bytes from ngn. +2 bytes because the previous answers were invalid (with idea thanks to ngn and dzaima).
Explanation
∘.×⍨∊,,⎕⍴1
⎕ Take input.
⍴1 An array of 1s of length our input. Example: 1 1 1
0, Prepend a 0. Example: 0 1 1 1
, Take all the prefixes and concatenate them. Example: 0 0 1 0 1 1 0 1 1 1
∊ Flatten the list. Example: 0 0 1 0 1 1 0 1 1 1
∘.×⍨ Turn the above list into a multiplication table of 0s and 1s
by multiplying the list with itself.
The output should look like:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
$endgroup$
1
$begingroup$
you could take input as⎕
to avoid the{
}
$endgroup$
– ngn
10 hours ago
add a comment |
$begingroup$
APL (Dyalog Unicode), 12 10 12 bytesSBCS
∘.×⍨∊,,⎕⍴1
Try it online!
Edit: -2 bytes from ngn. +2 bytes because the previous answers were invalid (with idea thanks to ngn and dzaima).
Explanation
∘.×⍨∊,,⎕⍴1
⎕ Take input.
⍴1 An array of 1s of length our input. Example: 1 1 1
0, Prepend a 0. Example: 0 1 1 1
, Take all the prefixes and concatenate them. Example: 0 0 1 0 1 1 0 1 1 1
∊ Flatten the list. Example: 0 0 1 0 1 1 0 1 1 1
∘.×⍨ Turn the above list into a multiplication table of 0s and 1s
by multiplying the list with itself.
The output should look like:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
$endgroup$
1
$begingroup$
you could take input as⎕
to avoid the{
}
$endgroup$
– ngn
10 hours ago
add a comment |
$begingroup$
APL (Dyalog Unicode), 12 10 12 bytesSBCS
∘.×⍨∊,,⎕⍴1
Try it online!
Edit: -2 bytes from ngn. +2 bytes because the previous answers were invalid (with idea thanks to ngn and dzaima).
Explanation
∘.×⍨∊,,⎕⍴1
⎕ Take input.
⍴1 An array of 1s of length our input. Example: 1 1 1
0, Prepend a 0. Example: 0 1 1 1
, Take all the prefixes and concatenate them. Example: 0 0 1 0 1 1 0 1 1 1
∊ Flatten the list. Example: 0 0 1 0 1 1 0 1 1 1
∘.×⍨ Turn the above list into a multiplication table of 0s and 1s
by multiplying the list with itself.
The output should look like:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
$endgroup$
APL (Dyalog Unicode), 12 10 12 bytesSBCS
∘.×⍨∊,,⎕⍴1
Try it online!
Edit: -2 bytes from ngn. +2 bytes because the previous answers were invalid (with idea thanks to ngn and dzaima).
Explanation
∘.×⍨∊,,⎕⍴1
⎕ Take input.
⍴1 An array of 1s of length our input. Example: 1 1 1
0, Prepend a 0. Example: 0 1 1 1
, Take all the prefixes and concatenate them. Example: 0 0 1 0 1 1 0 1 1 1
∊ Flatten the list. Example: 0 0 1 0 1 1 0 1 1 1
∘.×⍨ Turn the above list into a multiplication table of 0s and 1s
by multiplying the list with itself.
The output should look like:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
0 0 1 0 1 1 0 1 1 1
edited 9 hours ago
answered 10 hours ago
Sherlock9Sherlock9
8,06411860
8,06411860
1
$begingroup$
you could take input as⎕
to avoid the{
}
$endgroup$
– ngn
10 hours ago
add a comment |
1
$begingroup$
you could take input as⎕
to avoid the{
}
$endgroup$
– ngn
10 hours ago
1
1
$begingroup$
you could take input as
⎕
to avoid the {
}
$endgroup$
– ngn
10 hours ago
$begingroup$
you could take input as
⎕
to avoid the {
}
$endgroup$
– ngn
10 hours ago
add a comment |
$begingroup$
Wolfram Language (Mathematica), 41 bytes
a#&/@(a=Flatten@Array[{0,1~Table~#}&,#])&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 41 bytes
a#&/@(a=Flatten@Array[{0,1~Table~#}&,#])&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 41 bytes
a#&/@(a=Flatten@Array[{0,1~Table~#}&,#])&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 41 bytes
a#&/@(a=Flatten@Array[{0,1~Table~#}&,#])&
Try it online!
edited 7 hours ago
answered 9 hours ago
shrapshrap
913
913
add a comment |
add a comment |
$begingroup$
Python 2, 67 bytes
s='';n=input()
while n:s='#'*n+' '+s;n-=1
for c in s:print(c>' ')*s
Try it online!
Prints blank lines for empty lines, which the challenge allows.
Same length (with input one above n
):
r=range(input())
for n in r:print(' '.join(i*'#'for i in r)+'n')*n
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 67 bytes
s='';n=input()
while n:s='#'*n+' '+s;n-=1
for c in s:print(c>' ')*s
Try it online!
Prints blank lines for empty lines, which the challenge allows.
Same length (with input one above n
):
r=range(input())
for n in r:print(' '.join(i*'#'for i in r)+'n')*n
Try it online!
$endgroup$
add a comment |
$begingroup$
Python 2, 67 bytes
s='';n=input()
while n:s='#'*n+' '+s;n-=1
for c in s:print(c>' ')*s
Try it online!
Prints blank lines for empty lines, which the challenge allows.
Same length (with input one above n
):
r=range(input())
for n in r:print(' '.join(i*'#'for i in r)+'n')*n
Try it online!
$endgroup$
Python 2, 67 bytes
s='';n=input()
while n:s='#'*n+' '+s;n-=1
for c in s:print(c>' ')*s
Try it online!
Prints blank lines for empty lines, which the challenge allows.
Same length (with input one above n
):
r=range(input())
for n in r:print(' '.join(i*'#'for i in r)+'n')*n
Try it online!
answered 9 hours ago
xnorxnor
92.3k18188446
92.3k18188446
add a comment |
add a comment |
$begingroup$
J, 17 bytes
[:*/~2=/[:I.2+i.
Try it online!
$endgroup$
$begingroup$
did not know about thisI.
trick!
$endgroup$
– Jonah
2 hours ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
add a comment |
$begingroup$
J, 17 bytes
[:*/~2=/[:I.2+i.
Try it online!
$endgroup$
$begingroup$
did not know about thisI.
trick!
$endgroup$
– Jonah
2 hours ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
add a comment |
$begingroup$
J, 17 bytes
[:*/~2=/[:I.2+i.
Try it online!
$endgroup$
J, 17 bytes
[:*/~2=/[:I.2+i.
Try it online!
answered 9 hours ago
Galen IvanovGalen Ivanov
7,16211034
7,16211034
$begingroup$
did not know about thisI.
trick!
$endgroup$
– Jonah
2 hours ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
add a comment |
$begingroup$
did not know about thisI.
trick!
$endgroup$
– Jonah
2 hours ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
$begingroup$
did not know about this
I.
trick!$endgroup$
– Jonah
2 hours ago
$begingroup$
did not know about this
I.
trick!$endgroup$
– Jonah
2 hours ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
$begingroup$
@Jonah I was waiting for an opportunity to use it :)
$endgroup$
– Galen Ivanov
26 mins ago
add a comment |
$begingroup$
Haskell, 69 68 bytes
(a#b)0=
(a#b)n=(a#b)(n-1)++b:(a<$[1..n])
f n=((1#0)n#(0<$(1#0)n))n
Returns a matrix of numbers.
Try it online!
Variants of f
with the same byte count:
f n=((#)<*>(0<$)$(1#0)n)n
f n|l<-(1#0)n=(l#(0<$l))n
$endgroup$
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
1
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
add a comment |
$begingroup$
Haskell, 69 68 bytes
(a#b)0=
(a#b)n=(a#b)(n-1)++b:(a<$[1..n])
f n=((1#0)n#(0<$(1#0)n))n
Returns a matrix of numbers.
Try it online!
Variants of f
with the same byte count:
f n=((#)<*>(0<$)$(1#0)n)n
f n|l<-(1#0)n=(l#(0<$l))n
$endgroup$
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
1
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
add a comment |
$begingroup$
Haskell, 69 68 bytes
(a#b)0=
(a#b)n=(a#b)(n-1)++b:(a<$[1..n])
f n=((1#0)n#(0<$(1#0)n))n
Returns a matrix of numbers.
Try it online!
Variants of f
with the same byte count:
f n=((#)<*>(0<$)$(1#0)n)n
f n|l<-(1#0)n=(l#(0<$l))n
$endgroup$
Haskell, 69 68 bytes
(a#b)0=
(a#b)n=(a#b)(n-1)++b:(a<$[1..n])
f n=((1#0)n#(0<$(1#0)n))n
Returns a matrix of numbers.
Try it online!
Variants of f
with the same byte count:
f n=((#)<*>(0<$)$(1#0)n)n
f n|l<-(1#0)n=(l#(0<$l))n
edited 12 hours ago
answered 13 hours ago
niminimi
32.4k32389
32.4k32389
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
1
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
add a comment |
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
1
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
$begingroup$
Do the 0 row and column help?
$endgroup$
– dfeuer
7 hours ago
1
1
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
$begingroup$
@dfeuer: yes, they save a byte. See the first version of my answer.
$endgroup$
– nimi
6 hours ago
add a comment |
$begingroup$
APL+WIN, 29 bytes
m/⍉(m←¯1↓∊(⍳n),¨¯1)/(n,n←⎕)⍴1
Explanation:
(n,n←⎕)⍴1 prompt for integer n and create a nxn matrix of 1s
(m←¯1↓∊(⍳n) replicate the columns by 1,2,.....n and insert 0s between each replication
m/⍉ repeat replication and 0 insertion for the rows from above
Example:
⎕:
3
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
$endgroup$
add a comment |
$begingroup$
APL+WIN, 29 bytes
m/⍉(m←¯1↓∊(⍳n),¨¯1)/(n,n←⎕)⍴1
Explanation:
(n,n←⎕)⍴1 prompt for integer n and create a nxn matrix of 1s
(m←¯1↓∊(⍳n) replicate the columns by 1,2,.....n and insert 0s between each replication
m/⍉ repeat replication and 0 insertion for the rows from above
Example:
⎕:
3
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
$endgroup$
add a comment |
$begingroup$
APL+WIN, 29 bytes
m/⍉(m←¯1↓∊(⍳n),¨¯1)/(n,n←⎕)⍴1
Explanation:
(n,n←⎕)⍴1 prompt for integer n and create a nxn matrix of 1s
(m←¯1↓∊(⍳n) replicate the columns by 1,2,.....n and insert 0s between each replication
m/⍉ repeat replication and 0 insertion for the rows from above
Example:
⎕:
3
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
$endgroup$
APL+WIN, 29 bytes
m/⍉(m←¯1↓∊(⍳n),¨¯1)/(n,n←⎕)⍴1
Explanation:
(n,n←⎕)⍴1 prompt for integer n and create a nxn matrix of 1s
(m←¯1↓∊(⍳n) replicate the columns by 1,2,.....n and insert 0s between each replication
m/⍉ repeat replication and 0 insertion for the rows from above
Example:
⎕:
3
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
0 0 0 0 0 0 0 0
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
1 0 1 1 0 1 1 1
edited 12 hours ago
answered 13 hours ago
GrahamGraham
2,52678
2,52678
add a comment |
add a comment |
$begingroup$
Jelly, 7 bytes
‘RÄṬ|þ`
Try it online!
Outputs a digit matrix, using $0$ for the rectangles and $1$ for the padding between them. The TIO link contains a footer which formats a digit matrix in a human-readable way by lining up the rows and columns.
Explanation
‘RÄṬ|þ`
R Take a range from 1 to
‘ {the input} plus 1
Ä Cumulative sum; produces the first {input}+1 triangular numbers
Ṭ Produce an array with 1s at those indexes, 0s at other indexes
þ Create a table of {the array}
` with itself
| using bitwise OR
The number at cell $(x,y)$ of the resulting table will be $1$ if either $x$ or $y$ is a triangular number, or $0$ otherwise (because bitwise OR works like logical OR on 0 and 1). (We use R
, range from 1, because Jelly uses 1-based indexing, so we don't have to worry about column 0 being incorrectly full of 0s; we have to add 1 to the input because the array produced by Ṭ
stops at the largest element given in the input, so we need to draw a line on the right-hand side and the bottom.) The gaps between triangular numbers are the consecutive integers, so the rectangular blocks formed by the gaps between the lines end up as the sizes requested by the question; and the use of an OR operation (in this case, bitwise) allows the lines to cross each other correctly.
$endgroup$
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
add a comment |
$begingroup$
Jelly, 7 bytes
‘RÄṬ|þ`
Try it online!
Outputs a digit matrix, using $0$ for the rectangles and $1$ for the padding between them. The TIO link contains a footer which formats a digit matrix in a human-readable way by lining up the rows and columns.
Explanation
‘RÄṬ|þ`
R Take a range from 1 to
‘ {the input} plus 1
Ä Cumulative sum; produces the first {input}+1 triangular numbers
Ṭ Produce an array with 1s at those indexes, 0s at other indexes
þ Create a table of {the array}
` with itself
| using bitwise OR
The number at cell $(x,y)$ of the resulting table will be $1$ if either $x$ or $y$ is a triangular number, or $0$ otherwise (because bitwise OR works like logical OR on 0 and 1). (We use R
, range from 1, because Jelly uses 1-based indexing, so we don't have to worry about column 0 being incorrectly full of 0s; we have to add 1 to the input because the array produced by Ṭ
stops at the largest element given in the input, so we need to draw a line on the right-hand side and the bottom.) The gaps between triangular numbers are the consecutive integers, so the rectangular blocks formed by the gaps between the lines end up as the sizes requested by the question; and the use of an OR operation (in this case, bitwise) allows the lines to cross each other correctly.
$endgroup$
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
add a comment |
$begingroup$
Jelly, 7 bytes
‘RÄṬ|þ`
Try it online!
Outputs a digit matrix, using $0$ for the rectangles and $1$ for the padding between them. The TIO link contains a footer which formats a digit matrix in a human-readable way by lining up the rows and columns.
Explanation
‘RÄṬ|þ`
R Take a range from 1 to
‘ {the input} plus 1
Ä Cumulative sum; produces the first {input}+1 triangular numbers
Ṭ Produce an array with 1s at those indexes, 0s at other indexes
þ Create a table of {the array}
` with itself
| using bitwise OR
The number at cell $(x,y)$ of the resulting table will be $1$ if either $x$ or $y$ is a triangular number, or $0$ otherwise (because bitwise OR works like logical OR on 0 and 1). (We use R
, range from 1, because Jelly uses 1-based indexing, so we don't have to worry about column 0 being incorrectly full of 0s; we have to add 1 to the input because the array produced by Ṭ
stops at the largest element given in the input, so we need to draw a line on the right-hand side and the bottom.) The gaps between triangular numbers are the consecutive integers, so the rectangular blocks formed by the gaps between the lines end up as the sizes requested by the question; and the use of an OR operation (in this case, bitwise) allows the lines to cross each other correctly.
$endgroup$
Jelly, 7 bytes
‘RÄṬ|þ`
Try it online!
Outputs a digit matrix, using $0$ for the rectangles and $1$ for the padding between them. The TIO link contains a footer which formats a digit matrix in a human-readable way by lining up the rows and columns.
Explanation
‘RÄṬ|þ`
R Take a range from 1 to
‘ {the input} plus 1
Ä Cumulative sum; produces the first {input}+1 triangular numbers
Ṭ Produce an array with 1s at those indexes, 0s at other indexes
þ Create a table of {the array}
` with itself
| using bitwise OR
The number at cell $(x,y)$ of the resulting table will be $1$ if either $x$ or $y$ is a triangular number, or $0$ otherwise (because bitwise OR works like logical OR on 0 and 1). (We use R
, range from 1, because Jelly uses 1-based indexing, so we don't have to worry about column 0 being incorrectly full of 0s; we have to add 1 to the input because the array produced by Ṭ
stops at the largest element given in the input, so we need to draw a line on the right-hand side and the bottom.) The gaps between triangular numbers are the consecutive integers, so the rectangular blocks formed by the gaps between the lines end up as the sizes requested by the question; and the use of an OR operation (in this case, bitwise) allows the lines to cross each other correctly.
answered 7 hours ago
community wiki
ais523
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
add a comment |
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
Why is this a community wiki?! If you want to waive rep you could just give it to Erik the Outgolfer
$endgroup$
– Jonathan Allan
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
I CW all my answers (unless I think they might get a bounty, in which case I use a temporary account for them). Aiming for a high reputation normally means aiming to make the site worse (I once repcapped every day for a week to prove that it was possible; it wasn't particularly difficult, and yet it involved a lot of shallow questions/answers that didn't really contribute to the site much). Additionally, gaining reputation is mostly a negative on the account because it makes the site nag you into doing moderation work; and gaining privileges increases the risk of accidentally gaining badges.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
Also, I mostly disagree with the concept of ownership of posts on SE (although mostly with questions rather than answers, but you can't CW a question without moderator help). A CW marker very clearly says "if something is wrong here, feel free to edit it"; so I'd be applying a CW marker to everything even if it didn't waive reputation. SE is meant to be part wiki, after all, but people don't always use it as that.
$endgroup$
– ais523
6 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
RE "aiming for a high reputation" if you don't want that then just post when you think it is meaningful and avoid what you term "shallow" q&a. Either you feel this answer does add something to the site, in which case post it without CW, or you think it is "shallow", in which case just don't post it. RE "I mostly disagree with the concept of ownership of posts on SE" - well you're simply on the wrong site then.
$endgroup$
– Jonathan Allan
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
$begingroup$
I think the answer adds something to the site, but if it's not CW, I feel compelled to post in a way that would gain me reputation rather than posting what I think would be interesting; back when I was a 20k user, I ended up really hating the site and almost got turned away from code golf in general because of it, so I deleted my account as a result. When I returned, I used to delete my account with every answer I posted (creating a new one for the next answer), but someone else pointed out that CWing every answer would have a similar effect, so nowadays I do that instead.
$endgroup$
– ais523
5 hours ago
add a comment |
$begingroup$
Charcoal, 18 bytes
≔⪫EN×#⊕ι θEθ⭆θ⌊⟦ιλ
Try it online! Link is to verbose version of code. Explanation:
N Input number
E Map over implicit range
ι Current value
⊕ Incremented
× Repetitions of
# Literal `#`
⪫ Join with spaces
≔ θ Assign to variable
θ Retrieve variable
E Map over characters
θ Retrieve variable
⭆ Replace characters with
⌊ Minimum of
⟦ List of
ι Row character
λ Column character
Implicitly print each row on its own line
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
≔⪫EN×#⊕ι θEθ⭆θ⌊⟦ιλ
Try it online! Link is to verbose version of code. Explanation:
N Input number
E Map over implicit range
ι Current value
⊕ Incremented
× Repetitions of
# Literal `#`
⪫ Join with spaces
≔ θ Assign to variable
θ Retrieve variable
E Map over characters
θ Retrieve variable
⭆ Replace characters with
⌊ Minimum of
⟦ List of
ι Row character
λ Column character
Implicitly print each row on its own line
$endgroup$
add a comment |
$begingroup$
Charcoal, 18 bytes
≔⪫EN×#⊕ι θEθ⭆θ⌊⟦ιλ
Try it online! Link is to verbose version of code. Explanation:
N Input number
E Map over implicit range
ι Current value
⊕ Incremented
× Repetitions of
# Literal `#`
⪫ Join with spaces
≔ θ Assign to variable
θ Retrieve variable
E Map over characters
θ Retrieve variable
⭆ Replace characters with
⌊ Minimum of
⟦ List of
ι Row character
λ Column character
Implicitly print each row on its own line
$endgroup$
Charcoal, 18 bytes
≔⪫EN×#⊕ι θEθ⭆θ⌊⟦ιλ
Try it online! Link is to verbose version of code. Explanation:
N Input number
E Map over implicit range
ι Current value
⊕ Incremented
× Repetitions of
# Literal `#`
⪫ Join with spaces
≔ θ Assign to variable
θ Retrieve variable
E Map over characters
θ Retrieve variable
⭆ Replace characters with
⌊ Minimum of
⟦ List of
ι Row character
λ Column character
Implicitly print each row on its own line
answered 4 hours ago
NeilNeil
81.7k745178
81.7k745178
add a comment |
add a comment |
$begingroup$
Perl 6, 35 bytes
{[~](("
"~[~] *xx$_)xx$_)>>.say}
Try it online!
Anonymous code block that takes a number and prints the multiplication table with *
s and a leading newline.
$endgroup$
add a comment |
$begingroup$
Perl 6, 35 bytes
{[~](("
"~[~] *xx$_)xx$_)>>.say}
Try it online!
Anonymous code block that takes a number and prints the multiplication table with *
s and a leading newline.
$endgroup$
add a comment |
$begingroup$
Perl 6, 35 bytes
{[~](("
"~[~] *xx$_)xx$_)>>.say}
Try it online!
Anonymous code block that takes a number and prints the multiplication table with *
s and a leading newline.
$endgroup$
Perl 6, 35 bytes
{[~](("
"~[~] *xx$_)xx$_)>>.say}
Try it online!
Anonymous code block that takes a number and prints the multiplication table with *
s and a leading newline.
answered 3 hours ago
Jo KingJo King
24.9k359128
24.9k359128
add a comment |
add a comment |
$begingroup$
Mouse-2002, 79 bytes
Abusing Mouse's macros to repeat functionality.
?1+n:#P,n,j,k,b#P,j,y,k,#P,n,i,' ,#P,i,x,35;;;;$P0 2%:(1%.2%.-^4%3%!'2%.1+2%:)@
Try it online!
$endgroup$
add a comment |
$begingroup$
Mouse-2002, 79 bytes
Abusing Mouse's macros to repeat functionality.
?1+n:#P,n,j,k,b#P,j,y,k,#P,n,i,' ,#P,i,x,35;;;;$P0 2%:(1%.2%.-^4%3%!'2%.1+2%:)@
Try it online!
$endgroup$
add a comment |
$begingroup$
Mouse-2002, 79 bytes
Abusing Mouse's macros to repeat functionality.
?1+n:#P,n,j,k,b#P,j,y,k,#P,n,i,' ,#P,i,x,35;;;;$P0 2%:(1%.2%.-^4%3%!'2%.1+2%:)@
Try it online!
$endgroup$
Mouse-2002, 79 bytes
Abusing Mouse's macros to repeat functionality.
?1+n:#P,n,j,k,b#P,j,y,k,#P,n,i,' ,#P,i,x,35;;;;$P0 2%:(1%.2%.-^4%3%!'2%.1+2%:)@
Try it online!
answered 3 hours ago
MooseOnTheRocksMooseOnTheRocks
1714
1714
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f181582%2fprint-a-physical-multiplication-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Can we have extra row/columns of background characters in front, rather than at the end of the table?
$endgroup$
– Kirill L.
12 hours ago
$begingroup$
@KirillL. sure, as long as the rows line up
$endgroup$
– dzaima
12 hours ago