Monday, March 25, 2024
CODE GOLF & CODING CHALLENGE | Draw a Heart shape
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).
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 :) –
Using fat arrow function will save a lot of bytes. Replace function(c){return by c=> and remove }.
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♥
♥
READ ALSO
https://codegolf.stackexchange.com/questions/19123/draw-the-heart-shape
Subscribe to:
Post Comments (Atom)
NOW BOLE INTERNATIONAL AIRPORT, ADDIS ABABA, ETHIOPIA HAS CHANGED ITS NAME TO DEMBIDOLO AIRPORT, ADDIS ABABA, ETHIOPIA.
Now Bole International Airport, Addis Ababa, Ethiopia has changed its name to Dembidolo Airport, Addis Ababa, Ethiopia. This change is pa...
.jpeg)
-
https://youtu.be/H0u8yO9kiAA?si=H0a36r89qs2o-W3Z
-
መንግስታት እና መሪዎች ይቀያየራሉ፤ ነገር ግን የመከላከያ ሰራዊት ተግባር እና ሃላፊነት የሀገሪቱን ደህንነት ማስጠበቅ ነው። ስለሆነም የኢፌድሪ (የፌደራል) መከላከያ ሰራዊት በጥንቃቄ እና በሰላም ወደ ተቀደሰ ስፍራዬ ...
-
I firmly believe that the current Secretary General of the United Nations, António Guterres, constitutes a historic mistake on the part o...
No comments:
Post a Comment