Conto alla rovescia di Natale


10

Nello spirito delle vacanze e come qualcuno ha già iniziato il tema invernale ( Costruisci un pupazzo di neve! ), Propongo una nuova sfida.

Stampa il numero di giorni, ore, minuti e secondi fino a Natale (mezzanotte (00:00:00) 25 dicembre) su una finestra autonoma (non una console) in qualsiasi formato non ambiguo che ritieni opportuno, e aggiornalo continuamente come questi i valori cambiano.

Input - niente, deve leggere l'ora del sistema.

Il codice più corto vince :) Le stringhe "Giorni", "Ore", "Minuti", "Secondi" e "Fino a Natale" sono in codice libero. Puoi anche condirli se vuoi. Aromatizzarli è semplicemente allo scopo di produrre un risultato piacevole. Non è possibile aromatizzare le stringhe allo scopo di creare un numero magico per salvare il codice.


Cosa intendi esattamente con "condiscili"? Sono "giorni", "ore", "minuti", "secondi", e "fino a Natale" necessaria in uscita, o solo opzioni gratuite? Quanto "aroma" di queste corde è gratuito?
— Iszi,

2
Nessuna console ?? I programmatori di console si ribellano! Stavo solo scherzando. Bella idea Buone vacanze.
— Darren Stone,

@Iszi Non sono richiesti. Ho appena dato loro gratuitamente in modo che se le persone vogliono fare un bel risultato reale non perderanno così tanti personaggi.
— Cruncher,

1
La mezzanotte di Natale non è la fine del Natale?
— DavidC,

2
No, in genere la mezzanotte è l'istante zeroth del nuovo giorno. "Midnight Christmas" è quando inizia il Natale.
— breadbox

Risposte:


5

Rubino con scarpe , 96 - 33 = 63

Shoes.app{p=para
animate{p.text="0 days 0 hours 0 minutes #{1387951200-Time.new.to_f} seconds"}}

Bene, non hai mai detto che non potevamo . ;)

immagine dello schermo

Si aggiorna una volta ogni frame.

Il numero magico 1387951200è Natale - 25 dicembre 2013 00:00.

Sessione IRB di esempio per cui ho ottenuto i numeri:

irb(main):211:0> "0 days 0 hours 0 minutes  seconds".size
=> 33
irb(main):212:0> Time.new(2013,12,25,00,00,00).to_i
=> 1387951200
irb(main):213:0>

Dec 25, 2013 00:00è mezzanotte.
— Cruncher,

@Cruncher Ah, allora va bene. Editing di gran parte del testo inutile quindi
— Manopola

3

PowerShell: 279

Il conteggio dei personaggi non tiene conto degli omaggi. @ Cruncher - si prega di regolare di conseguenza.

golfed

($t=($a='New-Object Windows.Forms')+".Label"|iex).Text=($i={((New-TimeSpan -en 12/25|Out-String)-split"`n")[2..6]});$t.Height=99;($x=iex $a".Form").Controls.Add($t);$x.Text='Time Until Christmas';($s=iex $a".Timer").add_tick({$t.Text=&$i;$x.Refresh()});$s.Start();$x.ShowDialog()

Questa non è la cosa più bella, né come codice né come finestra, ma funziona.

Un bel po 'è che questo non è solo buono per il 2013 - funzionerà in qualsiasi anno, dalle 00:00 del 1 gennaio alle 00:00 del 25 dicembre.

Avviso: la finestra potrebbe non rispondere: continuerà ad aggiornarsi, ma potresti non essere in grado di spostarla o chiuderla.

inserisci qui la descrizione dell'immagine

Non golfato con commenti

(
    # $t will be the label that displays our countdown clock on the form.
    $t=(
        # $a is used as a shortcut to address the Forms class later.
        $a='New-Object Windows.Forms'
    # Tack ".Label" onto the end with iex to finish making $t.
    )+".Label"|iex

# Set the text for our label.
).Text=(
    # $i will be a script block shortcut for later.
    $i={
        (
            (
                # Get the current "Time until Christmas", and output it as a string.
                New-TimeSpan -en 12/25|Out-String
            # Break the string into newline-delimeted array.
            )-split"`n"
        # Only output elements 2..6 - Days, Hours, Minutes, Seconds, Milliseconds.
        )[2..6]
    }
);

# Make sure the label is tall enough to show all the info.
$t.Height=99;

(
    # Use iex and $a as shortcut to make $x a "New-Object Windows.Forms.Form".
    $x=iex $a".Form"

# Add the label to the form.
).Controls.Add($t);

# Put 'Time Until Christmas' in the title bar for flavor.
$x.Text='Time Until Christmas';

(
    # Use iex and $a as shortcut to make $s a "New-Object Windows.Forms.Timer".
    $s=iex $a".Timer"

# Tell the timer what to do when it ticks.
).add_tick(
    {
        # Use the $i script block to update $t.Text.
        $t.Text=&$i;
        # Reload the form so the updated text displays.
        $x.Refresh()
    }
);

# Start the timer.
$s.Start();

# Show the form.
$x.ShowDialog();

# Variable cleanup - omit from golfed code.
rv t,a,x,i,s

3

Mathematica 167-44 = 123

Quanto segue aggiorna continuamente una tabella che mostra i giorni, le ore, i minuti e i secondi (in millesimi) fino all'inizio del giorno di Natale. Non sono sicuro di come contare lo sconto per le stringhe gratuite.

Dynamic[Grid[Join[{{"Countdown", "until Christmas"}}, 
{DateDifference[Date[], {2013, 12, 25, 0, 0, 0}, {"Day", "Hour", "Minute", "Second"}], 
Clock[{1, 1}, 1]}[[1]] /. d_String :> d <> "s"]] ]

conto alla rovescia


Una soluzione rapida e sporca : 104-19 = 85 caratteri

Dynamic@{DateDifference[Date[], {2013, 12, 25, 0, 0, 0}, {"Day", "Hour", "Minute", 
 "Second"}], Clock[{1, 1}, 1]}[[1]]

{{17, "Day"}, {10, "Hour"}, {59, "Minute"}, {51.4011, "Second"}}


"Countdown to Christmas: Days"Questo può essere libero, "Day", "Hour", "Minute", "Second"può essere pure.
— Cruncher,

Grazie per il chiarimento. A proposito, gli spazi esterni alle stringhe non sono obbligatori. Sono inseriti solo per leggibilità.
— DavidC,

Perché ci sono "-" davanti ai numeri? Potrebbe essere fonte di confusione e sembrare che siamo già passati per Natale. Sarebbero corretti cambiando l'ordine in DateDifference?
— Cruncher,

Li ho rimossi e migliorato la formattazione, pagando il prezzo in caratteri aggiunti.
— DavidC,

2

Python 136

Sono sicuro che qualcuno può farlo meglio - non ho mai usato Tkinter prima. In particolare, scommetto che l.pack()e l["text"]possono essere evitabili.

tk

golfed

from Tkinter import*
from datetime import datetime as d
r=Tk()
l=Label(r)
l.pack()
while 1:
    l["text"]=d(2013,12,25)-d.now()
    r.update()

1

R

Ecco una soluzione per R utilizzando GTK + tramite il pacchetto gWidgets. Questo è un codice piuttosto brutto dal momento che non ho familiarità con il pacchetto gWidgets / GTK +.

Codice

Ecco il codice:

library(gWidgets)
options(guiToolkit="RGtk2")

# FUNCTION compute the hours minutes and seconds from time in seconds
fnHMS = function(timeInSec) {
  hours = timeInSec %/% 3600
  minutes = (timeInSec %% 3600) %/% 60
  seconds = (timeInSec %% 3600) %% 60
  return(list(hours = hours, minutes = minutes, seconds = seconds))
}

# test the function
fnHMS(1478843)

# container for the label and the button widget
christmasCountdownContainer = gwindow('Christmas Countdown!!', visible = TRUE)
christmasCountdownGroup = ggroup(horizontal = FALSE,
                                 container = christmasCountdownContainer)
ccWidget1 = glabel(sprintf('%4.0f hours, %4.0f minutes, %4.0f seconds till Christmas!!', 
                           (liHMS <- fnHMS(as.double(difftime(as.POSIXct(strptime('25-12-2013 00:00:01', 
                                      format = '%d-%m-%Y %H:%M:%S')),
                  Sys.time(), units = 'secs'))))[[1]], liHMS[[2]], liHMS[[3]]), 
                            container = christmasCountdownGroup)

ccWidget2 = gbutton("Update!", handler = function(h, ...) {
  # retrieve the old value of the ccWidget1
  oldValue = svalue(ccWidget1)
  liHMS = fnHMS(as.double(difftime(as.POSIXct(strptime('25-12-2013 00:00:01', 
                                                       format = '%d-%m-%Y %H:%M:%S')),
                                   Sys.time(), units = 'secs')))
  svalue(ccWidget1) = sprintf('%4.0f hours, %4.0f minutes, %4.0f seconds till Christmas!!',
                              liHMS[[1]], liHMS[[2]], liHMS[[3]])
  }, container = christmasCountdownGroup)

Produzione

Ecco come appare l'output:

inserisci qui la descrizione dell'immagine


Deve aggiornare continuamente - ciò significa automaticamente
— Maniglia

1

Dyalog APL, 61

{⎕SM[1;]←1 1,⍨⊂⍕(1 4⍴2↓2013 12 24 23 59 59 1000-⎕TS)⍪'Days' 'Hours' 'Minutes' 'Seconds'⋄∇1}1

0

C # 128

golfed

using D=System.DateTime;using System.Windows.Forms;class C{static void Main(){MessageBox.Show(""+(new D(2013, 12, 25)-D.Now));}}

Ungolfed

using D=System.DateTime;
using System.Windows.Forms;
class C
{
    static void Main()
    {
        MessageBox.Show(""+(new D(2013,12,25)-D.Now));
    }
}

1
Questo non fa continuamente il conto alla rovescia vero? Inoltre, benvenuto su codegolf!
— Cruncher,

Grazie, felice di essere qui! Immagino di aver frainteso, questo si aggiorna solo quando viene rieseguito. Modificherò e ripubblicherò presto
— James C.

0

Python 2, 115

from datetime import datetime as d
n=d.now()
print str(24-n.day),str(23-n.hour),str(59-n.minute),str(60-n.second)

Questo conta i newline come 2 caratteri.

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.