Reto
Dibujar un corazón
... como el arte ASCII!
Tu arte no tiene que parecerse exactamente al mío, pero tiene que verse como una forma de corazón.
El interior del corazón debe contener las palabras "Amor" al menos 20 veces
Reglas
- El programa debe escribir el arte en la consola.
- El código más corto (en bytes, cualquier idioma) gana.
El ganador será elegido el 14 de febrero en el día de San Valentín.
:D
popularity-contest
Respuestas:
JavaScript [160 bytes]
El siguiente código parece tener 160 bytes sin formato.
Simplemente ejecute esto en la consola del navegador (por ejemplo, en Firebug o Chrome Dev Tools).
fuente
/[lve]\d/
a/../
y el uso de matriz['','Love','\n']
en lugar de objeto salvará otros 10 bytes que conducen a 150 bytes en total, pero el corazón fuente no será tan bien en forma de más:)
function(c){return
porc=>
y quitar}
. ¡Deberías publicar una versión más corta!:)
Pero gracias por señalarlo! Espero que pronto JavaScript compita con Perl y Python en asuntos de golf y todos puedan probarlo.GolfScript:
62 625754 caracteresSalida:
O, por un poco de amor adicional, y el abuso obligatorio de la insignificancia del espacio en blanco (para 84 caracteres):
Salida:
fuente
C - 183 bytes
Not a winner, but a whole lotta love. Can you figure out how it works?
Output:
fuente
V
at the bottom.C
! The heart curve is public domain :)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:This is the output:
fuente
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:
Or, if you prefer (still valid code!)
Prints out two semicircles and a triangle to the screen, making a pretty decent facsimile of a heart.
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.fuente
Python 2, 117
prints exactly 20
love
s horizontally.output:
fuente
replace()
them; in the 3rd line'sprint
change one+
to,
and 10 with 9; in the last line use variable x's value. pastebin.com/i1TSEZfElove
s on the right side that you got by staggering the horizontallove
s?love
s. Including those thelove
count will be 23 :DPerl - 36 bytes
Output:
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:Perl - 60 bytes
Outputs the following:
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 befor 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 eachLove
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.fuente
-e
)$"
with' '
:perl -e "print' 'x(15&ord),Love,$/x/\D/for'3h112a05e0n1l2j4f6b9'=~/./g"
Wolfram Language (Mathematica) - 111
fuente
Javascript -
147141137133 charactersNote : I posted another answer, but this one use different approach and heart has a different shape.
How it works :
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).fuente
0
before floating numbers and assigningMath.abs
to a variable.Sclipting — 28 chars / 56 bytes
Output:
fuente
긢꼙겱딧꽔밂各감啃갰啃긂밀⓶復냄뭖끐⓷復겠⓸復終
— but this uses the啃
instruction, which I added after this challenge was posted, so it doesn’t count.)JavaScript -
136121115113 charactersTo run : copy paste into browser console (eg : Chrome or Firefox)
fuente
["L","o","v","e"] => "Love"
will save 11 bytes.C, 116 chars
(I don't know if this is heart-shaped enough... fills the inside of three circles to produce the output.)
Output:
Earlier in the golfing process, before replacing constant expressions (change
M
to adjust size):I also felt compelled to do this. :P
fuente
All variables in C are typed
en.wikibooks.org/wiki/C_Programming/Variablesint
, a legacy feature borrowed from pre-ANSI-C. It compiles just fine for me withclang foo.c
orgcc -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.Ruby, 47, or Golfscript, 41
Boring answer.
Golfscript version:
Output:
fuente
Ruby - 113 Characters
Output:
To be more clear
fuente
Perl - 159 characters
Not massively golfed...
Here's the same with added whitespace for slightly better readability...
Output is...
The complete word "Love" is contained within (vertically) 22 times, plus numerous partials.
fuente
APL, 36 chars / bytes*
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"
fuente
Extended BrainFuck : 193 (counted without non essential whitespace)
Turns into:
Brainfuck: 264 (counted without non essential whitespace)
You run it with any bf interpreter. Ubuntu has
bf
andbeef
and both works nicely.The output (344 bytes):
Ungolfed EBF code:
fuente
C# 224
Formatted:
Output:
fuente
Python, 334 Bytes
output:
fuente
str
call with string repetions, because*
has a higher precedence than+
.Perl - 97 characters
This answer is based on @Wasi's 121 character Python solution.
You need to run perl with the
-M5.010
option to enable 5.10-specific features. This is apparently allowed.Interesting features:
$.
to store the word "love". This is because it can be immediately followed by another word if necessary.$.for
is unambiguously tokenized as$.
followed byfor
;$_for
would not be tokenized as$_
followed byfor
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..replace
method significantly in code golfing.for 0..4
similarly wins overfor i in range(5)
fuente
CJam - 33 bytes
Try it online
Output:
Explanation:
fuente
Bash, 170 bytes
totally a copy of programFOX's :)
fuente