Final Fantasy XV SCOPERTO!


9

Dato che sono INSANELY ipotecato per l' evento Final Fantasy XV Uncovered , voglio che tu mi scriva un programma per dirmi quando è !!!

L'input

Il tuo input take sotto forma di HH:MM XDT, dove HHè un numero nell'intervallo 1-12, MMè un numero compreso tra 0-60, ed XDTè un fuso orario, Xessendo uno di E(orientale, UTC-4), C(centrale, UTC-5), P(pacifico, UTC-7) o M(montagna, UTC-6). Si presume che questo sia il PM. Gli input validi includono:

1:00 EDT (1 PM Eastern Daylight Time)
4:05 MDT (4:05 PM Mountain Daylight Time)
12:23 PDT (12:23 PM Pacific Daylight Time)
1:10 CDT (1:10 PM Central Daylight Time)

Si può presumere che l'input sia valido.

Il risultato

Il tuo programma deve effettuare le seguenti operazioni:

  1. Converti il ​​tempo dato in PDT e l'output It is XX:XX PM PDT., dove XX:XXè il tempo convertito. Si noti che non è necessario gestire alcun caso in cui la conversione del tempo attraverserebbe il limite AM / PM.

  2. Stampa una delle seguenti opzioni:

    1. Se il tempo convertito è precedente alle 18:00 PDT, stampare X minutes until the pre-show!, sostituendo Xcon il numero di minuti fino alle 18:00 PDT.

    2. Se il tempo convertito è dopo o uguale alle 18:00 PDT e prima delle 19:00 PDT , stampa Pre-show started X minutes ago; UNCOVERED is starting in Y minutes!, dove Xè il numero di minuti trascorsi dalle 18:00 PDT e Yil numero di minuti fino alle 7:00 PM PDT.

    3. Se il tempo convertito è successivo o uguale a 7:00 PM PDT , stampa UNCOVERED started X minutes ago!, dove Xè il numero di minuti trascorsi dalle 19:00 PDT.

Ogni stringa stampata deve essere seguita da una nuova riga.

punteggio

Questo è il golf del codice, quindi vince il programma più breve.


Si presume che tutti gli input siano validi?
Leaky Nun,

1
È HH:MM XDTun errore di battitura? Può essere CST.
Leaky Nun,

1
Sarebbe 2:45 EDTapparire così abbiamo bisogno di rilevare se il tempo convertito è PM o AM?
Leaky Nun,

Sarebbe stato bello se avessi effettivamente incluso gli offset UTC dei quattro fusi orari, quindi non avrei dovuto cercarli da solo.
Neil

@KennyLau CSTEra un errore di battitura e non sarebbe apparso alcun tempo che potesse oltrepassare il confine AM / PM. Ha modificato il post.
Kirbyfan64sos,

Risposte:


1

JavaScript (ES6), 257 byte

s=>(t=` minutes`,a=s.match(/(\d+):(\d+) (.)/),h=+a[1]+"PMCE".search(a[3]),m=420-h*60-a[2],`It is ${h}:${a[2]} PM PDT
${h<6?m-60+t+` until the pre-show`:h<7?`Pre-show started ${60-m+t} ago; UNCOVERED is starting in ${m+t}`:`UNCOVERED started ${-m+t} ago`}!`)

Non conosco i risparmi ma ci sono alcune stringhe che si ripetono con cui potresti giocare di più. "re-show" e "UNCOVERED" per esempio.
Matt,

@Matt Per una stringa che si ripete solo una volta che l'overhead è di 13 byte, quindi dovrebbe essere lungo 14 byte per valerne la pena. "minuti" ha ottenuto un bonus per essere vicino al tempo ed essere necessario quattro volte.
Neil

4

Python (335 byte)

t=raw_input().replace(*': ').split();x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;print '%s:%s PM PDT' % tuple(t[:1]);x=t[0]*60+int(t[1]);print ['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)), 'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]

Produzione:

1:00 MDT
2:00 PM PDT
240 minutes until the pre-show!

6:00 CDT  
8:00 PM PDT
UNCOVERED started 60 minutes ago!

6:50 PDT
6:50 PM PDT
Pre-show started 50 minutes ago; UNCOVERED is starting in 10 minutes!

Benvenuti in PPCG ! Spero che ti divertirai qui.
Leaky Nun,

Ecco una versione golfata non testata di 340 byte:t=raw_input().replace(' ',':').split(':');x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;t[2]='PDT';print'%s:%s PM %s'%tuple(t);x=t[0]*60+int(t[1]);print['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)),'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]
Leaky Nun

Benvenuto in PPCG, speriamo che troverai quello che vuoi qui e godrai il tuo tempo con noi! Se hai tempo e volontà, non dimenticare di mettere una versione non controllata del tuo codice (forse con commenti?), Che aiuterà notevolmente le persone a capire il tuo codice e ti aiuterà a fornirti suggerimenti per giocare a golf ancora di più;).
Katenkyo,

È possibile sostituire .replace(' ', ':').split(':')con .replace(*': ').split(), risparmiando 6 byte
Blue


2

Lua, 357 335 332 byte

Grazie a @Katenkyo per aver tagliato 22 byte.

golfed:

h,m,t=(...):match("(%d+):(%d+) (.)")f=tonumber h=(f(h)-("PMCE"):find(t))%12+1m=f(m)print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=h<6 and n..a.." until the pre-show!"or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"print(r)

( Provalo online )

Ungolfed:

n = "7:10 CST"

h,m,t = n:match("(%d+):(%d+) (.)")
h = (tonumber(h) - ("PMCE"):find(t))%12 + 1
m = tonumber(m)
print("It is "..h..":"..m.." PM PDT.")

n = (6-h)*60-m

if h<6 then
  r=n.." minutes until the pre-show!"
elseif h<7 then
  r="Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!"
else
  r="UNCOVERED started "..(m+(h-7)*60).." minutes ago!"
end

print(r)

Non devi mai usare il numero quando il tuo numero non è in una base diversa da 10, invece, puoi scrivere h=h+0, l'aggiunta di 0 convertirà automaticamente il risultato in un numero. Inoltre, è n=(...)obbligatorio? non sarebbe meglio includere l'uso di ...come segue -> h,m,t=(...):match("(%d+):(%d+) (.)"), non lo riutilizzerai comunque, dato che cambierai il valore ndell'uso he m:)
Katenkyo

Inoltre, dovresti essere in grado di cambiarti se / elseif / else per una singola dichiarazione ternaria del modulo r=(h<6 and n.." minutes until the pre-show!" )or h<7 and "Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!" or "UNCOVERED started "..(m+(h-7)*60).." minutes ago!". Potrebbe dover essere rielaborato un po ', ma l'utilizzo di questo farà risparmiare molto byte. Per informazione, la struttura di un ternario a lua è<condition> and <case true, have to be evaluated to true> or <case false, can be anything>
Katenkyo,

(non avevo ancora lo spazio per finire quello che volevo dire) Non dimenticare di controllare i suggerimenti per lua , non sono ancora esaustivi, ma ci sono alcune piccole cose utili :)
Katenkyo

Ecco una soluzione golf non testata se si desidera che una base includa tutto ciò che in h,m,t=(...):match("(%d+):(%d+) (.)")h=(h-("PMCE"):find(t))%12+1m=m+0print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=(h<6 and n.." minutes until the pre-show!" )or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"end print(r)realtà è 329 byte;).
Katenkyo,

L'ho aggiornato. 0 + m non funziona qui.
Leaky Nun,

1

C, 333 byte

#define p printf
char s[9];main(t){gets(s);s[5]=0;s[1]-=2+s[6]%2-s[6]%3;s[1]<48&&(s[1]+=10,--*s);
t=*s*600+s[1]*60+s[3]*10+s[4]-32568;p("It is %s PM PDT.",s);
t<0?p("%d minutes until the pre-show!",-t):t<60?p(
"Pre-show started %d minutes ago; UNCOVERED is starting in %d minutes!",t,60-t):
p("UNCOVERED started %d minutes ago!",t-60);}

333 byte dopo aver rimosso le newline non necessarie (tutte tranne quella dopo #define).


Non sei sicuro dei risparmi ma hai dei letterali stringa che potresti aggiungere come "minuti" e "SCOPERTO"
Matt

1

PHP, 347 328 327 322 byte

<?=$u="UNCOVERED";$m=" minutes";$s=" started ";$p="re-show";$z=['P'=>0,'M'=>1,'C'=>2,'E'=>3];$i=explode(":",$argv[1]);$h=$i[0]%12-$z[$argv[2][0]];$o=$i[1];$t=60-$o;$a="$s$o$m ago";echo"It is ".(($h+11)%12+1).":$o".($h<0?" A":" P")."M PDT.\n".($h<6?$t."$m until the p$p!":($h<7?"P$p$a; $u is starting in $t$m!":"$u$a!"));?>

vista esplosa

<?=
  $u = "UNCOVERED";
  $m = " minutes";
  $s = " started ";
  $p = "re-show";
  $z = [ 'P' => 0,
         'M' => 1,
         'C' => 2,
         'E' => 3 ];

  $i = explode(":", $argv[1]);
  $h = $i[0]%12 - $z[$argv[2][0]];
  $o = $i[1];
  $t = 60 - $o;
  $a = "$s$o$m ago";

  echo "It is " . (($h+11)%12+1) . ":$o" . ($h < 0 ? " A" : " P") . "M PDT.\n" .
       ($h < 6 ? $t . "$m until the p$p!"
               : ($h < 7 ? "P$p$a; $u is starting in $t$m!"
                         : "$u$a!"));
?>

Funziona come php script.php HH:MM XDT. Comprende l'ora e il fuso orario come $argvvoci, regex$argv[1] in out $i = [HH, MM], determina il fuso orario dal primo carattere in$argv[2] quanti minuti dopo le 18:00 PDT sono, quindi ternari il echo.

Potrebbe eliminare 2 byte utilizzando $u=UNCOVERED, ma sarebbe l'unico errore qui e mi piace che funzioni in modo pulito.


0

PowerShell 292 byte

$r,$i,$s,$u="re-show"," minutes"," start","UNCOVERED";$h,$m,$z=$args[0]-split":| ";$h=+$h-"PMCE".IndexOf($z[0]);"It is $h`:$m PM PDT.";if(($t=$h*60+$m-360)-lt0){"$($t*-1)$i until the p$r!"}else{if($t-gt59){"$u$s`ed $($t-60)$i ago!"}else{"P$r$s`ed $t$i ago; $u is$s`ing in $(($t-60)*-1)$i!"}}

Spiegazione meno giocata a golf

# Some string literals.
$r,$i,$s,$u,$g="re-show"," minutes"," start","UNCOVERED"," ago"
# Get the hours, minutes and zone into variables.
$h,$m,$z=$args[0]-split":| "
# Offset the time based on the passed timezone. 
$h=+$h - "PMCE".IndexOf($z[0])
# Display current PDT time.
"It is $h`:$m PM PDT."

# Based on adjusted time value for PDT determine what string to show. 
# Several string literals were used to save space.
if(($t=$h*60+$m-360)-lt0){
    # Show has not started yet
    "$($t*-1)$i until the p$r!"
}else{
    if($t-gt59){
        # Between 6 and 7
        "$u$s`ed $($t-60)$i$g!"
    }else{
        # It's after 7. Should have check more often. 
        "P$r$s`ed $t$i$g; $u is$s`ing in $(($t-60)*-1)$i!"
    }
}

Il valore letterale di "ago" è stato rimosso nel codice, ma per ora lasciato nella spiegazione in caso di altre modifiche.


Penso di aver esagerato con alcuni letterali e mi ha allungato il tempo ....
Matt
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.