| Bytes | Lang | Time | Link |
|---|---|---|---|
| 062 | JavaScript ES6 | 250916T121817Z | Arnauld |
| 068 | AWK | 250917T062433Z | jared_ma |
| 056 | R | 250916T184408Z | Giuseppe |
| 063 | Perl 5 | 250917T150627Z | Xcali |
| 019 | Japt R | 250916T150838Z | Shaggy |
| 163 | brainfuck | 250917T133903Z | Level Ri |
| 033 | x8664 machine code | 250917T083647Z | m90 |
| 053 | Python 3 | 250917T023304Z | Albert.L |
| 060 | Ruby | 250916T200959Z | Level Ri |
| 088 | Maple | 250916T224946Z | dharr |
| 016 | Jelly | 250916T224936Z | Jonathan |
| 015 | Vyxal 3 | 250916T215239Z | pacman25 |
| 051 | Python 3 | 250916T193616Z | xnor |
| 052 | APL+WIN | 250916T154325Z | Graham |
| 018 | Vyxal 3 | 250916T112311Z | Themooni |
| 018 | 05AB1E | 250916T084944Z | Kevin Cr |
| 013 | Canvas | 250916T095845Z | Kevin Cr |
| 012 | Charcoal | 250916T090344Z | Neil |
JavaScript (ES6), 62 bytes
f=(n=98)=>n--?` +o
`[n%14?n-49?~153>>n/3.5%20&n&1:2:3]+f(n):""
Method
We use a counter \$n\$ going from \$97\$ at the top-left corner to \$0\$ at the bottom-right corner. Even values are converted to either a space or a linefeed and the central hole is located at \$n=49\$. Remaining odd values are shown in figure 1.
We apply a horizontal partition by computing \$\lfloor 2n/7\rfloor\$ (figure 2).
We reduce modulo \$20\$ to make the first two rows look like the last two ones (figure 3).
There are pegs everywhere except when the result is \$0\$, \$3\$, \$4\$ or \$7\$.
97 95 93 91 89 87 85 | 27 27 26 26 25 24 24 | 7 7 6 6 5 4 4
83 81 79 77 75 73 71 | 23 23 22 22 21 20 20 | 3 3 2 2 1 0 0
69 67 65 63 61 59 57 | 19 19 18 18 17 16 16 | 19 19 18 18 17 16 16
55 53 51 -- 47 45 43 | 15 15 14 -- 13 12 12 | 15 15 14 -- 13 12 12
41 39 37 35 33 31 29 | 11 11 10 10 9 8 8 | 11 11 10 10 9 8 8
27 25 23 21 19 17 15 | 7 7 6 6 5 4 4 | 7 7 6 6 5 4 4
13 11 9 7 5 3 1 | 3 3 2 2 1 0 0 | 3 3 2 2 1 0 0
Fig. 1 Fig. 2 Fig. 3
Commented
f = ( // f is a recursive function taking:
n = 98 // n = cell counter, starting at 98
) => //
n-- ? // if n is not 0 (decrement afterwards):
` +o\n`[ // lookup string
n % 14 ? // if this is not an end of row:
n - 49 ? // if this is not the central cell:
~153 // 32-bit mask: 11111111111111111111111101100110
// i.e. only bits #0, #3, #4 and #7 are zero
>> // right-shift
n / 3.5 // divide n by 7/2
// (the result is implicitly floored below)
% 20 // reduce modulo 20
& n // bitwise AND with n for the parity
& 1 // isolate the least significant bit
// -> this gives ' ' or '+'
: // else:
2 // use 'o'
: // else:
3 // use '\n'
] //
+ f(n) // append the result of a recursive call
: // else:
"" // stop
AWK, 71 68 bytes
BEGIN{a="***";for(;++i<8;)print(i<3||i>5?" "a" ":i~4?a"0"a:a"*"a)}
Removed some curly braces and used for(;++i<8;) instead of for(;i<7;i++). Could also use END instead of a BEGIN (-2 bytes; prints the output when the process is killed).
R, 58 56 bytes
d=matrix("X",7,7)
d[z<--3:-5,z]=" "
d[25]=0
write(d,1,7)
Construct the array iteratively and write. It's 2 bytes shorter to initialize the array with X and use negative indexing to assign spaces.
R, 64 60 bytes
write(c(" ","X",0)[1+outer(x<-abs(-3:3)<2,x,"|")+!24:0],1,7)
Construct indices (1,2,3) using row() and t() corresponding to " ","X", and 0, respectively. Abuses recycling to set the center as 0.
Japt -R, 21 20 19 bytes
[3,3FE]Ëìxio)¸êÃû ê
[3,3FE]Ësxio)¸êÃû ê
[ :Create an array containing
3,3 : Two copies of 3
F : 15
E : 14
] :End array
Ë :Map
ì : Convert to digit array in base
xio : "x" prepended with "o"
) : End base conversion
¸ : Join with spaces
ê : Palindromise
à :End map
û :Centre pad with spaces to length of longest
ê :Palidromise
:Implicit output joined with newlines
brainfuck, 163 bytes
Count excludes 8 newlines added for clarity.
+++++++++++[->+>++++>+++>++++>+++>++++<<<<<<]
>[->]
<<....>[.<]
>>>>>....>[.<]
>>[.>]<<.>.<.>[.<]
>>[.>]<<.>+++.---<.>[.<]
>>[.>]<<.>.<.>[.<]
>>>>>....>[.<]
>>>>>....>[.<]
We create 11,44,33,44,33,44 on the tape, then subtract 1 from each to give + + + with a newline at the lefthand end. For rows with 3 symbols we print some spaces then run through the tape right to left ending in newline. For rows with 7 symbols we run left to right, fiddle about to create the centre symbol, then run right to left ending in newline.
The code is quite repetitive so there is some opportunity for further golfing.
x86-64 machine code, 33 bytes
B2 71 B8 20 20 20 20 AB 6A 03 59 B0 58 66 F3 AB B0 0A AA B1 07 D0 EA 73 F2 75 E7 88 17 00 4F D2 C3
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI a memory address at which to place the result, as a null-terminated byte string. The chosen characters are X and _.
In assembly:
f: mov dl, 0b01110001 # Set DL to this value.
r0: mov eax, 0x20202020 # Set EAX to this value (4 spaces in ASCII).
stosd # Write it to the output string, advancing the pointer.
push 3; pop rcx # Set RCX to 3.
r1: mov al, 0x58 # Set the low byte of EAX to 'X' in ASCII.
rep stosw # Write the low two bytes of EAX to the output string,
# advancing the pointer, and repeating RCX times, counting RCX down to 0.
mov al, 0x0A # Set the low byte of EAX to a line feed in ASCII.
stosb # Write it to the output string, advancing the pointer.
mov cl, 7 # Set the low byte of RCX to 7, making RCX 7.
shr dl, 1 # Shift DL right by 1 bit. The low bit goes into CF.
jnc r1 # If that bit is 0, jump to make a middle row.
jnz r0 # If the shift result is nonzero, jump to make an outer row.
mov [rdi], dl # End the string with a 0 byte from DL.
add [rdi - 46], cl # Add CL (7) to the middle character: 'X' becomes '_'.
ret # Return.
Python 3, 53 bytes
a=" +o+ "
for x in a:print(*map({x:x}.get,a,7*"+"))
Another "clean" (no non printables) 53er.
Maple, 90 89 88 bytes
proc()M:=Matrix(7,fill=" ");M(15..35):="x";M[3..5,..]:="x";M(25):="o";printf("%s",M)end;
f:=proc()
M:=Matrix(7,fill=" ");
M(15..35):="x";
M[3..5,..]:="x";
M(25):="o";
printf("%s",M)
end;
The "%s" format automatically puts spaces between characters and inserts blank lines.
Jelly, 16 bytes
⁽doṃ⁾ x;0s4ŒBŒḄG
A full program printing to stdout.
How?
⁽doṃ⁾ x;0s4ŒBŒḄG - Main Link: no arguments
⁽do - 26112
ṃ⁾ x - cast to base 2 with 1 as " " and 0 as "x"
;0 - concatenate a zero
s4 - split into fours -> top-left
ŒB - bounce each row -> top half
ŒḄ - bounce -> whole board
G - format as a grid (add adjoining spaces and newline characters)
- implicit, smashing print
I do quite like the more mathsy, \$17\$ bytes - Try it online!:
2ŻŻŒB+þ`ƽị“xo ”G - Main Link
2 - two
Ż - zero-range -> [0,1,2]
Ż - prefix with a zero -> [0,0,1,2]
ŒB - bounce -> [0,0,1,2,1,0,0]
+þ` - table of addition -> [[0, 0, 1, 2, 1, 0, 0],
[0, 0, 1, 2, 1, 0, 0],
[1, 1, 2, 3, 2, 1, 1],
[2, 2, 3, 4, 3, 2, 2],
[1, 1, 2, 3, 2, 1, 1],
[0, 0, 1, 2, 1, 0, 0],
[0, 0, 1, 2, 1, 0, 0]]
ƽ - integer square-root (0->0; 1,2,3->1; 4->2)
ị“xo ” - 1-index, cyclically into "xo "
G - format as a grid (add adjoining spaces and newline characters)
- implicit, smashing print
...which is the same length as not using the integer square-root, with:
2ŻŻŒB+þ`ị“xxxo ”G
Vyxal 3, 15 bytes
"ᑂ∨⎘“BᏜx ip√7⧢'
binary encoding of the first half of the string, prepend to empty stack (0) and palindromized before splitting
Python 3, 51 bytes
for i in b"":print(*"_++++o "[i:i+4]+"+"*3)
The bytestring contains unprintable ASCII with codes [6,6,1,2,1,6,6]. Compare to the printable version that follows, except here the indices have been shifted up by 1 to avoid null bytes which must be escaped.
53 bytes
for i in b"5501055":print(*"++++o "[i%8:][:4]+"+"*3)
The idea is to encode each line as a substring of ++++o , specifically, one of ++++, +++o, or . Then, append +++, and print the result space separated. The indices give the start position of the substring, which is truncated to length 4.
APL+WIN 52 bytes
m←v⍪(3 13⍴13⍴'# ')⍪v←2 13⍴13↑¯9↑'# # #'⋄m[4;7]←'o'⋄m
Vyxal 3, 18 bytes
'x"6⊍æ“f×6«¨„”ٽ0≜
'x"6⊍æ“f×6«¨„”ٽ0≜
'x # single character 'x'
× # repeated
"6⊍æ“f # 3,3,9,9,9,3,3 times
6« # prepend spaces to each until length is >=6
¨„ # intersperse spaces in each
” # join on newlines
≜ # replace
ٽ # the middle character
0 # with 0
💎
Created with the help of Luminespire.
<script type="vyxal3">
'x"6⊍æ“f×6«¨„”ٽ0≜
</script>
<script>
args=[]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
05AB1E, 19 18 bytes
„ #D0JŽ∞,ÅΓ4ä€û».∊
Uses # as pegs and 0 as center hole.
Explanation:
„ # # Push string " #"
D # Duplicate it
0 # Push a 0
J # Join the stack together to a string: " # #0"
Ž∞, # Push compressed integer 22291
ÅΓ # Run-length decode, using this string and digits:
# [" "," ","#","#"," "," ","#","#","#","#","#","#","#","#","#","0"]
4ä # Split the list of characters into 4 equal-sized parts
€û # Palindromize each list
» # Join each inner list by spaces,
# and then each string by newlines
.∊ # Mirror it vertically with overlapping center row
# (after which the result is output implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ž∞, is 22291.
Canvas, 13 bytes
“Q╴gG"kj╶‟┼ *
Uses # for pegs and o as center hole.
The compressed string " ##¶ ##¶####¶###o" can likely be golfed by simply generating this string, but this will do for now.
Explanation:
“Q╴gG"kj╶‟ "# Compressed " ##¶ ##¶####¶###o"
┼ # Quad-palindromize with overlap
* # Add a space between each pair of characters
# (after which the result is output implicitly)
Charcoal, 16 12 bytes
E³XX‖O↘¬OUE¹
Try it online! Link is to verbose version of code. Uses X and O for the output characters. Explanation:
E³XX
Output a 2×3 rectangle of Xs.
‖O↘¬
Reflect diagonally downright, then separately down and left, to complete the remaining Xs.
O
Output the central O. (It saves a byte to do this here rather than elsewhere in the code.)
UE¹
Space out the pegboard horizontally.