420 <s> Blaze </s> Golf It


10

Questa è una sfida piuttosto semplice, ma (spero) divertente.

Compito

Se in questo momento o il mese è 4e il giorno è 20, l'ora (su un orologio di 12 ore) è 4e il minuto è 20, o il minuto è 4e il secondo è 20, stampa questa arte ascii:

                        .
                       .:.
                       :|:
                      .:|:.
                      ::|::
       :.             ::|::             .:
       :|:.          .::|::.          .:|:
       ::|:.         :::|:::         .:|:;
       `::|:.        :::|:::        .:|::'
        ::|::.       :::|:::       .::|:;
        `::|::.      :::|:::      .::|::'
         :::|::.     :::|:::     .::|::;
         `:::|::.    :::|:::    .::|::;'
`::.      `:::|::.   :::|:::   .::|::;'     .:;'
 `:::..    `;::|::.  :::|:::  .::|:::    ::::;
   `:::::.    ':|::. :::|::: .::|:'   ,::::;'
     `:::::.    ':|:::::|:::::|:'   :::::;'
       `:::::.:::::|::::|::::|::::.,:::;'
          ':::::::::|:::|:::|:::::::;:'
             ':::::::|::|::|:::::::''
                  `::::::::::;'
                 .:;'' ::: ``::.
                      :':':
                        ;

Puoi avere spazi finali.

Altrimenti, stampa il numero di minuti e secondi rimasti fino alla prossima occasione nel formato: %d minutes and %d seconds left until your next hit.con il tempo ridotto al minimo.

Questo è , quindi vince il codice più breve in byte !

PS Se questa sfida è troppo inappropriata per questo sito, dimmelo e lo cambierò.


15
Non sei nella prima metà del liceo? : P
Arcturus,

Inoltre, le 4:00 PM (in un orario altrimenti non stampabile) vengono conteggiate come stampa-y per via delle 4 o non-stampa perché sono anche le 16:00 ore?
Arcturus,

4
Sarei più preoccupato che si tratti di un doppione, mi sento come se due metà di vecchie sfide (le varie tempistiche e le varie kgc) non lo rendessero davvero una sfida molto interessante, ma non sono sicuro di cosa Lo chiuderei come un duplicato di (o se è anche corretto farlo ...).
FryAmTheEggman,

@ ANerd-I principe, lo modificherò in.
Maltysen

Stavo guardando questa immagine e mi chiedevo se una sorta di codifica di lunghezza personalizzata sarebbe praticabile per il golf dell'output o se esiste una soluzione migliore?
Patrick Roberts,

Risposte:


6

Python 2, 371 byte

Questa fonte contiene byte non stampabili, quindi viene presentata come un dump esadecimale che può essere decodificato xxd -r.

00000000: efbb bf66 726f 6d20 7469 6d65 2069 6d70  ...from time imp
00000010: 6f72 742a 0a74 3d74 696d 6528 290a 693d  ort*.t=time().i=
00000020: 300a 7768 696c 6527 3034 3a32 3027 6e6f  0.while'04:20'no
00000030: 7420 696e 2073 7472 6674 696d 6528 2725  t in strftime('%
00000040: 6d3a 2564 2572 272c 6c6f 6361 6c74 696d  m:%d%r',localtim
00000050: 6528 742b 6929 293a 692b 3d31 0a70 7269  e(t+i)):i+=1.pri
00000060: 6e74 5b22 7801 74cd c701 c430 0844 d1bb  nt["x.t....0.D..
00000070: aaf0 cd99 0286 6654 887a dfa0 f41d 7136  ......fT.z....q6
00000080: 8f61 7829 0b6f 5c72 bdb6 9414 de86 d2eb  .ax).o\r........
00000090: 9894 d4e7 64f7 de39 099a 8ed8 32b5 d34a  ....d..9....2..J
000000a0: e8c9 2a53 9da4 371a b1d0 a3d4 18e8 b212  ..*S..7.........
000000b0: 5a25 a139 158a ac90 4cba 7692 4007 c62e  Z%.9....L.v.@...
000000c0: 81b8 31c4 9682 04e2 6ab8 8f21 3bb3 3ce1  ..1.....j..!;.<.
000000d0: 7582 0163 8524 79a8 c175 cb58 7ce5 45ff  u..c.$y..u.X|.E.
000000e0: b3b7 8cc7 bfbe fbaa 9b95 b068 1837 db90  ...........h.7..
000000f0: a546 b54a 5cb9 5c38 6801 0936 a2a8 a85e  .F.J\.\8h..6...^
00000100: 6ca3 4c3e 8e83 a4ef 1412 12ac 7027 7075  l.L>........p'pu
00000110: 2084 ca61 026b 5c30 286e a1fe 222e 6465   ..a.k\0(n..".de
00000120: 636f 6465 2827 7a69 7027 292c 2725 6420  code('zip'),'%d 
00000130: 6d69 6e75 7465 7320 616e 6420 2564 2073  minutes and %d s
00000140: 6563 6f6e 6473 206c 6566 7420 756e 7469  econds left unti
00000150: 6c20 796f 7572 206e 6578 7420 6869 742e  l your next hit.
00000160: 2725 2869 2f36 302c 6925 3630 295d 5b69  '%(i/60,i%60)][i
00000170: 3e30 5d                                  >0]

Parte leggibile:

from time import*
t=time()
i=0
while'04:20'not in strftime('%m:%d%r',localtime(t+i)):i+=1
print["(ZLIB DATA)".decode('zip'),'%d minutes and %d seconds left until your next hit.'%(i/60,i%60)][i>0]

Oh spiacenti, ho letto male il codice. L'ho pensato continuamente in loop e stampato. Stupido piccolo schermo mobile.
Mego

4

JavaScript (ES6), 537 byte

alert((f=t=>new Date(Date.now()+t*1e3).toISOString().match`(T16|04)[-:]20`)(i=0)?"À\u0019\u0002û1!°?4\u0002ë14!°>C3\u0002=\u0001Ê34\u0003Ê1\u0002=4\u00011C3\u000114\u0002=C\u0013ð4\u0009\u001fCS\u0002m34\u0001>Ià14s\u0002>C3\u0001=IÐ1CS\u0002n34\u0013À4\u0009\u001c34s\u0002?I3\u0001;I°1C3%ð6I3\u0001:I 1C3ub3\u0001l4\u00134\u0009\u001934S\u0007\u001bS'`\u0011 V34\u0013\u00004\u0009\u001034\u0009:Z\u0002i³\u0001zC3\u00014\u00091Cs8Z'°6\u001b 74K³4\u00079['Ð6\u001b³4J£4\u001a8Y' yó4I4]s\u0002Ê7M34CÓw\u0002«6u\u00021u\u0007`6\u0013\u0002ëss#ÀY".replace(/./g,c=>(l=" .\n:|;`',0123456")[(n=c.charCodeAt())&15]+l[n>>4]).replace(/.\d+/g,c=>c[0].repeat(parseInt(c.slice(1),7)+3)):eval('for(;!f(++i););`${i/60|0} minutes and ${i%60|0} seconds left until your next hit.`'))

Utilizza la codifica CP-1252.

Nota: tutti i file illeggibili in questo post sono salvati in \u00xxmodo che il sistema Stack Exchange non li rimuova automaticamente. Dovrebbero essere considerati avere una dimensione di un byte.

Spiegazione

Utilizza uno schema di codifica di lunghezza pari a impacchettare ogni carattere in 4 bit. La logica principale del codice è di 174 byte e la stringa foglia (compresa la decompressione) è di 364 byte. Ulteriori dettagli sul metodo di compressione sono disponibili di seguito.

alert((
  f=t=>                                   // f checks for 4:20 in a date
    new Date(Date.now()+t*1e3)            // get the date at now + t seconds
    .toISOString().match`(T16|04)[-:]20`  // find 4:20 in the ISO date string
)(i=0)?

  // Leaf decompression
  "À\u0019\u0002û1!°?4\u0002ë14!°>C3\u0002=\u0001Ê34\u0003Ê1\u0002=4\u00011C3\u000114\u0002=C\u0013ð4\u0009\u001fCS\u0002m34\u0001>Ià14s\u0002>C3\u0001=IÐ1CS\u0002n34\u0013À4\u0009\u001c34s\u0002?I3\u0001;I°1C3%ð6I3\u0001:I 1C3ub3\u0001l4\u00134\u0009\u001934S\u0007\u001bS'`\u0011 V34\u0013\u00004\u0009\u001034\u0009:Z\u0002i³\u0001zC3\u00014\u00091Cs8Z'°6\u001b 74K³4\u00079['Ð6\u001b³4J£4\u001a8Y' yó4I4]s\u0002Ê7M34CÓw\u0002«6u\u00021u\u0007`6\u0013\u0002ëss#ÀY"
  .replace(/./g,c=>                       // unpack each 4-bit character
    (l=" .\n:|;`',0123456")               // l = lookup table of characters
    [(n=c.charCodeAt())&15]+l[n>>4]       // return the two characters in the byte
  )
  .replace(/.\d+/g,c=>                    // run-length decoding
    c[0].repeat(parseInt(c.slice(1),7)+3) // repeat character n + 3 times (base-7)
  )

:eval(`                                   // eval just to allow a for loop here...
  for(;!f(++i););                         // check each second up until a match

  \`${i/60|0} minutes and ${i%60|0} seconds left until your next hit.\`
`))

Algoritmi di compressione

Nessuna compressione, 911 byte

Questa è la stringa foglia senza alcuna compressione.

`                        .
                       .:.
                       :|:
                      .:|:.
                      ::|::
       :.             ::|::             .:
       :|:.          .::|::.          .:|:
       ::|:.         :::|:::         .:|:;
       \`::|:.        :::|:::        .:|::'
        ::|::.       :::|:::       .::|:;
        \`::|::.      :::|:::      .::|::'
         :::|::.     :::|:::     .::|::;
         \`:::|::.    :::|:::    .::|::;'
\`::.      \`:::|::.   :::|:::   .::|::;'     .:;'
 \`:::..    \`;::|::.  :::|:::  .::|:::    ::::;
   \`:::::.    ':|::. :::|::: .::|:'   ,::::;'
     \`:::::.    ':|:::::|:::::|:'   :::::;'
       \`:::::.:::::|::::|::::|::::.,:::;'
          ':::::::::|:::|:::|:::::::;:'
             ':::::::|::|::|:::::::''
                  \`::::::::::;'
                 .:;'' ::: \`\`::.
                      :':':
                        ;`

Codifica run-length, 542 byte

Dato che ci sono molti caratteri ripetuti consecutivi, la codifica della lunghezza di esecuzione migliora significativamente il conteggio dei byte.

` 21.
 20.:.
 20:|:
 19.:|:.
 19::|::
 4:. 10::|:: 10.:
 4:|:. 7.::|::. 7.:|:
 4::|:. 6:0|:0 6.:|:;
 4\`::|:. 5:0|:0 5.:|::'
 5::|::. 4:0|:0 4.::|:;
 5\`::|::. 3:0|:0 3.::|::'
 6:0|::. 2:0|:0 2.::|::;
 6\`:0|::. 1:0|:0 1.::|::;'
\`::. 3\`:0|::. 0:0|:0 0.::|::;' 2.:;'
 \`:0.. 1\`;::|::.  :0|:0  .::|:0 1:1;
 0\`:2. 1':|::. :0|:0 .::|:' 0,:1;'
 2\`:2. 1':|:2|:2|:' 0:2;'
 4\`:2.:2|:1|:1|:1.,:0;'
 7':6|:0|:0|:4;:'
 10':4|::|::|:4''
 15\`:7;'
 14.:;'' :0 \`\`::.
 19:':':
 21;`.replace(/.\d+/g,c=>c[0].repeat(+c.slice(1)+3))

Ogni carattere ripetuto 3 o più volte viene sostituito dal carattere seguito da un numero decimale di amount - 3. La stringa codificata viene generata con questo codice:

uncompressed.replace(/(.)\1{2,}/g,c=>c[0]+(c.length-3))

Packing a 4 bit + RLE, 364 byte

Ci sono 9 caratteri distinti nella stringa originale, il che significa che 4 è il numero minimo di bit per rappresentarli. Convenientemente, ciò consente di inserire esattamente due rappresentazioni di caratteri in un singolo byte, consentendo di utilizzare un algoritmo di decompressione semplice (e adatto al golf). Inoltre, ci sono 7 caratteri rimasti, che consente di utilizzare la codifica di lunghezza di base 7 prima dell'imballaggio. Mettere ciascun indice a 4 bit negli stuzzichini superiori e inferiori di ciascun carattere compresso significa che sono memorizzati 2 caratteri per byte, poiché la codifica CP-1252 codifica ogni carattere sotto il punto di codice 256 come un singolo byte.

"À\u0019\u0002û1!°?4\u0002ë14!°>C3\u0002=\u0001Ê34\u0003Ê1\u0002=4\u00011C3\u000114\u0002=C\u0013ð4\u0009\u001fCS\u0002m34\u0001>Ià14s\u0002>C3\u0001=IÐ1CS\u0002n34\u0013À4\u0009\u001c34s\u0002?I3\u0001;I°1C3%ð6I3\u0001:I 1C3ub3\u0001l4\u00134\u0009\u001934S\u0007\u001bS'`\u0011 V34\u0013\u00004\u0009\u001034\u0009:Z\u0002i³\u0001zC3\u00014\u00091Cs8Z'°6\u001b 74K³4\u00079['Ð6\u001b³4J£4\u001a8Y' yó4I4]s\u0002Ê7M34CÓw\u0002«6u\u00021u\u0007`6\u0013\u0002ëss#ÀY"
.replace(/./g,c=>(l=" .\n:|;`',0123456")[(n=c.charCodeAt())&15]+l[n>>4])
.replace(/.\d+/g,c=>c[0].repeat(parseInt(c.slice(1),7)+3))

Il seguente codice viene utilizzato per eseguire la codifica e l'imballaggio della lunghezza di esecuzione:

chars="",max=16;
[...uncompressed].map(c=>~chars.indexOf(c)?0:chars+=c);
base=max-chars.length;
chars+=[...Array(base).keys()].join``;
unpacked=uncompressed.replace(/(.)\1{2,}/g,c=>c[0]+(c.length-3).toString(base));
packed=unpacked.replace(/(.|\n){2}/g,s=> // Note: unpacked length must be even!
  String.fromCharCode(chars.indexOf(s[0])|(chars.indexOf(s[1])<<4)));

Huffman Coding, (Possibile miglioramento futuro)

Alcuni caratteri sono presenti molto più di altri, quindi una codifica Huffman (numeri interi a lunghezza variabile che rappresentano ciascun carattere) potrebbe salvare alcuni byte aggiuntivi. Tuttavia questo introdurrà molta più complessità nell'algoritmo di decompressione, quindi oltre ad essere molto più lavoro può anche costare più byte per decomprimerlo di quanto non risparmi nella stringa codificata.


Ho provato a usare la stessa compressione che ho fatto per la mia risposta di Pasqua, ma ci vogliono 421 byte solo per riprodurre la stringa.
Neil,

3

Javascript ES6, 905 byte

Accidenti ... L'orologio da 12 ore ha ucciso la mia soluzione altrimenti breve ( ahum ).
905 byte per stampare 898 caratteri di ascii art yay

_=>(a=(d=Date)(c=new d(),z=O=>Math.abs(new d(a[3]+O)-c)).split` `)[1]=='Apr'&a[2]==20|~a[4].search(/(04|16):20/)?'0,0,2ca2o,0,10e,0,0,1eu9z4,0,22w,1ulajuo,0,bklxc,2zgg,i,120gdfk,8lc,1s1s,15,j0jf9c,7em8,tac,10,190zcw0,tm8w,ksk,hra0ia,mihog0,3aels,wy,iv8e15,b98u80,cvs1s,575,9fm71g,190zcw0,bg7vgg,1t4,148d4lu,121pblx,b9ea68,2b36,iv8hn5,9zleso,15kytz4,98cp,4fwpwk,zir9ud,1h9u3ln,11c6vb4,84kda8,kbuo05,b98u84,14possy,k9su6i,a26hwk,zvft34,kavrpc,1tn1j4,1r3jis,kamgao,a5bhq8,2b2q,beyt6x,j0y810,muhiww,9xl,a5b7s8,14npcwi,1bkfw1s,4ys,14lipw4,kalr6k,0,1aq,kalqzg,0,48m,2j6hqf,zik0zk,0,33mcjk,0,5'.split`,`.map(a=>('0'.repeat(32)+parseInt(a,36).toString(2)).substr(-32)).join``.match(/.{1,3}/g).map(a=>` .:\`|;'
`[parseInt(a,2)]).join``:~~((T=Math.min(z('/4/20'),z(` ${a[1]} ${++a[2]} 0:4:20`),z(' 4:20'),z(' 0:4:20'),z(' 16:20'),z(' 0:16:20'))/1000)/60)+` minutes and ${~~(T%60)} seconds left until your next hit.`

Codice Ungolfed

Nota: il codice non salvato non verrà eseguito

function() {
    // (all vars here are actually global)
    var d = Date; // short reference to Date object
    var dateString = Date() // "Tue Apr 12 2016 20:13:00 GMT+0200 (W. Europe Daylight Time)"
    .split` `; // ["Tue", "Apr", "12", ...]
    var currentDate = new Date();
    dateDiff = function(toAppend) {
        return Math.abs( // no dates in the past
            new Date(dateString[3] + toAppend) // new Date('2016' + something)
            - currentDate // substract the current date. 
                          // Thanks JS for the datetime implementation
        );
    }

    if ((dateString[1] == 'Apr' & dateString[2] == 20) |
        ~dateString[4].search(/(04|16):20/)) { // if the time doesn't contain 04:20 or 
                                               // 16:20, this will return -1. ~-1 is 0 
                                               // and thus falsy
        alert(printAscii());
    } else {
        alert(printTimeLeft());
    }
}

function printAscii() {
    var magicString = '0,0,2ca2o,0,10e,0,0,1eu9z4,0,22w,1ulajuo,0,bklxc,2zgg,i,120gdfk,8lc,1s1s,15,j0jf9c,7em8,tac,10,190zcw0,tm8w,ksk,hra0ia,mihog0,3aels,wy,iv8e15,b98u80,cvs1s,575,9fm71g,190zcw0,bg7vgg,1t4,148d4lu,121pblx,b9ea68,2b36,iv8hn5,9zleso,15kytz4,98cp,4fwpwk,zir9ud,1h9u3ln,11c6vb4,84kda8,kbuo05,b98u84,14possy,k9su6i,a26hwk,zvft34,kavrpc,1tn1j4,1r3jis,kamgao,a5bhq8,2b2q,beyt6x,j0y810,muhiww,9xl,a5b7s8,14npcwi,1bkfw1s,4ys,14lipw4,kalr6k,0,1aq,kalqzg,0,48m,2j6hqf,zik0zk,0,33mcjk,0,5' // ;)
    var splitted = magicString.split`,`;
    var binarySequence = splitted.map(function(piece) {
        return ('0'.repeat(32) + // 000000000... this will be padded
            parseInt(a,36) // parseInt('190zcw0',36) -> 000000002722627584
            .toString(2) // -> 10100010010010000000000000000000
        ).substr(-32) // left pad binary sequence
    }).join``; // create one big binary sequence from several smaller
    var groupsOfThree = binarySequence.match(/.{1,3}/g);
    return groupsOfThree.map(function(three) {
        return ` .:\`|;'\n`[parseInt(a,2)]; // magic.. turn 010 into : etc
    }).join``; // create them blaze
}

function printTimeLeft() {
    // this is way longer than it should be.. probably
    var minimumTimeDifference = Math.min(
        dateDiff('/4/20'), // -> Difference between now and 2016/4/20 00:00:00
        dateDiff(' 4:20'), // 2016 04:20:00.. Sadly the 2016 is needed (i think)
        dateDiff(' 0:4:20'), // 2016 00:04:20
        dateDiff(' 16:20'), // Damn 12 hour clock :(
        dateDiff(' 0:16:20'),
        dateDiff(` ${dateString[1]} // 2016 Apr 
                   ${dateString[2]+1} // 2016 Apr 13 (12+1)
                   0:4:20` // Check the first occurrence of 4 minutes and 20 seconds 
                           // the next day
    )
    var timeInSeconds = minimumTimeDifference / 1000;
    return Math.floor(timeInSeconds) + // ~~ works like Math.floor
        ` minutes and ${Math.floor(timeInSeconds%60)} seconds left until your next hit.`;
}

Provalo!

f=
_=>(a=(d=Date)(c=new d(),z=O=>Math.abs(new d(a[3]+O)-c)).split` `)[1]=='Apr'&a[2]==20|~a[4].search(/(04|16):20/)?'0,0,2ca2o,0,10e,0,0,1eu9z4,0,22w,1ulajuo,0,bklxc,2zgg,i,120gdfk,8lc,1s1s,15,j0jf9c,7em8,tac,10,190zcw0,tm8w,ksk,hra0ia,mihog0,3aels,wy,iv8e15,b98u80,cvs1s,575,9fm71g,190zcw0,bg7vgg,1t4,148d4lu,121pblx,b9ea68,2b36,iv8hn5,9zleso,15kytz4,98cp,4fwpwk,zir9ud,1h9u3ln,11c6vb4,84kda8,kbuo05,b98u84,14possy,k9su6i,a26hwk,zvft34,kavrpc,1tn1j4,1r3jis,kamgao,a5bhq8,2b2q,beyt6x,j0y810,muhiww,9xl,a5b7s8,14npcwi,1bkfw1s,4ys,14lipw4,kalr6k,0,1aq,kalqzg,0,48m,2j6hqf,zik0zk,0,33mcjk,0,5'.split`,`.map(a=>('0'.repeat(32)+parseInt(a,36).toString(2)).substr(-32)).join``.match(/.{1,3}/g).map(a=>` .:\`|;'
`[parseInt(a,2)]).join``:~~((T=Math.min(z('/4/20'),z(` ${a[1]} ${++a[2]} 0:4:20`),z(' 4:20'),z(' 0:4:20'),z(' 16:20'),z(' 0:16:20'))/1000)/60)+` minutes and ${~~(T%60)} seconds left until your next hit.`

alert(f())

Nel seguente frammento di codice è possibile impostare la data per verificare l'arte ascii

day=prompt('Day?', 12);
month=prompt('Month?', 'Apr');
f=
_=>(a=(d=Date)(c=new d(),z=O=>Math.abs(new d(a[3]+O)-c)).split` `)[1]==month&a[2]==day|~a[4].search(/(04|16):20/)?'0,0,2ca2o,0,10e,0,0,1eu9z4,0,22w,1ulajuo,0,bklxc,2zgg,i,120gdfk,8lc,1s1s,15,j0jf9c,7em8,tac,10,190zcw0,tm8w,ksk,hra0ia,mihog0,3aels,wy,iv8e15,b98u80,cvs1s,575,9fm71g,190zcw0,bg7vgg,1t4,148d4lu,121pblx,b9ea68,2b36,iv8hn5,9zleso,15kytz4,98cp,4fwpwk,zir9ud,1h9u3ln,11c6vb4,84kda8,kbuo05,b98u84,14possy,k9su6i,a26hwk,zvft34,kavrpc,1tn1j4,1r3jis,kamgao,a5bhq8,2b2q,beyt6x,j0y810,muhiww,9xl,a5b7s8,14npcwi,1bkfw1s,4ys,14lipw4,kalr6k,0,1aq,kalqzg,0,48m,2j6hqf,zik0zk,0,33mcjk,0,5'.split`,`.map(a=>('0'.repeat(32)+parseInt(a,36).toString(2)).substr(-32)).join``.match(/.{1,3}/g).map(a=>` .:\`|;'
`[parseInt(a,2)]).join``:~~((T=Math.min(z('/4/20'),z(` ${a[1]} ${++a[2]} 0:4:20`),z(' 4:20'),z(' 0:4:20'),z(' 16:20'),z(' 0:16:20'))/1000)/60)+` minutes and ${~~(T%60)} seconds left until your next hit.`

alert(f())


Penso che un tempo non valido come 15:16:20sarà una partita sul tuo regex e visualizzare accidentalmente la corda magica?
Valore inchiostro

@KevinLau Dang, hai ragione. Lo risolverò domani ..
Bassdrop Cumberwubwubwub

Non credo che ()siano necessari per il datecostruttore: c=new d(), ...può diventare soloc=new d, ...
Cyoce
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.