用您喜欢的语言做一个情人节愿望[关闭]


13

编写最具创意的程序,以您喜欢的编程语言显示您的情人愿望。

例如

#!/usr/bin/perl

use Modern::Perl;

say "I love Perl";

@ugoren已接受
Wordzilla 2014年

Answers:


38

C / Python多语种/一夫多妻

一夫一妻制并不适合所有人。
根据我对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();

输出,当以C运行时:

C, I love you much more than Python

作为Python运行时的输出:

Python , I love you much more than  C

11
这真是太棒了。
亚当·玛拉斯

24

JavaScript(ES6)

漂亮版本:

           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);

控制台输出:

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

带注释的版本:

[
  // 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');

13

处理中

public static final int px = 25;
public static final int rectRad = 3;
PFont font;

public boolean[][] used;
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(500, 500);
  background(255);
  stroke(127+64);
  strokeWeight(1.75);
  //font=loadFont("Font1.vlw");
  font=createFont("Purisa",28);
  textFont(font,28);
  frameRate(50);
  used = new boolean[width/px][height/px]; // initialised to false by default
}

void draw() {
  int i, j;
  int drawingframes = width * height / px / px;
  int textframesdelay = (int)(500 * frameRate / 1000);
  do {
    i=(int)random(0, width / px);
    j=(int)random(0, height / px);
  } while(used[i][j] && frameCount <= drawingframes);
  used[i][j] = true;
  if(frameCount > drawingframes + textframesdelay) {
    noLoop();
    return;
  } else if(frameCount == drawingframes + textframesdelay) {
    fill(63 + 32);
    text("Dear Processing,", 10, 50);
    text("Happy Valentine's Day!", 80, 200);
    text("Love,\nAce", 10, 430);
    return;
  } else if(frameCount > drawingframes) {
      return; // effectively creating a small delay after drawing the tiles
              // and before writing the text
  }
  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 * width / px + i;
  if(java.util.Arrays.binarySearch(heart,hash)>=0) {
  //if(heart.indexOf(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);
}

看到它在这里在线运行。

一种可能的输出的屏幕截图: 在此处输入图片说明


3
好一个。我很喜欢它。
Merin Nakarmi 2014年

8

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,<@

输出(作为图像,因为它在控制台中看起来比这里更好):



3

重击

有什么比通过SSH连接到您的妻子/丈夫的计算机更好,然后让她的NIC用最喜欢的脚本语言为“情人节快乐”闪烁莫尔斯电码的有趣部分呢?我敢肯定,您几乎都是从-BASH开始的?正如我们的极客所知道的那样-您应该始终注意机器的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

当然,“摩尔斯”包含摩尔斯电码“翻译”为数字:

111131231221312213212231112312312113132132311321313111321131232122

“ 1”短,“ 2”长,“ 3”是空格。显然,必须安装强制性的“ ethtool”。如果不是,那么请您的配偶这样做。


3

基本知识

仅仅因为我们都曾经写过其中一种,而这实际上是唯一能真正表达这种语言简单诚实的心的风格。

10 PRINT "HAPPY VALENTINES DAY BASIC"
20 GOTO 10

3

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]]

在此处输入图片说明

那是Taubin的心。是的,我意识到挑战需要ASCII艺术。但是,如果您要对其投票,请不要这么做,因为它太漂亮了,请这样做,因为我从/math/12098/drawing-heart-in-mathematica中窃取了代码


2

〜-〜!

仅出于兴趣考虑,字符数为865

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

输出:

 ____   ____
/    \ /    \
|           |
\ I <3 ~-~! /
 \         /
  \       /
   \     /
    \   /
     \ /

2

蟒蛇

还记得人们何时没有用于情人节的计算机,而不得不将自己的爱情生活刻在树上吗?那就是我在做什么:

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')

注意:inside变量的前值是硬编码的。输出:

  ___    ___
 /   \  /   \ 
/     \/     \ 
|Me           |
|      +     |
 \    Python/
  \        /
   \      /
    \    /
     \  /
      \/

但是代码不使用任何树。
ugoren

-3

嗯,是这样的吗?

<?echo "I love PHP";


14
这是一场人气竞赛-发挥创意。
2014年

-3
#include<stdio.h>
#include<conio.h>
main();
{
  int i, n;
   printf(" enter n=");
    scanf("%d",&n);
         for(i=0;i<n;i++)
      {
          printf(" i love you honey ");
      }  
         scanf("%d",&i);
        getch();
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.