22
\$\begingroup\$

Given the battery level L in the range 0-5, your code should draw the following ASCII art.

When L=0:

############
#          ###
#          ###
#          ###
############

When L=1:

############
###        ###
###        ###
###        ###
############

When L=2:

############
#####      ###
#####      ###
#####      ###
############

And etc. You can change the character # to any other (except space), it's up to you. Trailing spaces are allowed.

This is a code-golf challenge so the shortest solution wins.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ I presume I can't change the character # to a space. \$\endgroup\$
    – pxeger
    Commented Feb 24, 2022 at 18:33
  • 2
    \$\begingroup\$ @pxeger Yes, you can't now :) \$\endgroup\$
    – sinvec
    Commented Feb 24, 2022 at 18:37
  • \$\begingroup\$ you allow trailing whitespace, but what about preceding whitespace? (specifically a preceding newline?) \$\endgroup\$
    – Dave
    Commented Feb 26, 2022 at 3:10
  • \$\begingroup\$ @Dave I think it would be fine \$\endgroup\$
    – sinvec
    Commented Feb 26, 2022 at 7:30

35 Answers 35

14
\$\begingroup\$

Google Sheets, 124 bytes

=substitute(query({rept("#",12);sort(if({1;1;1},"#"&rept("#",A1*2)&rept("-",10-A1*2)&"###"));rept("#",12)},,9)," ",char(10))

89 bytes if it's okay for the output to be displayed in separate cells

={rept("#",12);sort(if({1;1;1},"#"&rept("#",A1*2)&rept("-",10-A1*2)&"###"));rept("#",12)}

Try it here

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Welcome to Code Golf, and nice first answer! \$\endgroup\$
    – pxeger
    Commented Feb 24, 2022 at 20:19
  • \$\begingroup\$ @pxeger, thanks! :) \$\endgroup\$
    – user111190
    Commented Feb 24, 2022 at 20:33
14
\$\begingroup\$

brainfuck, 266 245 242 bytes

-21 bytes thanks to @emanresu A's suggestion to use ÿ instead of ! (since ÿ's charcode is the same as the glider reference value 255 on an 8 bit bf interpreter like TIO's).

-3 bytes by removing unnecessary code (at the expense of a pretty memory layout).

-[-[-<]>>+<]>->>+++++[<++>-]->++++[<...>-]<<.>+>-[>+<-----]>---<,>[<->-]<[<+>-]<[>->+>->+>->+<<<<<<-]+++++[>+>>+>>+<<<<<-]->>>>>>>-<+[[[-<+]-.>+[->+]-<[+[-<+]-..>+[->+]-<-]>+<-<[+[-<+]-<<..>>>+[->+]-<-]+[-<+]-...<.>>+[->+]<->]<<+]++++[>...<-]

Try it online!

Uses a glider and fancy loop tricks to print the middle 3 rows. Uses ÿ instead of # since that is allowed by the challenge.

Ungolfed:

memory layout
(pni = 5 minus inp)
3   4   5   6   7   8   9   10  11  12
' ' \n  ÿ   pni inp pni inp pni inp ÿ

' ' = 32
-[-[-<]>>+<]>-
\n = 10
>>+++++[<++>-]
ÿ = 255
-

print top row of ÿs
>++++[<...>-]<<.>+

get input
>-[>+<-----]>---<,>[<->-]<[<+>-]<

copy to loop cells
[>->+>->+>->+<<<<<<-]
+++++[>+>>+>>+<<<<<-]
create glider refs
->>>>>>>-<+

main loop
[
  glider collision guard
  exit the loop when all loop variables are exhausted
  [-
    print first ÿ
    +[-<+]-.>
    +[->+]-
    print ÿs in battery
    <[
      +[-<+]-..>
      +[->+]-
      <-
    ]
    move glider back one cell
    >+<-
    print spaces in battery
    <[
      +[-<+]-<<..>>>
      +[->+]-
      <-
    ]
    print last 3 ÿs and \n
    +[-<+]-...<.>>
    +[->+]
    move glider back one cell
    <->
  ]<<+
]

print last row of ÿs
++++[>...<-]
\$\endgroup\$
3
  • 2
    \$\begingroup\$ Would it be cheaper to use ÿ instead? \$\endgroup\$
    – emanresu A
    Commented Feb 25, 2022 at 3:01
  • \$\begingroup\$ It could be, actually. Let me try doing that and see. \$\endgroup\$
    – nununoisy
    Commented Feb 25, 2022 at 13:27
  • \$\begingroup\$ Finally got around to implementing your golf @emanresu A. Thanks! \$\endgroup\$
    – nununoisy
    Commented Feb 27, 2022 at 20:04
10
\$\begingroup\$

Python, 46 bytes

lambda n:[s:="#"*12,*3*[f'#{"##"*n:10}###'],s]

Attempt This Online!

Outputs a list of lines, as allowed by standard I/O rules.

\$ -9 -1 = -10 \$ thanks to @xnor


Python, 76 bytes

lambda n,r=f"#{' '*10}#".replace:[a:=r(" ","#")]+[r(" ","#",2*n)+"##"]*3+[a]

Attempt This Online!

Did you know Python's str.replace method has a third parameter to limit the maximum number of replacements that will be performed? You do now!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ 47 bytes using f-strings: lambda n:[s:="#"*12]+[f"#{'##'*n:10}###"]*3+[s] \$\endgroup\$
    – xnor
    Commented Feb 24, 2022 at 19:00
  • 3
    \$\begingroup\$ List unpacking saves a byte: lambda n:[s:="#"*12,*[f'#{"##"*n:10}###']*3,s] \$\endgroup\$
    – xnor
    Commented Feb 24, 2022 at 19:40
7
\$\begingroup\$

C (POSIX), 83 bytes

#define s"\n############"
#define r"\n%1$-11s###"
f(i){printf(s r r r s,s+12-i*2);}

I was originally tweaking ErikF's answer but ended up making more substantial changes, so it felt like a new separate answer. Note that this saves some space by printing a newline before the output, which has been approved.

Uses compile-time string concatenation to compress the output template, then uses printf to fill in the correct amount of the bar.

Breakdown:

r template pattern

\n             - print a literal newline
  %     s      - followed by a string
   1$          - from the first argument (POSIX extension)
     -         - padded with trailing spaces
      11       - to at least 11 characters
         ###   - followed by 3 literal hash symbols

printf call

printf(
  s r r r s,     // concatenate define'd strings into full pattern
  s + 12 - i * 2 // first argument: fragment of s (last i * 2 + 1 characters)
);

Expanded

f(i) {
    printf(
        "\n############\n%1$-11s###\n%1$-11s###\n%1$-11s###\n############",
        "\n############" + 12 - i * 2
    );
}

Try it online


As an interesting alternative, this version uses hex values to draw the shape, so it's limited to f characters, but avoids the initial newline. It is the same size (83 bytes):

#define r"%2$-11lxfff\n"
f(i){printf("%lx\n"r r r"%1$lx",(1l<<48)-1,(16l<<i*8)-1);}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Somehow, the "Expanded" version might be less readable than the golfed version. :-) \$\endgroup\$
    – Cody Gray
    Commented Feb 26, 2022 at 12:24
  • \$\begingroup\$ yes the golfed version is quite nice for its clarity, but I expanded it so that it is obvious what's happening for people who may not be familiar with C's macro expansion / compile-time string concatenation \$\endgroup\$
    – Dave
    Commented Feb 26, 2022 at 15:36
  • \$\begingroup\$ Very elegant. I was going to take a stab at this one but I don’t think I can outdo this. \$\endgroup\$
    – mreff555
    Commented Mar 18, 2022 at 23:46
7
\$\begingroup\$

Acc!!, 152 148 99 bytes

N-46
Count l while l-5 {
Count c while c-14+2*0^(l%4) {
Write 32+0^((c+3)/2%7/_*(l%4))
}
Write 10
}

Uses exclamation points. Try it online!

Explanation

This was fun to golf. The verbose syntax of Acc!! drove me to combine as many Count while and Write statements as possible, which required some interesting expressions to encapsulate the logic. (2024 update: looks like I didn't combine nearly "as many as possible" the first time around.)

N-46

Read a character from stdin and store its codepoint minus 46 in the accumulator. If the input number is L, the accumulator now holds the value L+2.

Count l while l-5 {

Do the following (output one line of the battery) five times. (The first and fifth iterations will have l be 0 and 4, so to distinguish them from the others, we can check if l%4 is zero.)

Count c while c-14+2*0^(l%4) {

Do the following (output a character in the middle part of the battery) fourteen times; but when l%4 is zero, do it twelve times. (0^x is a convenient way to turn x=0 into 1 and x>0 into 0.)

Write 32+0^((c+3)/2%7/_*(l%4))

Write either a space or an exclamation point, based on the loop index c, the accumulator value _, and the line number l.

For the inside of the battery, observe that we want to output some number of exclamation points, then some number of spaces, then three more exclamation points. This looks like a slice into a periodic function. Since we want to add exclamation points in pairs, let's aim for something like this:

0         1
01234567890123456789
!!!!..........!!!!..

where ! means "definitely maps to !" and . means "might map to either ! or depending on the accumulator value."

We want to run our loop from 3 to 16 in this function; since loop variables in Acc!! always start at zero, we'll just add 3 to the loop variable c.

Next, we combine the pairs of characters that will always be the same by int-dividing by 2:

0123456789
!!.....!!.

We can get the periodic behavior if we take this input mod 7:

0123456
!!.....

Now it's just a matter of adjusting the cutoff depending on the input value. Conceptually, we want exclamation points if this number is less than L+2, and spaces if it is greater than or equal to L+2. Conveniently, L+2 is the value in the accumulator. Inconveniently, Acc!! doesn't have comparison operators, so we'll have to abuse some arithmetic:

With integer division, and assuming b is always positive, a/b is 0 if a<b and some positive number otherwise. To turn 0 vs positive into 1 vs 0, we can take 0 to that power. End result: 0^(a/b) is 1 if a<b and 0 otherwise.

To handle the first and last lines, which should be entirely exclamation points, we just need to multiply the exponent by l%4. The product a/b*(l%4) is 0 if a<b or if l is 0 or 4, and some positive number otherwise. Taking 0 to that power gives the desired 1 or 0 result.

In our case, we have a = (c+3)/2%7 and b = _ (the accumulator). Substituting those into the above expression and adding to 32 gives exclamation point (ASCII 33) or space (ASCII 32) exactly where we want them.

}
Write 10
}

Close the c loop, write a newline, and close the l loop.

\$\endgroup\$
5
\$\begingroup\$

Charcoal, 18 bytes

UO⊕⊗N³-¹²↘‖O↓UO±³-

Try it online! Link is to verbose version of code. Explanation:

UO⊕⊗N³

Draw the fullness of the top half of the battery.

-¹²↘

Draw the line at the top of the battery and leave the cursor at the top right of the 3×3 square end.

‖O↓

Reflect to complete the fullness and sides of the battery. (This also moves the cursor to the bottom right of the 3×3 square end.)

UO±³-

Draw the 3×3 square end.

\$\endgroup\$
4
+50
\$\begingroup\$

Pari/GP, 82 bytes

n->[print(l)|l<-[s="############",e=Strchr([35-3*(j>n+n&j<11)|j<-[0..13]]),e,e,s]]

Try it online!

This code is most probably not the shortest possible, as this is my first time golfing in Pari/GP.

Thanks @alephalpha for -14 bytes.

\$\endgroup\$
5
  • \$\begingroup\$ You can use list comprehension instead of a for loop. 87 bytes. \$\endgroup\$
    – alephalpha
    Commented Mar 1, 2022 at 9:18
  • \$\begingroup\$ Even shorter using Strchr to convert integers to strings: 82 bytes. \$\endgroup\$
    – alephalpha
    Commented Mar 1, 2022 at 9:31
  • \$\begingroup\$ @alephalpha Thanks for the tips! I'm sure I'll be using these in the future. I wanted to ask, is there a way to do string multiplication in Pari/GP? Like "#"*12 in python. \$\endgroup\$
    – ophact
    Commented Mar 1, 2022 at 9:51
  • \$\begingroup\$ There is no string multiplication. The shortest way I can think of is concat(["#"|i<-[1..12]]), but that is already longer than "############". \$\endgroup\$
    – alephalpha
    Commented Mar 1, 2022 at 10:04
  • 1
    \$\begingroup\$ -2 bytes by using exclamation marks instead: Try it online! \$\endgroup\$
    – DLosc
    Commented Mar 1, 2022 at 18:59
3
\$\begingroup\$

Vyxal, 18 bytes

d×*₀↲×p14e:"×12*p∞

Try it Online!

d                  # Input * 2
 ×*                # That many asterisks
   ₀↲              # Pad the left to length 10 with spaces
     ×p            # Prepend an asterisk
       14e         # Extend to length 14 by appending the first char
          :"       # Pair with itself
                p  # Prepend to this...
            ×12*   # 12 asterisks
                 ∞ # Palindromise the result
\$\endgroup\$
3
\$\begingroup\$

JavaScript, 76 70 bytes

-6 thanks to Hannesh

_=>(a=`############
`)+`#${'##'.repeat(_).padEnd(10)}###
`.repeat(3)+a

Try it Online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Could save 6 bytes by using .padEnd(10) instead of +' '.repeat(5-_) \$\endgroup\$
    – Hannesh
    Commented Mar 6, 2022 at 3:22
3
\$\begingroup\$

brainfuck, 202 bytes

+++++[>++>++++++<<-]>>++>-............<<.>>>>++++[->+++<]>>>>>+++++++[<+++++++>-],<--[>-<-]>[<+<+<+>>>-]<<<[<[-<+<+>>]<[>+<-]>>[<<++<-->>>-]<<-[-<<.>>]<[-<<.>>]<...<<.>>>>>>>[[<+>-]>]<<[<]>>]<[<<<.>>>-]

Try it online!

first, I try to comment this shorter bytes brainfuck to first brainfuck(245 bytes) comment, but i don't have enough reputation. so i decide to comment here and give the link to that first comment. also if I can, I will try to expaining this code later

\$\endgroup\$
2
\$\begingroup\$

Retina 0.8.2, 55 bytes

.+
#$&$*_10$* ###¶
+`(_*)_  
##$1
.+¶
12$*#¶$&$&$&12$*#

Try it online! Explanation:

.+
#$&$*_10$* ###¶

Produce a body row of the empty battery but include L _s.

+`(_*)_  
##$1

For each _, delete two spaces and add two #s.

.+¶
12$*#¶$&$&$&12$*#

Triplicate the row and wrap it in lines of 12 #s.

\$\endgroup\$
2
\$\begingroup\$

C (gcc) with -lm, 93 91 bytes

  • -2 thanks to ceilingcat

Uses 9 as the fill character. I make use of 10n-1 producing n nines when n>0.

*s="999999999999";f(i,j){for(puts(s),j=3;j--;printf("%-11.f999\n",exp10(i-~i)-1));puts(s);}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ you can get down to 90 if you use hex instead of decimal (I expected more but oh well): *s="ffffffffffff";f(i,j){for(puts(s),j=3;j--;printf("%-11lxfff\n",(16l<<i*8)-1));puts(s);} \$\endgroup\$
    – Dave
    Commented Feb 26, 2022 at 2:06
  • \$\begingroup\$ or down to 88 if you use strings (and it lets you use any output character): short*s="############";f(i,j){for(puts(s),j=3;j--;printf("#%-10s###\n",s+6-i));puts(s);} \$\endgroup\$
    – Dave
    Commented Feb 26, 2022 at 2:06
2
\$\begingroup\$

Python 3.8, 85 72 68 49 46 bytes

lambda l,a="##":[a*6,*3*[f'#{l*a:10}###'],a*6]

Outputs a list of strings, as allowed by standard I/O rules

Try it online!

-13 thx to @Aiden chow

-4 thx to @ovs

-3 thx to @Aiden chow

\$\endgroup\$
5
  • \$\begingroup\$ 72 bytes by converting c into an f-string and some other optimizations. \$\endgroup\$
    – Aiden Chow
    Commented Feb 25, 2022 at 7:04
  • \$\begingroup\$ Additional -4 by using the sep argument of print. \$\endgroup\$
    – ovs
    Commented Feb 25, 2022 at 7:07
  • 1
    \$\begingroup\$ is this looking too much like pxeger's answer? \$\endgroup\$
    – DialFrost
    Commented Feb 25, 2022 at 7:26
  • \$\begingroup\$ @DialFrost yeah it's looking really similar to pxeger's answer, though it's still a little different so i think it's fine. \$\endgroup\$
    – Aiden Chow
    Commented Feb 25, 2022 at 7:46
  • 1
    \$\begingroup\$ Also 46 bytes (different from pxeger's answer) \$\endgroup\$
    – Aiden Chow
    Commented Feb 25, 2022 at 7:47
2
\$\begingroup\$

Julia 1.0, 57 51 48 bytes

c='#';!n=[c^12,(h=rpad(c*c^2n,11)*c^3;),h,h,c^12]

Try it online!

-3 MarcMush

\$\endgroup\$
1
  • \$\begingroup\$ 48 bytes \$\endgroup\$
    – MarcMush
    Commented Feb 25, 2022 at 19:47
2
\$\begingroup\$

Excel, 82 74 bytes

It Taylor Rained 8 bytes.

=LET(a,REPT("#",12),b,MID(a&REPT(" ",10),12-2*A1,11)&"###
",a&"
"&b&b&b&a)

Input of L is in the cell A1. Output is wherever the formula is. For best results, make sure the column is wide enough, text wrapping is on, and the font is monospace. The output will be correct regardless but this makes that fact visually apparent.

  • LET(a,REPT("#",12) defines a to be 12 number signs in a row. Combining LET() and REPT() only saves us 1-3 bytes but savings are savings.
  • b,MID(a&REPT(" ",10),12-2*A1,11)&"###\n" has a lot going one but the summary is this:
    • Create a string of 12 # and 10 spaces.
    • Find the right spot (based on the input) in the middle of that string to start pulling characters.
    • Pull 11 characters (1 # + 2*input # + however many spaces).
    • Add ### and a line break.
    • Set the resulting string to the variable b.
  • a&"\n"&b&b&b&a concatenates the pieces into an output.

Screenshot

\$\endgroup\$
1
  • \$\begingroup\$ you can get to 74 bytes with =LET(a,REPT("#",12),b,MID(a&REPT(" ",10),12-2*A1,11)&"###\n",a&"\n"&b&b&b&a) or =LET(a,REPT("#",12),a&"\n"&REPT(MID(a&REPT(" ",10),12-2*A1,11)&"###\n",3)&a) \$\endgroup\$ Commented Feb 26, 2022 at 0:46
2
\$\begingroup\$

C++, 267 bytes

#include<iostream>
#define c std::cin
#define o std::cout
#define h()o<<H<<'\n'
#define L 12
#define H 111111111111
#define M 1
typedef int I;
I main(){I l;c>>l;h();for(I i=0;i<3;i++){o<<M;for(I j=0;j<l*2;j++){o<<1;}for(I k=0;k<L-l*2-2;k++){o<<' ';}o<<111<<'\n';}h();}

Try it Online!

First time golfing in C++, not sure if it's good or not.

\$\endgroup\$
1
2
\$\begingroup\$

J, 50 46 44 bytes

(a,3 1#(a=:12#'#'),:~'# #'#~(>:,10&-,3:)@+:)

Found that building row by row can be shorter.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Lua, 87 bytes

x,b=...,"\n"d=b.rep a=d("#",12)print(a..b..d(b.format("%-11s###\n",d("#",1+2*x)),3)..a)

Attempt This Online!

enter image description here

My alternate approach before the format string was 6 bytes longer at 93 bytes:

x,b=...,"\n"d,f=b.rep,''a=d("#",12)print(a..b..d(d("#",1+2*x)..d(" ",10-2*x).."###"..b,3)..a)
\$\endgroup\$
2
\$\begingroup\$

YASEPL, 58 bytes

prompts you for input

=l'*+=h$35»=a;h,12<!c;h,l!:11!d;" ",l!e;h,3!)cſdſe<<<!a<
\$\endgroup\$
2
\$\begingroup\$

Pip, 29 27 bytes

DhYPhX6L3P[hJhXa.sXt-2*ah]y

Uses the character 9. Attempt This Online!

Explanation

DhYPhX6L3P[hJhXa.sXt-2*ah]y
                             ; h is 100, t is 10, s is space (predefined)
Dh                           ; Decrement h to 99
    hX6                      ; String-repeat h 6 times (twelve 9s)
  YP                         ; Print that and yank it into the y variable
       L3                    ; Do three times:
             hXa             ;  Repeat h (command-line arg) times
                 sX          ;  Repeat space this many times:
                   t-2*a     ;   10 minus 2 times command-line arg
                .            ;  Concatenate
           hJ                ;  Join h on that string (basically add 9 to
                             ;   the front and end of it)
          [             h]   ;  List containing that and another copy of h
         P                   ;  Print, concatenated together
                          y  ; After the loop, print y again
\$\endgroup\$
1
\$\begingroup\$

Python 3, 86 bytes

a,b="#"*12,int(input())
c="#"+"#"*2*b+" "*(10-2*b)+"###"
print("\n".join([a,c,c,c,a]))

Try it online!

Quick and dirty, but it works.

\$\endgroup\$
0
1
\$\begingroup\$

Charcoal, 49 bytes

P×-¹²P↓×-⁵≔Nα↓→F³«P×-×α²↓»P×-¹¹Fχ«→»P↑×-⁴F³«↑P×-³`

Try It Online! Link is to verbose version of code.

My second Charcoal answer!

Uses "-" instead of "#" because if I change, The Output uses both "-" and "#".

Explanation:

TODO: Understand the code and explain

\$\endgroup\$
3
  • \$\begingroup\$ Trivial golfs: ↓→ can be ; Fχ«→» can be Fχ→ or Mχ→; P×-¹² can be P¹² (but not when using ); ≔Nα can be Nα (but I normally use θ instead of α). \$\endgroup\$
    – Neil
    Commented Feb 24, 2022 at 20:22
  • \$\begingroup\$ @Neil Thanks for 8 bytes. \$\endgroup\$
    – Fmbalbuena
    Commented Feb 24, 2022 at 21:44
  • \$\begingroup\$ Actually the P×- was just an example; you can do the same simplification to in a couple of other places too. \$\endgroup\$
    – Neil
    Commented Feb 24, 2022 at 23:21
1
\$\begingroup\$

05AB1E, 19 18 bytes

X12×$·×Tj7bìĆRD».∊

Outputs 1 instead of #.

Try it online or verify all test cases.

Explanation:

X               # Push 1
 12             # Push 12
   ×            # Repeat the "1" 12 times: 111111111111
$               # Push 1 and the input
 ·              # Double the input
  ×             # Repeat the "1" that many times
   Tj           # Pad it with leading spaces up to length 10
     7bì        # Prepend the binary of 7: 111
        Ć       # Enclose; append its own head
         R      # Reverse it
          D     # Duplicate it
           »    # Join the stack with newline delimiter
            .∊  # Mirror it vertically with overlap
                # (after which the result is output implicitly)
\$\endgroup\$
1
\$\begingroup\$

Noether, 76 bytes

I~l12("#"P!i)?3(0~rl2*1+("#"P!r)0~r11l2*-(r0{>}{" "P}!r)"###"P?!k)12("#"P!y)

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Java (JDK), 98, 95 bytes

L->{System.out.format("%s"+"%2$-11s###\n".repeat(3)+"%1$s","############\n","#".repeat(L-~L));}

Try it online!

\$\endgroup\$
0
1
\$\begingroup\$

Perl 5, 63 bytes

$_=($s='#'x12 .$/).('#'.'#'x($x=2*$_).$"x(10-$x)."###\n")x3 .$s

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 57 bytes \$\endgroup\$
    – Neil
    Commented Feb 27, 2022 at 0:57
  • \$\begingroup\$ Nice, no need for $x here. \$\endgroup\$
    – Kjetil S
    Commented Feb 28, 2022 at 9:19
  • 1
    \$\begingroup\$ Nice, I came up with pretty much the same approach for 44 bytes, but it does necessitate resetting $\ in your test suite (works as a single run without a problem though!) \$\endgroup\$ Commented Mar 1, 2022 at 9:36
  • \$\begingroup\$ Gosh, nice too. I missed the fine print about allowing other chars than #. \$\endgroup\$
    – Kjetil S
    Commented Mar 1, 2022 at 17:13
1
\$\begingroup\$

CJam, 38 bytes

li2*:I;'#:OC*N+_O_I*+AI-S*+O3*+N+3*\++

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Ruby, 43 characters

->l{[s=?#*12,m='#%-10s###'%(?#*l*2),m,m,s]}

Sample run:

irb(main):001:0> puts ->l{[s=?#*12,m='#%-10s###'%(?#*l*2),m,m,s]}[3]
############
#######    ###                                       
#######    ###                                       
#######    ###                                       
############                                         

Try it online!

\$\endgroup\$
1
\$\begingroup\$

R, 92 82 bytes

Inputs L and outputs the battery status to stdout.

-10 bytes by changing the rep function alias and including 2* in the definition of L. (golfed by pajonk)

R="#";`?`=rep;cat(s<-(R?12),"\n",c(R,R?(L<-2*scan())," "?10-L,"###\n")?3,s,sep="")

Attempt This Online!

\$\endgroup\$
2
  • \$\begingroup\$ -10 bytes by changing r to ? and including 2* in the definition of L. \$\endgroup\$
    – pajonk
    Commented Apr 11 at 4:41
  • \$\begingroup\$ @pajonk that is cool! thank you. \$\endgroup\$
    – Patric
    Commented Apr 11 at 6:28
1
\$\begingroup\$

JavaScript (Node.js), 92 bytes

b=L=>console.log([t='#'[r='repeat'](12),m='#'+'##'[r](L)+'  '[r](5-L)+'###',m,m,t].join`\n`)

Attempt This Online!

\$\endgroup\$
1
  • \$\begingroup\$ You can save a byte by changing .join`\n` to a literal newline inside the string. \$\endgroup\$ Commented Apr 12 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.