Challenge
Display to the screen or write to stdout this exactly:
**
**
****
****
****
****
****
****
****
**********
**********
**********
Winning
This is code-golf, so the shortest submission (in bytes) wins.
Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It only takes a minute to sign up.
Sign up to join this communityDisplay to the screen or write to stdout this exactly:
**
**
****
****
****
****
****
****
****
**********
**********
**********
This is code-golf, so the shortest submission (in bytes) wins.
for n in b"":print(f"{'**'*n:^10}")
Yawn, bytestrings. I got close with a few other approaches:
48 bytes
for n in[2]*2+[4]*7+[10]*3:print(f"{'*'*n:^10}")
48 bytes
for n in[1]*2+[2]*7+[5]*3:print(-n%5*' '+'**'*n)
This code is 46 bytes in Python 2 where print
doesn't need parens. Thanks to dingledooper for -1 byte with -n%5
.
49 bytes
print(" **\n"*2+" ****\n"*7+('*'*10+'\n')*3)
50 bytes
n=15
while n-3:print(f"{(5>>n//7)*'**':^10}");n-=1
for c in b'':print(f"{'**'*c:^10}")
:P (if the unprintables would format correctly)
\$\endgroup\$
Nov 14 at 21:13
1. CP-1610 instructions are encoded with 10-bit values (0x000 to 0x3FF), known as DECLEs. Although the Intellivision is also able to work on 16-bit, programs were really stored in 10-bit ROM back then.
A full program in 10-bit ROM format, mapped at $4800. This includes an initialization of the video chip so that the display is correct.
ROMW 10 ; use 10-bit ROM
ORG $4800 ; map our program at $4800
4800 0002 EIS ; enable interrupts
4801 0001 SDBD ; R4 = data pointer
4802 02BC 002B 0048 MVII #data, R4
4805 02BD 0200 MVII #$200, R5 ; R5 = BACKTAB pointer
4807 02A0 loop MVI@ R4, R0 ; load data word into R0
4808 0080 TSTR R0 ; if it's zero ...
4809 0204 001A BEQ done ; ... exit
480B 0081 MOVR R0, R1 ; copy R0 to R1
480C 03B9 0007 ANDI #7, R1 ; isolate the 3 least significant bits
480E 0275 line PSHR R5 ; save R5 on the stack
480F 0082 MOVR R0, R2 ; copy R0 to R2
4810 0066 SLR R2, 2 ; right-shift R2 by 3 positions
4811 0062 SLR R2
4812 03BA 0007 ANDI #7, R2 ; isolate the 3 least significant bits
4814 00D5 ADDR R2, R5 ; add that to R5
4815 0083 MOVR R0, R3 ; copy R0 to R3
4816 02BA 0057 MVII #$0057, R2 ; load the value of a white '*' in R2
4818 026A char MVO@ R2, R5 ; write the character
4819 033B 0040 SUBI #$40, R3 ; subtract 64 from R3
481B 0223 0004 BPL char ; keep drawing while it's positive
481D 02B5 PULR R5 ; restore R5
481E 02FD 0014 ADDI #20, R5 ; advance to the next line
4820 0011 DECR R1 ; decrement R1
4821 022C 0014 BNEQ line ; draw another line if it's not zero
4823 0220 001D B loop ; or process the next value
4825 02BD 0030 done MVII #$30, R5 ; R5 = pointer into STIC registers
4827 0268 MVO@ R0, R5 ; no horizontal delay
4828 0268 MVO@ R0, R5 ; no vertical delay
4829 0268 MVO@ R0, R5 ; no border extension
482A 0017 spin DECR R7 ; loop forever
482B 0062 data DECLE $062 ; data format: WWWWPPPNNN
482C 00DF DECLE $0DF ; W = width - 1
482D 0243 DECLE $243 ; P = left padding
482E 0000 DECLE 0 ; N = number of lines
made with jzIntv
unlines[(' '<$['1'..a])++("**"<*[a..'9'])|a<-"998888888555"]
-9 bytes thanks to Unrelated String
-9 byte thanks to ovs
Uses the range syntax [a..'9'] to do substraction.
do
block to bind ('\n':)
only ties! In any case you can go down to 79 with init$unlines
instead--or drop the init
, since OP's own "canonical" answer has a trailing newline too.
\$\endgroup\$
Nov 15 at 1:50
unlines
. Thanks!
\$\endgroup\$
Nov 15 at 8:38
unlines[...|a<-[9,9,8,8,...]]
. Then using <$
and <*
instead of replicate can save a few more, which also allows switching from a list of integers to a string
\$\endgroup\$
<$
, I have to add any parentheses to fix operator precedence with ++
.
\$\endgroup\$
Nov 15 at 19:35
Quite straight forward, with some optimisations:
*
p
flag for saving one bytes/ /**/4
to simply replace one space by two *
h;H;G
to produce three identical liness/^/ ** /p;p
s/ /**/4p;h;H;G;p;p
s/ /*/g
repeat 2 <<<' **'
repeat 7 <<<' ****'
repeat 3 <<<**********
It's pretty basic, clever tricks like left-padding l:expr::string1:
didn't help.
/a/**//s/ a//w/
aaaaa//b/
sa/ s
sbbbbbbbwww
-1 byte thanks to @Philippos
»ƛ⁼c»yøḊ×v*øm
Bitstring:
0000111111001110001100010001100001000110001001001010100111011011101111010100110110101111000100100
Explanation:
»ƛ⁼c»yøḊ×v*øm
»ƛ⁼c» Decompresses integer => 122753
yøḊ Interleave, Run-length decoding => [1,1,2,2,2,2,2,2,2,5,5,5]
×v* Map repeat asterisk n times
øm Palindromise, center and join by newlines
The more trivial answer »ɽβ≬ǓG»f×v*øm
has a higher vyncode score (probably because the compressed part is longer).
↑E333ac×*⍘ιφ‖C
Try it online! Link is to verbose version of code. Explanation:
↑E333ac×*⍘ιφ
Output the first five columns of the figure, whose heights are the hexadecimal digits 333ac
, starting at the bottom working up.
‖C
Make a mirror copy to complete the figure.
-5 thanks to @l4m2
for(n of"443333333000")print("".padEnd(n).padEnd(10-n,"*"))
2_4··♂∙]⌂*♂Ωn
Explanation:
2 # Push 2
_ # Duplicate it
4 # Push 4
·· # Quadruplicate it twice
♂ # Push 10
∙ # Triplicate it
] # Wrap all values on the stack into a list: [2,2,4,4,4,4,4,4,4,10,10,10]
⌂* # Convert each to strings with that many "*"
♂Ω # Centralize the strings to length 10
n # Join the list of padded strings by newlines
# (after which the entire stack is output implicitly as result)
*=$c000
ldy #23
lda #32
w ldx data,y
q jsr $ffd2
dex
bpl q
eor #10
dey
bpl w
rts
data
!byte 9,29,9,29,9,32,3,35,3,35,3,35,3,35,3,35,3,35,3,36,1,37,1,3
print(''.join(map(lambda a,c:f"{'*'*a:^10}\n"*c,(2,4,10),(2,7,3))))
removed parentheses around fstring thanks to @corvus_192
explode"112222222555"|rep(" ",5-x)..rep("**",x)
Relatively self explanatory, explodes the string 112222222555
into a list of single characters, each of which represents half the width of the building as it goes down. Then, maps over that list, replacing each entry with a string of 5-x
spaces, and 2*x
asterisks, which effectively rebuilds it.
NOTE: This code assumes that x
is already displayed. To see the full *STDOUT* as it is, you should drag the list to the full screen.
Direct solution. Had to add some spaces so it would align up nicely because when Scratch displays lists, line numbers are displayed and modify the position of their corresponding item.
Alternatively, 0 bytes
define
delete[all v]of[x v
add[ **]to[x v
add[ **]to[x v
repeat(7
add[ ****]to[x v
end
repeat(3
add[**********]to[x v
19 bytes saved thanks to Jonah. 2 bytes more by switching from index origin 1 to 0
'* '[2 7 3⌿⊃(⊂10⍴2)⊤¨975 903 0]
Try it online! Thanks to Dyalog Classic
Original code:
m←12 5⍴' '⋄((∊10 35 15⍴¨(⊂5⍴2)⊤¨1 3 31)/,m)←'#'⋄m,⌽m
'* '[1+2 7 3⌿↑(2⊥⍣¯1¨975 903 0)]
. Perhaps you can convert it to a fn / improve it?
\$\endgroup\$
0reada,b,c:s=1:on-(a<.)goto2:forx=1toc:ifsthen?spc(a);:s=.
1fory=1tob:?"**";:next:?:s=1:next:goto
2data4,1,2,3,2,7,0,5,3,-1,,
Here it is in action:
I will add a better explanation later, but for those who maybe are unfamiliar with Commodore BASIC, here is a more readable listing of broadly the same outcome that I made in order to work out the logic before I minimised and crunched the BASIC listing into the three lines in this entry:
foreach(var x in "443333333000")Console.WriteLine("".PadRight(x-48).PadRight(58-x,'*'));
Edit: @corvus_192 pointed out that using 48 instead of '0' would save a few chars. Thanks!
Implementation of Arnauld's JS version: https://codegolf.stackexchange.com/a/266751/120291
'0'
is 48 in ascii, so you can use "".PadRight(x-48).PadRight(58-x,'*')
\$\endgroup\$
Nov 15 at 19:46
>-[-[-<]>>+<]>->>--[<+>++++++]<->++++++++++>++[-<<<....>..>.>]+++++++[-<<<...>....>.>]+++[-<<..........>.>]
4,4,(,3*7),0,0,0|%{$_}|%{""|% *ht($_-'0')|% *ht(10-($_-'0'))'*'}
# PowerShell, 85 bytes
foreach($n in 4,4,3,3,3,3,3,3,3,0,0,0){"".PadRight($n-'0').PadRight(10-($n-'0'),'*')}
# PowerShell, 64 bytes
foreach($n in $c){"".PadRight($n-'0').PadRight(10-($n-'0'),'*')}
Thanks to @lost_in_a_musical_note's answer for laying the groundwork!
$c
in your byte count, e.g. Try it online!
\$\endgroup\$
00079){3+`**}rT{.]i.};
00079){3+`**}rT{.]i.};
00079) # A Stack of the numbers 0, 0, 0, 7, 9 (Each 3 less than the height of half the columns)
{ }r # Replace each number with
3+ # +3
`** # Multiply by "*" (Which repeats "*" x times)
T # Transpose
{ }; # For each row
.] # Concatenate back into a string and duplicate
i. # Inverse the duplicate and concatenate, palindromizing
# Implicit output the contents of the stack.
'* '{~2 7 3#:@#975,903,0:
This just encodes the full rows as binary numbers, then duplicates them according to the 2 7 3 frequency. This results in a 12 by 10 binary matrix, which is converted to ascii.
I didn't find a way to exploit the symmetry in a way that beats this.
(,.~|."1)'*'#~"+2 7 3#1 2 5
\$\endgroup\$
Nov 21 at 1:10
42¶423333333111
3
¶34
1
¶010
(.)(.+)
$1$* $2$**
Try it online! Explanation:
42¶4233333111
Start with the encoding for the first two lines plus an encoded encoding for the remaining lines.
3
¶34
1
¶010
Decode the encoding for the remaining lines. All lines are now singly encoded.
(.)(.+)
$1$* $2$**
Decode the encoding for each line (first digit is number of spaces, other digit(s) is number of asterisks).
2Dx7.DTÐ)'*×.c
Explanation:
2 # Push 2
# Stack: 2
D # Duplicate it
# Stack: 2,2
x # Double it (without popping)
# Stack: 2,2,4
7 # Push 7
# Stack: 2,2,4,7
.D # Duplicate the 4 7 times
# Stack: 2,2,4,4,4,4,4,4,4
T # Push 10
# Stack: 2,2,4,4,4,4,4,4,4,10
Ð # Triplicate it
# Stack: 2,2,4,4,4,4,4,4,4,10,10,10
) # Wrap everything on the stack into a list
# Stack: [2,2,4,4,4,4,4,4,4,10,10,10]
'*× '# Convert each to a string of that many "*"
# Stack: ["**","**","****","****",...,"**********"]
.c # Join by newlines and pad leading spaces to centralize the lines
# Stack: " **\n **\n ****\n...\n**********"
# (after which the result is output implicitly)
Count i while i-132 {
Write 32+10*0^((i%11*2-9)^2/(((i/11+5)/7)^2*20+2))-i%11/10*22
}
Let's start with this 99-byte version:
Count r while r-12 {
Count c while c-10 {
Write 32+10*0^((c*2-9)^2/(((r+5)/7)^2*20+2))
}
Write 10
}
We have a straightforward nested loop over 12 rows r
and 10 columns c
, with a newline written at the end of each row. The math to determine space or asterisk runs as follows:
We want to transform the column numbers such that inner columns map to a smaller value than outer columns; then, for each row, we can apply a cutoff so the inner columns become one character and the outer columns become a different character. Acc!! doesn't have an absolute value operator, so we'll use squaring. To preserve symmetry, we double the column number and subtract an odd constant: (c*2-9)^2
c c*2-9 (c*2-9)^2
0 -9 81
1 -7 49
2 -5 25
3 -3 9
4 -1 1
5 1 1
6 3 9
9 9 81
The column cutoff is also dependent on the row number:
First, we shift and int-divide the row numbers to quantize them into the correct chunks:
r (r+5)/7
0-1 0
2-8 1
9-11 2
Now a linear function doesn't put the cutoffs in the right range, but a quadratic function does:
(r+5)/7 ((r+5)/7)^2*20+2
0 2
1 22
2 82
Next, we need to check whether the modified column value is greater than or less than the cutoff. We can do this using int division. But that results in different non-zero values, which isn't good for the ASCII-code math we're going to do. We can convert them to 0 and 1 by exploiting the fact that 0^0 = 1 and 0^x = 0 for any positive x in Acc!!.
col cutoff col/cutoff 0^(col/cutoff)
1 2 0 1
9 2 4 0
25 2 12 0
1 22 0 1
9 22 0 1
25 22 1 0
1 82 0 1
9 82 0 1
25 82 0 1
We then multiply that quantity by 10 and add 32, turning 0 into 32 (space) and 1 into 42 (asterisk), and write out the appropriate character.
To get from the 99-byte version to the 85-byte version, we first move the newline-printing into the nested loop. We add an 11th column, which according to the existing math would always be a space (ASCII 32); then we subtract 22 if the column index is >= 10, turning that space into a newline (ASCII 10).
... while c-11 {
Write ... - c/10*22
Now we can combine the two loops into a single loop whose index i
runs from 0 to 131. The row number r
is simply i/11
, and the column number c
is i%11
.
=let(c,"**",n,"**
",e," "&n,f," "&c&n,g,c&c&c&c&n,e&e&rept(f,7)&g&g&g)
Put the formula in cell A1
. It uses simple string concatenation. The whole output is displayed in that one cell.
The text string in n
is two asterisks followed by a newline. A literal newline can be specified this way in Google Sheets, saving nine bytes over "&char(10)&"
.
Structured version (80 bytes):
=map({2;7;3},{4;3;0},{2;4;10},lambda(n,s,a,rept(rept(" ",s)&rept("*",a)&"
",n)))
The output is shown in A1:A3
, with newlines in cells. The text string between &"
and ",n"
is a newline.
," **"*2
," ****"*7
,("*"*10)*3
," **"*2 # Creates an array (" **", " **") print it on stdout
," ****"*7 # Same as above
,("*"*10)*3 # Builds and string of 10 stars, then same as above
0 DATA4,2,2,3,4,7,,10,3:READA,B,C:FORJ=1TOC:PRINTTAB(A):FORI=1TOB:PRINT"*";:NEXT:PRINT:NEXT:GOTO
In C64 must be typed in with abbreviations.