크리스마스 카운트 다운


10

휴일의 정신으로, 누군가 이미 겨울 테마를 시작했을 때 ( 눈사람 만들기! ) 나는 새로운 도전을 제안합니다.

크리스마스 (콘솔이 아닌 독립형 창)에 크리스마스 (자정 (00:00:00) 12 월 25 일)까지의 일 수, 시간, 분 및 초를 원하는 모호하지 않은 형식으로 인쇄하고 계속해서 다음과 같이 업데이트하십시오. 값이 변경됩니다.

입력-아무것도 아님, 시스템 시간을 읽어야합니다.

가장 짧은 코드 승리 :) 문자열 "일", "시간", "분", "두 번째"및 "크리스마스까지"는 무료 코드입니다. 원하는 경우 맛을 낼 수도 있습니다. 그것들을 맛내는 것은 좋은 결과물을 생산하기위한 것입니다. 코드를 저장하기 위해 마법의 숫자를 만들 목적으로 문자열을 맛볼 수는 없습니다.


"맛 내기"란 정확히 무엇을 의미합니까? 출력에 "일", "시간", "분", "초"및 "크리스마스까지"가 필요 합니까 아니면 무료 옵션입니까? 그 줄의 "맛"은 얼마입니까?
Iszi

2
콘솔 없음 ?? 콘솔 코더 반란! 농담이야 좋은 생각. 행복한 휴일.
Darren Stone

@Iszi 필요하지 않습니다. 사람들이 실제로 좋은 결과물을 만들고 싶을 때 너무 많은 캐릭터를 잃지 않도록 무료로 제공했습니다.
Cruncher

1
크리스마스 자정은 크리스마스의 끝이 아닌가?
DavidC

2
아니요, 일반적으로 자정은 새 날의 0 번째 순간입니다. "Midnight Christmas"는 크리스마스가 시작될 때입니다.
breadbox December

답변:


5

신발이 달린 루비 , 96-33 = 63

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

글쎄, 당신은 우리가 할 수 없다고 결코 말하지 않았다 . ;)

스크린 샷

프레임마다 한 번씩 업데이트합니다.

마법의 숫자 1387951200는 크리스마스입니다-2013 년 12 월 25 일 00:00.

숫자를 얻은 위치에 대한 샘플 IRB 세션 :

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자정입니다.
Cruncher

@Cruncher 아, 그럼. 쓸모없는 텍스트를 많이 편집 한 다음
Doorknob

3

PowerShell : 279

캐릭터 수는 공짜를 고려하지 않습니다. @Cruncher-그에 따라 조정하십시오.

골프

($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()

이것은 코드 나 창으로 가장 아름다운 것이 아니지만 작동합니다.

한 가지 좋은 점은 이것이 2013 년에만 좋지 않다는 것입니다 .1 월 1 일 00:00부터 12 월 25 일 00:00까지 어느 해에도 작동합니다.

경고 : 창이 응답하지 않을 수 있습니다. 계속 업데이트되지만 이동하거나 닫을 수 없습니다.

여기에 이미지 설명을 입력하십시오

댓글이없는 골프

(
    # $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

매스 매 티카 167-44 = 123

다음은 크리스마스가 시작될 때까지 일, 시간, 분 및 초 (단위 : 천분)를 나타내는 표를 지속적으로 업데이트합니다. 무료 문자열 할인을 계산하는 방법을 잘 모르겠습니다.

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"]] ]

카운트 다운


빠르고 더러운 해결책 : 104-19 = 85 자

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

{{17, "하루"}, {10, "시간"}, {59, "분"}, {51.4011, "두 번째"}}


"Countdown to Christmas: Days"이 무료로 할 수있다, "Day", "Hour", "Minute", "Second"뿐만 아니라 수 있습니다.
Cruncher

설명 주셔서 감사합니다. Btw, 문자열 외부의 공백은 필수가 아닙니다. 가독성을 위해서만 삽입됩니다.
DavidC

숫자 앞에 "-"가있는 이유는 무엇입니까? 혼란 스러울 수 있으며 이미 크리스마스를 통과 한 것처럼 보입니다. DateDifference에서 순서를 변경하여 수정됩니까?
Cruncher

나는 그것들을 제거하고 서식을 개선하여 추가 된 문자로 가격을 지불했습니다.
DavidC

2

파이썬 136

나는 누군가가 이것을 더 잘 할 수 있다고 확신합니다-나는 전에 Tkinter를 사용한 적이 없습니다. 특히 나는 내기 l.pack()l["text"]수는 피할 수 있습니다.

tk

골프

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

아르 자형

다음은 gWidgets 패키지를 통해 GTK +를 사용하는 R에 대한 솔루션입니다. gWidgets / GTK + 패키지에 전혀 익숙하지 않기 때문에 이것은 매우 추악한 코드입니다.

암호

코드는 다음과 같습니다.

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)

산출

출력 결과는 다음과 같습니다.

여기에 이미지 설명을 입력하십시오


지속적으로 업데이트해야합니다. – 자동으로
Doorknob

1

디아 로그 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

골프

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

언 골프

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

1
이것은 지속적으로 카운트 다운되지 않습니까? 또한 codegolf에 오신 것을 환영합니다!
Cruncher

고마워요, 여기 와서 기뻐요! 오해 된 것 같습니다. 다시 실행할 때만 업데이트됩니다. 곧 수정하고 다시 게시하겠습니다
James C.

0

파이썬 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)

이것은 개행을 2 자로 계산합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.