Python 136

2

Python 136

Ich bin sicher, jemand kann das besser - ich habe Tkinter noch nie benutzt. Insbesondere wette ich, dass die l.pack()und l["text"]können vermeidbar sind.

tk

Golf gespielt

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()
chmullig
quelle

Antworten:

1

R.

Hier ist eine Lösung für R mit GTK + über das gWidgets-Paket. Dies ist ein ziemlich hässlicher Code, da ich mit dem Paket gWidgets / GTK + überhaupt nicht vertraut bin.

Code

Hier ist der Code:

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)

Ausgabe

So sieht die Ausgabe aus:

Geben Sie hier die Bildbeschreibung ein

tchakravarty
quelle
Es muss ständig aktualisiert werden - das heißt automatisch
Türknauf
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
TwiNight
quelle
0

C # 128

Golf gespielt

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));
    }
}
James C.
quelle
1
Das zählt nicht ständig herunter, oder? Willkommen auch bei Codegolf!
Cruncher
Danke, ich bin froh, hier zu sein! Ich glaube, ich habe es falsch verstanden, dies würde nur aktualisiert, wenn es erneut ausgeführt wird. Ich werde bald bearbeiten und neu veröffentlichen
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)

Dies zählt Zeilenumbrüche als 2 Zeichen.

Timtech
quelle