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

No comments:

Post a Comment

ANOTHER BIBLE VERSE OF THE DAY: Daniel 10:3

   I ate no choice food; no meat or wine touched my lips; and I used no lotions at all until the three weeks were over. - Daniel 10:3 --- UN...