-3
\$\begingroup\$

Print the following output of a happy coincidence addition pattern:

   8
   8
   8
  88
+888
----
1000

Rules:

  • No leading spaces except the ones already present
  • There can be a trailing newline
  • + sign needs to be displayed
  • Order of parcels needs to be the same

No winner. It is per language.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ So, what exactly do you want us to print? 1000? 8+8+8+88+888=1000? \$\endgroup\$
    – Okx
    Nov 1, 2017 at 17:33
  • 1
    \$\begingroup\$ I think he wants the entire equation as-is. \$\endgroup\$ Nov 1, 2017 at 17:35
  • 1
    \$\begingroup\$ Ah, I got confused by the lack of the tag kolmogorov-complexity \$\endgroup\$
    – Okx
    Nov 1, 2017 at 17:43
  • 19
    \$\begingroup\$ I downvoted this challenge for the following reason: The output is far too short (in my opinion) for a KC challenge, and doesn't have a great pattern either. This doesn't leave too much place for clever compression, and hardcoding is most likely the golfiest way to solve it (in most languages). \$\endgroup\$
    – Mr. Xcoder
    Nov 1, 2017 at 17:57
  • 2
    \$\begingroup\$ I upvoted because with answers getting below the size of the plain output (34 bytes), there obviously are some "clever" ways. \$\endgroup\$ Nov 2, 2017 at 9:59

23 Answers 23

5
\$\begingroup\$

PowerShell, 34 33 31 bytes

,'   8'*3+"  88
+888"+'-'*4+1e3

Try it online!

Five bytes shorter than printing the string as-is, but still not very golfy. now getting to be golfy.

Constructs an array of 3x ' 8' (saving a byte), then array-concatenates the remaining items, with '-'*4 saving a byte. The other byte savings comes from using 1e3 in place of 1000.

\$\endgroup\$
1
  • \$\begingroup\$ You can replace all + on line breaks. This will not change the length. Only for fun. \$\endgroup\$
    – mazzy
    Aug 9, 2018 at 7:48
5
\$\begingroup\$

Charcoal, 15 14 bytes

G↑↑↓↙³8←→⟦+⁴Iφ

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

G↑↑↓↙³          Draw a polygon implicitly closing the path
      8         Filled with the string 8
       ←        Move left one character
          +     Literal string +
           ⁴    Integer 4 (prints as ----)
             φ  Predefined variable 1000
            I   Cast to string
         ⟦      Wrap in array (implicit ⟧)
        →       Override ← print direction
                Implicitly print one per line
\$\endgroup\$
4
\$\begingroup\$

Bash, 35 bytes

printf %4s\\n {,,,8,+88}8 ---- 1000

Try It Online

\$\endgroup\$
3
\$\begingroup\$

Python 2, 40 bytes

print"   8\n"*3+"  88\n+888\n----\n1000"

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ +2 bytes if you make it Python 3 compatible, but otherwise you're absolutely right. \$\endgroup\$ Nov 1, 2017 at 17:56
2
\$\begingroup\$

Python 3, 57 52 51 50 bytes

-5 bytes thanks to Mr. Xcoder.

-1 byte thanks to Dennis.

-1 byte again, thanks to Mr. Xcoder.

for i in 8,8,8,88,'+888','-'*4,1000:print('%4s'%i)

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ Ahum Hardcoded output is 49 bytes.. \$\endgroup\$ Nov 2, 2017 at 8:55
  • 2
    \$\begingroup\$ @KevinCruijssen Huh, that’s already my answer :-) \$\endgroup\$
    – Mr. Xcoder
    Nov 2, 2017 at 9:09
  • \$\begingroup\$ @Mr.Xcoder Oh, oops.. Didn't notice there was another Python answer. Yours is even shorter by using print"..." instead of print('...'), though. :) I'll delete my comment above in that case. \$\endgroup\$ Nov 2, 2017 at 9:12
  • \$\begingroup\$ @KevinCruijssen because that was already posted for Py2 I didn’t want to steal it ;) Besides, simply printing hard-coded is... boring? Almost like a cop-out so I didn’t take that approach :) \$\endgroup\$ Nov 2, 2017 at 15:09
  • \$\begingroup\$ @KevinCruijssen Keep in mind though that Python 2 and Python 3 are their own languages, in a sense, so there can be two different approaches :) \$\endgroup\$ Nov 2, 2017 at 15:11
2
\$\begingroup\$

05AB1E, 20 bytes

-1 byte thanks to Riley

8ÐЫD„8+«'-4×₄R).Bí»

Try it online!

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

SOGL V0.12, 15 bytes

≥č*xi«∙tν↔β⁸‘4n

Try it Here! - simply 8 8 8 88+888----1000 compressed, then split to line lengths of 4

20 19 byte non-compression based method:

8³'E■888+⁰§o┌4*LM*⁰

Try it Here!

8                    push 8
 ³                   triplicate the 8
  'E                 push 88
    ■888+            push "888+"
         ⁰           wrap those in an array
          §          reverse horizontally, padding with spaces
           o         output that
            ┌4*      push "-"*4
               LM*   push 100*10
                  ⁰  wrap those two in an array, outputting both
\$\endgroup\$
2
\$\begingroup\$

brainfuck, 107 bytes

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

Try it online!

Explanation

++++++++[>+++++>+>+++++++>++++<<<<-]>+++++>++<<+++
TAPE:
>V_LOOP< C_DASH C_NL C_EIGHT C_SPACE
003      045    010  056     032

~~~OUTPUT SECTION~~~
V_LOOP TIMES DO                     [-
    PRINT C_SPACE x 3                 >>>> ...
    PRINT C_EIGHT                     <.
    PRINT C_NL                        <.
                                    <<]
PRINT C_SPACE x 2                   >>>>..
PRINT C_EIGHT x 2                   <..
PRINT C_NL                          <.
C_DASH = C_DASH MINUS 2 (PLUS SIGN) <--
PRINT PLUS SIGN                     .
PRINT C_EIGHT x 3                   >>...
PRINT C_NL                          <.
PRINT C_DASH x 4                    <++....
PRINT C_EIGHT                       >.
C_DASH = C_DASH PLUS 2 ('1')        <++++
PRINT '1'                           .
C_DASH = C_DASH MINUS 1 ('0')       -
PRINT '0' x 3                       ...
\$\endgroup\$
2
\$\begingroup\$

Bubblegum, 23 bytes

00000000: 5350 50b0 e042 262c 2cb8 b42d 8084 2e10  SPP..B&,,..-....
00000010: 7019 1a18 1800 00                        p......

Try it online!

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

V, 23 bytes

3o³ 8òÙhr8òR1³0-Ò-kr+

Try it online!

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

Javascript 44 bytes

a=x=>`   8
`.repeat(3)+`  88
+888
----
1000`

console.log(a())

\$\endgroup\$
1
  • 2
    \$\begingroup\$ 39 bytes \$\endgroup\$
    – user72349
    Nov 1, 2017 at 19:25
1
\$\begingroup\$

GNU sed, 37 bytes

s:$:   8:p;p
a\  88
a+888
a----
a1000

Try it online!

I use the a command to append text lines to output. For comparison, the trivial solution is to print the hardcoded text like below, 42 bytes. Reduction is 11.9 %.

c\   8\n   8\n   8\n  88\n+888\n----\n1000
\$\endgroup\$
1
\$\begingroup\$

///, 31 bytes

/!/   8
/!!!  88
+888
----
1000

Try it online!

A measly 3 bytes savings.

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

QBIC, 36 bytes

?@   8`?A?A?@  88`?@+888`?@----`?z^3
\$\endgroup\$
1
\$\begingroup\$

LOLCODE, 66 bytes

HAI 1.3
VISIBLE "   8:)   8:)   8:)  88:)+888:)----:)1000"
KTHXBYE

Try it online!

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

R, 46 bytes41 bytes

cat('   8
   8
   8
  88
+888
----
1000')

Try it online!

Thanks to Dennis for golfing off 5 bytes.

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

Java 8, 45 bytes

v->"   8\n   8\n   8\n  88\n+888\n----\n1000"

Boring hard-coded output, but this can't be done any shorter in Java. Just utilizing the repeated part " 8\n" is already 52 bytes..
v->"aaa 88\n+888\n----\n1000".replace("a"," 8\n")

Try it here.

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

J, 28 27 bytes

|.|:'1-+','0-88888'$~3,4,:7

Try it online!

                                             0-8   
          '0-88888'$~3,4,:7      Three rows: 0-88   
                                             0-88888
    '1-+',                       "1-+" on top
|.|:                             Rotate counter-clockwise
\$\endgroup\$
1
\$\begingroup\$

J, 37 bytes

  7 4 $'   8   8   8  88+888----1000'
\$\endgroup\$
0
0
\$\begingroup\$

Brainfuck, 104 bytes

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

Uses the same technique as this genius answer.

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

Tcl, 42 bytes

puts "   8
   8
   8
  88
+888
----
1000"

Try it online!

\$\endgroup\$
3
0
\$\begingroup\$

Stax, 19 bytes

∩π╚nY╤¼æ♂ç♦d└tä♂&lò

Run and debug it

ASCII equivalent:

.-+]125E{'8*eN$m+MrVk+m

Build the 8s together with the line below by transposing the string representation of the array [-8,-88,-88888].

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

Befunge-93, 66 bytes

"0001"25*"-":::25*"888+"25*"88  "25*"8 "::25*"8 "::25*"8 "::>:#,_@

Try it online!

\$\endgroup\$

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.