Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Write the most creative program to display your Valentine wish to your favorite programming language, in that language.

E.g.

#!/usr/bin/perl

use Modern::Perl;

say "I love Perl";
share|improve this question
    
Isn't it time to accept an answer? –  ugoren Feb 19 at 13:16
    
Accepted @ugoren –  Wordzilla Feb 21 at 8:19
add comment

11 Answers

up vote 21 down vote accepted

C/Python Polyglot/Polygamist

Monogamy isn't for everyone.
Based on my answer to Execute Prints Backwards.

#define def main(){0?
#define print printf(
#define return 0)));}

def main():
    print "Python",
    print ", I love you much more than ",
    print "C",
    return

main();

Output, when run as C:

C, I love you much more than Python

Output, when run as Python:

Python , I love you much more than  C
share|improve this answer
6  
This is freaking brilliant. –  Adam Maras Feb 13 at 22:33
add comment

JavaScript (ES6)

Pretty version:

           r=/c/g         ,n='\n'
       ,m=/.\d+/g,[,    ,'ca','8b',5,
     'a10b',6,'ca3b',  13,'a4b',1,3,'c'
    ,'a1b',16,'a2b1',5,'cb35cb',35,'ca',
    ,'1b7 JS b',22,'ca2b',31,'ca3b',29,
     ,'ca',5,'b',25,'ca7b',2,1,'ca',9,
      ,'b','17ca',11,'b13ca',14,'b',
       '7c','a1',7,'b1c'].join('').
         replace(m, c=>(c[0]!='a'?
           '\u2665':' ').repeat
              (+c.substr(1))).
                 replace(r,
                     n);

Console output:

            ♥♥♥♥♥          ♥♥♥♥♥♥
       ♥♥♥♥♥♥♥♥♥♥♥♥♥    ♥♥♥♥♥♥♥♥♥♥♥♥♥
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
     ♥♥♥♥♥♥♥ JS ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
       ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
         ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
           ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
             ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
               ♥♥♥♥♥♥♥♥♥♥♥♥♥
                  ♥♥♥♥♥♥♥
                     ♥

Annotated version:

[
  // Contains the instruction to draw the heart.
  //   * `a` is a space
  //   * `b` is a heart
  //   * `c` is a line break
  // 
  // `a` and `b` instructions are followed by an integer
  // telling how many times the character should be printed.
  // 
  // Abuse JS arrays to split the string in smaller parts.
  ,,'ca','8b',5,'a10b',6,'ca3b',13,'4b13ca1b16a2b1cb35cb35ca1b7'
  // This is the text we want to display.
  ,' JS '
  // Other instructions to draw the heart.
  // This part isn't splitted for readability purpose.
  ,'bca2bca3b29ca5b25ca7b21ca9b17ca11b13ca14b7ca17b1c'
]
// Join every substring.
.join('')
// Process instructions.
.replace(
  // Match all `a` and `b` instructions.
  /.\d+/g,
  c => (
    // Fetch the right character.
    c[0] != 'a'
      ? '\u2665' // `b` Heart
      : ' '      // `a` Space
  )
  // Repeat the character.
  .repeat(
    // Extract the number from the instruction.
    +c.substr(1)
  )
)
// Replace `c` by a line break.
.replace(/c/g,'\n');
share|improve this answer
add comment

Processing

public static final int px=25;
public static final int ht=500, wth=500;
public static final int rectRad = 3;
PFont font;

public boolean[][] used = new boolean[wth/px][ht/px];
public int[] heart = {
               65, 66, 67,                 72, 73, 74,
           84, 85, 86, 87, 88,         91, 92, 93, 94, 95,
      103,104,105,106,107,108,109,110,111,112,113,114,115,116,
  122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,
  142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,
  162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,
      183,184,185,186,187,188,189,190,191,192,193,194,195,196,
          204,205,206,207,208,209,210,211,212,213,214,215,
          224,225,226,227,228,229,230,231,232,233,234,235,
              245,246,247,248,249,250,251,252,253,254,
                  266,267,268,269,270,271,272,273,
                      287,288,289,290,291,292,
                          308,309,310,311,
                              329,330
                                 };

void setup(){
  size(ht,wth);
  background(255);
  stroke(127+64);
  strokeWeight(1.75);
  font=createFont("Purisa",28);
  textFont(font,28);
  int i,j;
  for(i=0;i<wth/px;i++) for(j=0;j<ht/px;j++) used[i][j]=false;
}

boolean noLoopFlag=false;
void draw(){
  int i,j,unusedCount=0;
  for(i=0;i<ht/px;i++) for(j=0;j<wth/px;j++) if(!used[i][j]) unusedCount++;
  do {
    i=(int)random(0,wth/px);
    j=(int)random(0,ht/px);
  } while(used[i][j]&&unusedCount>0);
  used[i][j]=true;
  if(noLoopFlag) {
    noLoop();
    return;
  }
  if(unusedCount==0) {
    fill(63+32);
    text("Dear Processing,",10,50);
    text("Happy Valentine's Day!",80,200);
    text("Love,\nAce",10,430);
    delay(500);
    noLoopFlag=true;
    return;
  }

  int R=(int)random(64,255-64);
  int G=(int)random(128,255);
  int B=(int)random(128,255);
  int alpha=(int)random(55,85);

  int hash=j*wth/px+i;
  if(java.util.Arrays.binarySearch(heart,hash)>=0) {
    R=(int)random(128+64, 255);
    G=(int)random(0,63);
    B=(int)random(0,63);
    alpha=(int)random(70,100);
  }

  fill(R,G,B,alpha);
  rect(i*px, j*px, px, px, rectRad, rectRad, rectRad, rectRad);
  delay(20);
}

Not some very well written code, but it works nicely

See it run online here.

Or if you don't want to run the java applet to see the animation, here is one possible output: enter image description here

share|improve this answer
2  
Nice one. I enjoyed it. –  Merin Nakarmi Feb 11 at 17:48
add comment

Befunge 98

"/\ "7k:a"/ ":"\ "6k:a"/ "2k:"\ "5k:a"/ ":"89 ":"\ "4k:a"/ "6k:"\ "3k:a"| ":"egnufeB | "2k:a"| "8k:"| "2k:a"\ /____\ / "3k:a'_' 5k:'_\4k:a"?enitnelaV ym eb uoy lliW"aa >:!2+j4,<@

Output (as image, because it looks nicer in the console than here):

share|improve this answer
add comment

BASH

What is better than to SSH to your wifeys/husbands machine and then let her NIC do the fun part of flashing morse code for "Happy Valentines Day" for your favourite scripting language I am sure you've nearly all started with - BASH? And as we Geeks all know - you should always have an eye on your machine's NIC ;)

#!/bin/bash

#.... .- .--. .--. -.-- ...- .- .-.. . -. - .. -. . ... -.. .- -.--
#1111 12 1221 1221 2122 1112 12 1211 1 21 2 11 21 1 111 211 12 2122

while IFS= read -r -n1 char
do
    ethtool eth0 p$char
done < morse

Of course "morse" contains the morse code "translated" to numbers:

111131231221312213212231112312312113132132311321313111321131232122

'1' is short, '2' is long and '3' is space. Obviously the obligatory 'ethtool' should be installed. If not, then do your spouse the favour of doing so.

share|improve this answer
add comment

PHP

Why overcomplicate, when you can do simplest thing that works?

Program:

I ♥ PHP!

Output:

I ♥ PHP!
share|improve this answer
2  
It's not about the shortest code - it's about the most creative and beautiful one. –  german_guy Feb 11 at 20:07
add comment

BASIC

Just because we all wrote one of these once, and this is really the only style that truly expresses this language's simple honest heart.

10 PRINT "HAPPY VALENTINES DAY BASIC"
20 GOTO 10
share|improve this answer
add comment

Python

Remember when people didn't have computers for Valentines and had to etch their lovelife on trees? That's what I'm doing:

def valentine(person1,person2):
    leading_whitespace = range(0,4)[::-1] +[0]+range(0,8)
    inside = [3,5,14,14]+range(0,15)[::-1][::2]
    layers = ["  ___    ___",r" /   \  /   \ ",r'/     \/     \ ','|             |']
    for i in range(5,12):
        layers.append(' ' * leading_whitespace[i] + '\\' + ' ' * inside[i] + '/')
    #inserts person1 into layers[4]
    temp = []
    for char in layers[3]: temp.append(char)
    temp[1:len(person1)+1] = person1
    layers[3] = ''.join(temp)

    temp = []
    layers[4] = '|      +     |'

    # do that again for person2
    for char in layers[5]: temp.append(char)
    temp[-len(person2)-1:-1] = person2
    layers[5] = ''.join(temp)

    print '\n'.join(layers)

valentine('Me','Python')

Note: the first values of the inside variable are hard-coded. Output:

  ___    ___
 /   \  /   \ 
/     \/     \ 
|Me           |
|      +     |
 \    Python/
  \        /
   \      /
    \    /
     \  /
      \/
share|improve this answer
    
But the code doesn't use any trees. –  ugoren Feb 14 at 15:20
add comment

mhm is it something like this ?

<?echo "I love PHP";

share|improve this answer
8  
It's a popularity contest - get creative. –  unclemeat Feb 11 at 6:09
add comment

~-~!

Just for the sake of interest, the character count is 865.

'=~~~~:''=<<'+~>,'+~~~>,':'''=<'+~>,<',<'+~>-~>:''''=<'+~>,<<',~~>+~>+~~:'''''=',',~~:''''''=',<<'+~>,<'+~~>+~>:'''''''=',~~+~~:
@''''':@''':@''':@''':@''':@''''':@''''':@''''':@''':@''':@''':@''':@''''''':
@'''':@''''':@''''':@''''':@''''':@'':@''''':@'''':@''''':@''''':@''''':@''''':@'':@''''''':
@'''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@'''''':@''''''':
@'':@''''':@|I|:@''''':@|<|:@|3|:@''''':@|~|:@|-|:@|~|:@|!|:@''''':@'''':@''''''':
@''''':@'':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@'''':@''''''':
@''''':@''''':@'':@''''':@''''':@''''':@''''':@''''':@''''':@''''':@'''':@''''''':
@''''':@''''':@''''':@'':@''''':@''''':@''''':@''''':@''''':@'''':@''''''':
@''''':@''''':@''''':@''''':@'':@''''':@''''':@''''':@'''':@''''''':
@''''':@''''':@''''':@''''':@''''':@'':@''''':@'''':@''''''':

Output:

 ____   ____
/    \ /    \
|           |
\ I <3 ~-~! /
 \         /
  \       /
   \     /
    \   /
     \ /
share|improve this answer
add comment

Mathematica

ContourPlot3D[(2 x^2 + y^2 + z^2 - 1)^3 - (1/10) x^2 z^3 - y^2 z^3 == 
  0, {x, -1.5, 1.5}, {y, -1.5, 1.5}, {z, -1.5, 1.5}, Mesh -> None, 
 ContourStyle -> Opacity[0.8, Red]]

enter image description here

That's Taubin's heart surface. Yes, I realize the challenge asks for ASCII art. However, if you're going to downvote it, don't do so because it's excessively beautiful, do it because I stole the code from http://math.stackexchange.com/questions/12098/drawing-heart-in-mathematica

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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