#AHK, 208 bytes
AHK, 208 bytes
AutoTrim,Off
w=%1%
b=%2%
f:=Mod(b,w)
Loop,%w%
s=%s%---
s=|%s%|`n
If (f>0) {
Loop,%f%
t=%t%|X|
Loop,% w-f
t=%t% ` ` `
t=|%t%|`n
t:=s t t t s
}
Loop,%w%
r=%r%|X|
r=|%r%|`n
Loop,% (b-f)/w
t:=t s r r r s
Send,%t%
There are a few things frustating me from golfing further:
- AutoHotkey doesn't have a built-in repeat function
- You can't directly use the passed in arguments (
%1%
&%2%
) in math functions because those expect variable or number input and it will assume the unescaped1
to be the number one rather than the variable name - I am not very good at golfing
An easier to read version of the above looks like this:
AutoTrim,Off
w=%1%
b=%2%
f:=Mod(b,w)
Loop,%w%
s=%s%---
s=|%s%|`n
If (f>0) {
Loop,%f%
t=%t%|X|
Loop,% w-f
t=%t% ` ` `
t=|%t%|`n
t:=s t t t s
}
Loop,%w%
r=%r%|X|
r=|%r%|`n
Loop,% (b-f)/w
t:=t s r r r s
Send,%t%
If a Loop
doesn't use brackets {}
, then only the next line is part of the loop. If setting a variable's value using :=
instead of =
, you can drop the percent sign escape characters. Tilde n is the newline character.