33
\$\begingroup\$

Challenge

Draw a Heart shape

enter image description here

...as ASCII art!

Your art doesn't have to look exactly like mine, but it has to look like a Heart Shape.

The inside of of the heart has to contain the words "Love" at least 20 times

Rules

  • The program must write the art to the console.
  • Shortest code (in bytes, any language) wins.

The winner will be chosen on February 14th on Valentines Day

\$\endgroup\$
3
  • 4
    \$\begingroup\$ In order to be a fair code-golf I think you should give a more restrictive definition of the output. \$\endgroup\$
    – Howard
    Jan 22, 2014 at 18:16
  • 3
    \$\begingroup\$ I'm waiting for someone to submit a biologically accurate looking heart. Whoever does that immediately gets a +1 from me. \$\endgroup\$
    – Joe
    Jan 23, 2014 at 16:05
  • 3
    \$\begingroup\$ This would've much been better as a popularity-contest \$\endgroup\$
    – SztupY
    Jan 29, 2014 at 16:40

23 Answers 23

52
\$\begingroup\$

JavaScript [160 bytes]

The following code seems to be 160 bytes unformatted.

   ('l2v2l6v2'+  'e1l1v3l2'+
 'v3e1v7e1v7e1v7e1l2v6e1l4v5'+
'e1l6v4e1l8v3e1l7l3v2e1l9l3v1')
 .replace(/[lve]\d/g,function
   (c){return Array(-~c[1]).
      join({l:' ',v:'Love'
         ,e:'\n'}[c[0
             ]])})

Simply run this in the browser console (e.g. in Firebug or Chrome Dev Tools).

\$\endgroup\$
9
  • 2
    \$\begingroup\$ Changing /[lve]\d/ to /../ and using array ['','Love','\n'] instead of object will save another 10 bytes leading to 150 bytes in total, but the source heart won't be that well shaped anymore :) \$\endgroup\$
    – VisioN
    Jan 23, 2014 at 11:57
  • 3
    \$\begingroup\$ !!!Awesome job!!! \$\endgroup\$
    – SpYk3HH
    Jan 23, 2014 at 15:04
  • 1
    \$\begingroup\$ Using fat arrow function will save a lot of bytes. Replace function(c){return by c=> and remove }. You should post a shorter version! \$\endgroup\$
    – Florent
    Jan 23, 2014 at 15:19
  • 2
    \$\begingroup\$ No. EcmaScript 6. \$\endgroup\$
    – Florent
    Jan 23, 2014 at 15:21
  • 1
    \$\begingroup\$ @Florent Ah! As far as I know ECMAScript 6 is still experimental and unfortunately it is still very hard to test how it works. Lets assume my code is ECMAScript 5 compatible :) But thank you for pointing out! I hope soon JavaScript will compete with Perl and Python in golfing matters and everyone will be able to try that out. \$\endgroup\$
    – VisioN
    Jan 23, 2014 at 15:27
27
\$\begingroup\$

GolfScript: 62 57 54 characters

4 1.5\.5,+{.5\-\2*\0.}/]4/{[32'LOVE']2*]zip{(*}%''+}%~

Output:

    LOVE    LOVE
  LOVELOVELOVELOVE
LOVELOVELOVELOVELOVE
  LOVELOVELOVELOVE
    LOVELOVELOVE
      LOVELOVE
        LOVE

Or, for some added love, and the obligatory abuse of whitespace insignificance (for 84 characters):

    5 1       .8\
  .)...5   ,{.5\-\3
 *\0.}/]4 /{[32[9829
  :x.'LOVE'\]''+]2
    *[@;]zip{(*}%
     ''+}%~' '15
        *x[]+
          +

Output:

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥
\$\endgroup\$
16
\$\begingroup\$

C - 183 bytes

Not a winner, but a whole lotta love. Can you figure out how it works?

#include <stdio.h>
#define C(a) ((a)*(a)*(a))
int main(){int x,y;for(y=9;y>-6;y--){for(x=-8;x<9;x++)putchar(C(x*x+y*y-25)<25*x*x*y*y*y?"LOVE"[(x+10)%4]:'-');putchar('\n');}return 0;}

Output:

-----------------
--LOVE-----OVEL--
-ELOVEL---LOVELO-
-ELOVELO-ELOVELO-
-ELOVELO-ELOVELO-
-ELOVELOVELOVELO-
--LOVELOVELOVEL--
--LOVELOVELOVEL--
---OVELOVELOVE---
----VELOVELOV----
----VELOVELOV----
------LOVEL------
-------OVE-------
--------V--------
-----------------
\$\endgroup\$
3
  • 6
    \$\begingroup\$ Nice job putting V at the bottom. \$\endgroup\$ Jan 22, 2014 at 20:16
  • 1
    \$\begingroup\$ Nice use of the heart curve! You can still save a couple of characters and get down to 153 (I also changed the output slightly at the cost of one added byte): ideone.com/ELnkEE \$\endgroup\$
    – reima
    Jan 23, 2014 at 1:09
  • \$\begingroup\$ Very cool. I've never been great at REALLY squeezing bytes. You should post it as your own C! The heart curve is public domain :) \$\endgroup\$
    – user15259
    Jan 23, 2014 at 18:35
15
\$\begingroup\$

Scala - 273 Characters

Well, I certainly don't expect to win for brevity, but I wanted to see if I could do it in Scala. A smarter golfer could probably shave several bytes off, but here's what I got:

type D=Double;def w(x:D,y:D,a:D)={val(i,j)=(x-a,y-8);Math.sqrt(i*i+j*j)< 8};val l:Stream[Char]="love".toStream#:::l;val c=l.toIterator;def p(b:Boolean)=print(if(b)c.next else' ');for(y<-0 to 24){for(x<-0 to 32){if(y>7)p((16-x).abs< 24-y)else p(w(x,y,8)|w(x,y,24))};println}

Or, if you prefer (still valid code!)

  type D=      Double 
def w(x:D,    y:D,a:D)=
{val(i,j)=   (x-a,y -8);
Math.sqrt(i* i+j*j)< 8};
val l : Stream [Char] =
"love".toStream#:::l;val
 c= l .toIterator;def p
  (b:Boolean) =print(if
   (b)c.next else' ');
    for (y <-0 to 24) 
     { for (x<- 0 to
      32){if(y >7)
        p((16-x).
          abs < 
          24-y)
         else
        p(w
       (x,
       y,
      8
      )
      |
      w(
       x,
         y,
           24)
              )}
                 println}

Prints out two semicircles and a triangle to the screen, making a pretty decent facsimile of a heart.Picture of heart.scala output

Needs to be run with the scala interpreter (compiling would require adding some extra cruft for object Main { def main(args: Array[String]) = { ... } } and I'm just havin' none of that.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ @epidemian I probably could've made it look more like a normal heart, but I misjudged the size of the code and was too lazy. So I made a tail instead. I like to pretend that it's a balloon :p \$\endgroup\$
    – KChaloux
    Feb 14, 2014 at 18:05
14
\$\begingroup\$

Python, 210 characters

Of course, this won't win because it is a code golf, but I wanted to be creative and I have not used the word Love in my source code:

import gzip
print(gzip.decompress(b'\x1f\x8b\x08\x00\x95\x10\xe0R\x02\xffSPP\xf0\xc9/KU\x80\x03\x10\x8f\x0bB\xa1c.l\x82dJ\xe0\xb0\x01\xe6\x02\x0cATa.T\xf7\x02\x00\xd9\x91g\x05\xc5\x00\x00\x00').decode('ascii'))

This is the output:

   Love          Love
  LoveLoveLoveLoveLove
LoveLoveLoveLoveLoveLove
LoveLoveLoveLoveLoveLove
LoveLoveLoveLoveLoveLove
  LoveLoveLoveLoveLove
    LoveLoveLoveLove
      LoveLoveLove
          Love
\$\endgroup\$
2
  • \$\begingroup\$ I like your approach ^_^ \$\endgroup\$
    – Navin
    Jan 29, 2014 at 1:52
  • 2
    \$\begingroup\$ Using gzip is not really creative... \$\endgroup\$ Feb 13, 2015 at 18:38
12
\$\begingroup\$

Python 2, 117

prints exactly 20 loves horizontally.

x="love";print"   x    x\nx xx x\nx   x   x".replace("x",x)
for i in range(5):print" "*i+x+" "*(9-i*2),x
print" "*6,x

output:

   love    love
love lovelove love
love   love   love
love          love
 love        love
  love      love
   love    love
    love  love
       love
\$\endgroup\$
4
  • \$\begingroup\$ Spare some characters by: use a single letter placeholder in the 2nd line's string then replace() them; in the 3rd line's print change one + to , and 10 with 9; in the last line use variable x's value. pastebin.com/i1TSEZfE \$\endgroup\$
    – manatwork
    Jan 22, 2014 at 19:28
  • \$\begingroup\$ @manatwork Thank you. Edited the body now down to 121 chars :-) \$\endgroup\$
    – Wasi
    Jan 22, 2014 at 19:36
  • \$\begingroup\$ Are you counting the three vertical loves on the right side that you got by staggering the horizontal loves? \$\endgroup\$ Jan 29, 2014 at 20:42
  • \$\begingroup\$ @JoshuaTaylor Thanks, I didn't notice those vertical loves. Including those the love count will be 23 :D \$\endgroup\$
    – Wasi
    Jan 30, 2014 at 10:30
11
\$\begingroup\$

Perl - 36 bytes

  open    0;s
/\S.?/Lo.ve
  /ge,print
    , , for
        <0>

Output:

  LoveLove    LoveLove
LoveLoveLoveLoveLoveLove
  LoveLoveLoveLoveLove
    LoveLoveLoveLove
        LoveLove

This is a bit of a cheat; it will print Love once for every two non-white space characters in the source code. With the required whitespace to make the heart shape, the code is 61 bytes in length: flattened it is only 36 bytes:

open 0;s/\S.?/Lo.ve/ge,print,,for<0>

Perl - 60 bytes

print$"x(15&ord),Love,$/x/\D/for'3h112a05e0n1l2j4f6b9'=~/./g

Outputs the following:

   Love        Love
 Love Love  Love Love
Love     Love     Love
Love              Love
 Love            Love
  Love          Love
    Love      Love
      Love  Love
         Love

Exactly 20 Love.


Brief Explaination
by request

  • for'3h112a05e0n1l2j4f6b9'=~/./g
    This modifies the print statement, and iterates over each character. The regex /./ obviously matches a single character, and in a list context /./g will return a list of all characters in the string. A more common, but slightly longer way to write this would be for split//,'3h112a05e0n1l2j4f6b9'.
  • print$"x(15&ord),Love,$/x/\D/
    The special variable $" defaults to a space. The ordinal value of each character mod 16 stores the number spaces needed between each Love via string repetition (x). Finally, if the character is not a digit (/\D/), the value of $/, which defaults to "\n" is tacked on to the end.
\$\endgroup\$
7
  • \$\begingroup\$ your second program throws an error: "syntax error at -e line 1, near "/\D/for3h112a05e0n1l2j4f6b9" (tried to invoke from command line using -e) \$\endgroup\$
    – Tomas
    Jan 31, 2014 at 17:40
  • \$\begingroup\$ From command line, you will need to replace $" with ' ': perl -e "print' 'x(15&ord),Love,$/x/\D/for'3h112a05e0n1l2j4f6b9'=~/./g" \$\endgroup\$
    – primo
    Jan 31, 2014 at 17:46
  • \$\begingroup\$ OK, nice trick! \$\endgroup\$
    – Tomas
    Jan 31, 2014 at 17:50
  • \$\begingroup\$ The 36 byte version doesn't actually print the required output \$\endgroup\$
    – Tobia
    Feb 1, 2014 at 13:20
  • 1
    \$\begingroup\$ @simbabque done. \$\endgroup\$
    – primo
    Jun 17, 2016 at 14:05
6
\$\begingroup\$

Wolfram Language (Mathematica) - 111

i=0;MatrixForm@Table[If[(x^2+y^2-200)^3+10x^2y^3<0,{"L","O","V","E"}[[i++~Mod~4+1]],""],{y,-20,20},{x,-20,20}]

enter image description here

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

Javascript - 147 141 137 133 characters

with(Math){s="";for(k=800;k--;)
x=abs(1.25-k%40/16),y=k/320-1.25,
s+=.75>x+abs(y)|.5>sqrt(x*x-x+y*y-y+.5)
?"Love"[k%4]:39==k%40?"\n":" "}s

Note : I posted another answer, but this one use different approach and heart has a different shape.

How it works :

enter image description here

First, I render a diamond (equation is |x|+|y|) then, I combine two circles on the top. x values are mirrored (so only one circle is needed).

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You could shorten your code by removing the 0 before floating numbers and assigning Math.abs to a variable. \$\endgroup\$
    – Florent
    Jan 24, 2014 at 9:48
  • \$\begingroup\$ Also you may want to remove two useless semicolons from the end to save another couple of bytes. \$\endgroup\$
    – VisioN
    Jan 29, 2014 at 8:11
4
\$\begingroup\$

Ruby, 47, or Golfscript, 41

Boring answer.

puts" Love  Love
"+"LoveLoveLove
"*6+"    Love"

Golfscript version:

" Love  Love
""LoveLoveLove
"6*"    Love"

Output:

 Love  Love
LoveLoveLove
LoveLoveLove
LoveLoveLove
LoveLoveLove
LoveLoveLove
LoveLoveLove
    Love
\$\endgroup\$
1
  • 33
    \$\begingroup\$ Lol, what an ugly heart! :D \$\endgroup\$
    – Abbas
    Jan 22, 2014 at 18:48
4
\$\begingroup\$

Sclipting — 28 chars / 56 bytes

겤뙡늆굚넰밌各긂밀❷거雙復냄뭖끐❸갰右거雙復겠⓸걠右復終

Output:

    LOVE    LOVE
  LOVELOVELOVELOVE
LOVELOVELOVELOVELOVE
  LOVELOVELOVELOVE
    LOVELOVELOVE
      LOVELOVE
        LOVE
\$\endgroup\$
6
  • \$\begingroup\$ (Or in 24 characters: 긢꼙겱딧꽔밂各감啃갰啃긂밀⓶復냄뭖끐⓷復겠⓸復終 — but this uses the instruction, which I added after this challenge was posted, so it doesn’t count.) \$\endgroup\$
    – Timwi
    Jan 23, 2014 at 19:28
  • \$\begingroup\$ This is 84 bytes. \$\endgroup\$
    – tobyink
    Jan 23, 2014 at 21:08
  • \$\begingroup\$ No, it’s 56 bytes as UTF-16. \$\endgroup\$
    – Timwi
    Jan 23, 2014 at 21:13
  • \$\begingroup\$ @Timwi for me it measures 58 bytes. Odd. \$\endgroup\$
    – primo
    Jan 28, 2014 at 23:54
  • \$\begingroup\$ @primo: It’s 56 bytes. If you saved it as “Unicode” in Windows Notepad, you get a 58 byte file that consists of the UTF-16 BOM (2 bytes) plus the 56-byte program. \$\endgroup\$
    – Timwi
    Jan 30, 2014 at 14:03
4
\$\begingroup\$

JavaScript - 136 121 115 113 characters

s="";for(k=800;k--;)
x=1.25-k%40/16,y=k/320-1.25,
s+=Math.pow(x*x+y*y-1,3)<x*x*y*y*y
?"Love"[k%4]:39==k%40?"\n":" ";s

To run : copy paste into browser console (eg : Chrome or Firefox)

\$\endgroup\$
2
  • \$\begingroup\$ ["L","o","v","e"] => "Love" will save 11 bytes. \$\endgroup\$
    – VisioN
    Jan 23, 2014 at 11:49
  • \$\begingroup\$ Fixed :). Thanks for suggestion. \$\endgroup\$
    – tigrou
    Jan 23, 2014 at 12:04
3
\$\begingroup\$

C, 116 chars

(I don't know if this is heart-shaped enough... fills the inside of three circles to produce the output.)

i = 192, x, y;
main(t) {
  for (; i--; putchar(i % 16? y : 10))
    y = i / 16 - 8,
    x = i % 16 - 8,
    t = x*x + y*y,
    y = " Levo"[ (t < 64 & y < 0 | t < 8*abs(x)) * (i % 4 + 1) ];
}

Output:

 veLov   veLov 
oveLove oveLove
oveLove oveLove
oveLove oveLove
oveLoveLoveLove
oveLoveLoveLove
oveLoveLoveLove
 veLoveLoveLov 
 veLoveLoveLov 
  eLoveLoveLo  
    oveLove    

Earlier in the golfing process, before replacing constant expressions (change M to adjust size):

#define M 4

i = 3*M * 4*M, x, y;
main(t) {
  for (; i--; putchar(i % (4*M)? x : '\n')) {
    y = i / (4*M) - 2*M, x = i % (4*M) - 2*M,
    t = x*x + y*y, x = " Levo"[ (t < 4*M*M & y < 0 | t < abs(2*M*x)) * (1 + i % 4) ];
  }
}

I also felt compelled to do this. :P

#define F for
#define M main

 /*##     ####
####*/i  =192,x
,y;M(t) {F(;i--
;putchar(i %16?
y:10))y=i/16-8,
x=i%16-8,t=x*x+
y*y,y=" Levo"[(
 t<64&y<0|t<8*
  abs(x))*(i%
    4+1)];}
\$\endgroup\$
3
  • \$\begingroup\$ What kind of mystic options/compiler should you use to compile it ? All variables in C are typed en.wikibooks.org/wiki/C_Programming/Variables \$\endgroup\$
    – Micka
    Jan 24, 2014 at 19:07
  • 1
    \$\begingroup\$ @Micka global variables are implicitly declared as int, a legacy feature borrowed from pre-ANSI-C. It compiles just fine for me with clang foo.c or gcc -std=c99 foo.c (though, with plenty of warnings). Do you get any errors? I don't know C well enough to gurantee that I don't depend on undefined behaviour, but I believe I don't do that. \$\endgroup\$
    – FireFly
    Jan 24, 2014 at 19:30
  • 1
    \$\begingroup\$ Hrm, apparently it's not sanctioned by any of the standards--I thought it was legal in C90 at least, but alas, it isn't. So it's just a legacy thing left from pre-ANSI-C that most compilers support anyway (see [this footnote](en.wikipedia.org/wiki/… on wikipedia e.g.). \$\endgroup\$
    – FireFly
    Jan 24, 2014 at 19:53
3
\$\begingroup\$

Ruby - 113 Characters

l=->a,b=28,c=1{puts (("Love"*a).center(b))*c};l.call(2,14,2);l.call(3,14,2);[7,7,7,6,5,4,3,2,1].map{|x|l.call(x)}

Output:

1.9.3p448 :811 > l=->a,b=28,c=1{puts (("Love"*a).center(b))*c};l.call(2,14,2);l.call(3,14,2);[7,7,7,6,5,4,3,2,1].map{|x|l.call(x)}
   LoveLove      LoveLove   
 LoveLoveLove  LoveLoveLove 
LoveLoveLoveLoveLoveLoveLove
LoveLoveLoveLoveLoveLoveLove
LoveLoveLoveLoveLoveLoveLove
  LoveLoveLoveLoveLoveLove  
    LoveLoveLoveLoveLove    
      LoveLoveLoveLove      
        LoveLoveLove        
          LoveLove          
            Love            

To be more clear

enter image description here

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

Perl - 159 characters

Not massively golfed...

printf"%-14s%14s\n",$_,~~reverse for map{($.,$i,$c)=split',';($"x$i).($.x$c)}qw(L,5,3 o,3,8 v,1,11 e,0,13 L,1,13 o,3,11 v,5,9 e,7,7 L,8,6 o,10,4 v,12,2 e,13,1)

Here's the same with added whitespace for slightly better readability...

printf "%-14s%14s\n", $_, ~~reverse
   for map {
      ($.,$i,$c) = split',';
      ($"x$i).($.x$c)
   } qw(
      L,5,3
      o,3,8
      v,1,11
      e,0,13
      L,1,13
      o,3,11
      v,5,9
      e,7,7
      L,8,6
      o,10,4
      v,12,2
      e,13,1
   )

Output is...

     LLL            LLL     
   oooooooo      oooooooo   
 vvvvvvvvvvv    vvvvvvvvvvv 
eeeeeeeeeeeee  eeeeeeeeeeeee
 LLLLLLLLLLLLLLLLLLLLLLLLLL 
   oooooooooooooooooooooo   
     vvvvvvvvvvvvvvvvvv     
       eeeeeeeeeeeeee       
        LLLLLLLLLLLL        
          oooooooo          
            vvvv            
             ee             

The complete word "Love" is contained within (vertically) 22 times, plus numerous partials.

\$\endgroup\$
1
  • \$\begingroup\$ +1 for creativity. I wouldn't have thought to make it vertical. \$\endgroup\$ Jan 23, 2014 at 15:55
3
\$\begingroup\$

APL, 36 chars / bytes*

7 16⍴∊'  ' 'Love'[20400948744⊤⍨36/2]

Must be evaluated with ⎕IO←0 (the default varies by implementation)

*APL can be written in a single-byte charset if needed (as long as you don't use any other Unicode character) so N chars = N bytes for the purpose of counting.

Output:

Contains exactly 20 "Love"

  Love    Love
LoveLoveLoveLove
LoveLoveLoveLove
LoveLoveLoveLove
  LoveLoveLove
    LoveLove
      Love
\$\endgroup\$
2
\$\begingroup\$

Extended BrainFuck : 193 (counted without non essential whitespace)

    {h]<[<]<        [<}>>-->
-3>->-3>+9>+9>+>-7>+>->-5>+>->->
-3>+>+>>4->->6+>5+>>4+[-<4+>]<[-
<4+<5+<5+<5+4>&h++]>[-[-[<10+.[-]
    >-[[-]3<[-]]>[<4+3<[[->>
    +<<]<]]]>[[>]>[.>&h]<<++
        >]]>[<<4+[->8+<]
        >....[-]<<+>>]>]

Turns into:

Brainfuck: 264 (counted without non essential whitespace)

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

You run it with any bf interpreter. Ubuntu has bf and beef and both works nicely.

bf heart.bf

The output (344 bytes):

    LOVELOVE        LOVELOVE
    LOVELOVE        LOVELOVE
LOVELOVELOVELOVELOVELOVELOVELOVE
LOVELOVELOVELOVELOVELOVELOVELOVE
LOVELOVELOVELOVELOVELOVELOVELOVE
LOVELOVELOVELOVELOVELOVELOVELOVE
    LOVELOVELOVELOVELOVELOVE
    LOVELOVELOVELOVELOVELOVE
        LOVELOVELOVELOVE
        LOVELOVELOVELOVE
            LOVELOVE
            LOVELOVE

Ungolfed EBF code:

>>--> ; mark

;; ##  ##@   
;;########@
;;########@
;; ######@
;;  ####@
;;   ##@
;; the block below is the art above 
;; where space is replaced with ->
;; # with > and @ with +>
->>>->->>>+>
>>>>>>>>+>
>>>>>>>>+>
->>>>>>>+>
->->>>>>+>
->->->>>+>+>

;; we store the string LOVE after a blank
>
~"LOVE"<[<]<
[<++] ;; add 2 to every cell until mark

;; Variables
:new
:zero
:in
:next

@zero
$in(
  -[ ; 1
     -[ ; 2
        $zero 10+.[-]
        $in-[#[-]$new<[-] @in] ; its second round lf
        $next[#$in++++$new<[[->>+<<]<]]@new     ; 2   
      ]
      >[[>]>[.>]<[<]<[<]<<++>   ]@new
  ]>[@next $zero 4+(-$in 8+) $in.... (-) $new+ $in]@zero
)
\$\endgroup\$
2
\$\begingroup\$

C# 224

class P{static void Main(){for(int i=0,m=1;i<30;i++)for(int l=0;l<new[]{5,6,7,6,8,10,3,10,4,13,1,13,1,87,1,27,4,23,7,20,11,16,16,11,20,7,24,3,27,1}[i];l++,m++)System.Console.Write((i%2>0?"love"[m%4]:' ')+(m%29>0?"":"\n"));}}

Formatted:

class P
{
    static void Main()
    {
        for (int i = 0, m = 1; i < 30; i++)
            for (int l = 0; l < new[] { 5, 6, 7, 6, 8, 10, 3, 10, 4, 13, 1, 13, 1, 87, 1, 27, 4, 23, 7, 20, 11, 16, 16, 11, 20, 7, 24, 3, 27, 1 }[i]; l++, m++)
                System.Console.Write((i % 2 > 0 ? "love"[m % 4] : ' ') + (m % 29 > 0 ? "" : "\n"));
    }
}

Output:

     velove       elovel
   ovelovelov   velovelove
 lovelovelovel velovelovelov
lovelovelovelovelovelovelovel
ovelovelovelovelovelovelovelo
velovelovelovelovelovelovelov
 lovelovelovelovelovelovelov
   elovelovelovelovelovelo
    ovelovelovelovelovel
      lovelovelovelove
         lovelovelov
           elovelo
             vel
              l
\$\endgroup\$
1
\$\begingroup\$

Perl - 97 characters

This answer is based on @Wasi's 121 character Python solution.

$.=love;say"   $.    $.$/$. $.$. $.$/$.   $.   $.";say$"x$_,$.,$"x(9-$_*2),$.for 0..4;say$"x 6,$.

You need to run perl with the -M5.010 option to enable 5.10-specific features. This is apparently allowed.

Interesting features:

  • I use the variable $. to store the word "love". This is because it can be immediately followed by another word if necessary. $.for is unambiguously tokenized as $. followed by for; $_for would not be tokenized as $_ followed by for because $_for is itself a legal variable name.
  • $", a built-in variable representing that character that arrays will be joined with when interpolated into a string (and defaults to a single space character) is used instead of " " for savings of one character here and there.
  • Perl's string interpolation beats the python .replace method significantly in code golfing.
  • Perl's for 0..4 similarly wins over for i in range(5)
\$\endgroup\$
1
\$\begingroup\$

CJam - 33 bytes

19285703234336595Zb["Love"SS+N]f=

Try it online

Output:

  Love    Love
LoveLoveLoveLove
LoveLoveLoveLove
LoveLoveLoveLove
  LoveLoveLove
    LoveLove
      Love

Explanation:

19285703234336595    number that contains the pattern as base-3 digits
Zb                   converts to base 3 (Z=3)
["Love"SS+N]         creates an array containing "Love", "  " and a newline
f=                   replaces the base-3 digits with the corresponding strings
                     (0 -> "Love", 1 -> "  ", 2 -> newline)
\$\endgroup\$
1
\$\begingroup\$

Python, 334 Bytes

x = "love"
print("\t  love\t      love")
print("\t"+str(x*2)+"    "+str(x*2))
print("      "+str(x*6))
print(str(" "*5)+str(x*6)+"lo")
print(str(" "*5)+str(x*6)+"lo")
print("      "+str(x*6))
print("\t"+str(x*5))
print("\t"+str(" "*2)+str(x*4)+"l")
print("\t"+str(" "*4)+str(x*3)+"l")
print("\t"+str(" "*7)+str(x*2))
print("\t"+str(" "*10)+"v")

output:

enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Welcome to PPCG. This is code golf, so please include the number of bytes of your code in the answer. Please also state what language this is. \$\endgroup\$ Feb 12, 2015 at 23:24
  • \$\begingroup\$ @MartinBüttner what language do you meant? and this is 334 bytes \$\endgroup\$
    – Yanti
    Feb 13, 2015 at 10:49
  • 1
    \$\begingroup\$ The programming language you've written this code in. \$\endgroup\$ Feb 13, 2015 at 10:50
  • \$\begingroup\$ I know ! This is Python ! Oh and you can remove the str call with string repetions, because * has a higher precedence than +. \$\endgroup\$ Jun 17, 2016 at 19:04
  • \$\begingroup\$ Actually, this code is 682 bytes long. \$\endgroup\$ Jun 17, 2016 at 20:32
0
\$\begingroup\$

Bash, 170 bytes

totally a copy of programFOX's :)

echo '\x1f\x8b\x08\x00\x95\x10\xe0R\x02\xffSPP\xf0\xc9/KU\x80\x03\x10\x8f\x0bB\xa1c.l\x82dJ\xe0\xb0\x01\xe6\x02\x0cATa.T\xf7\x02\x00\xd9\x91g\x05\xc5\x00\x00\x00'|gunzip
\$\endgroup\$
0
\$\begingroup\$

print('\n'.join([''.join([(' Your text here'[(x-y) % len(' Enter same text here')] if ((x0.05)**2+(y0.1)**2-1)**3-(x*0.05)2(y0.1)**3 <= 0 else ' ') for x in range(-30, 30)]) for y in range(30, -30, -1)]))enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to the site. Is this python? Could you use proper formatting and say a little bit about your answer? You can get the formatting a couple of ways but you should be able to highlight your code and select a button in the ui to make it format as code. \$\endgroup\$
    – Wheat Wizard
    Jan 14, 2021 at 6:55

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