クリスマスカウントダウン


10

休暇の精神で、そして誰かがすでに冬のテーマを始めたように(雪だるまを作ろう!)私は新しい挑戦を提案します。

クリスマスまでの日数、時間数、分数、秒数(12月25日の真夜中(00:00:00))を、スタンドアロンのウィンドウ(コンソールではなく)に、適切と思われる形式で印刷し、次のように継続的に更新します。値が変化します。

入力-なし。システム時間を読み取る必要があります。

最短コードが勝つ:)文字列「Days」、「Hours」、「Minutes」、「Seconds」、および「Until Christmas」は無料のコードです。必要に応じて、風味を付けることもできます。それらを味付けすることは、素晴らしい出力を生成する目的のために全くあります。コードを保存するためのマジックナンバーを作成する目的で文字列をフレーバー化することはできません。


「味わう」とはどういう意味ですか?「日」、「時間」、「分」、「秒」、および「クリスマスまで」は出力に必要ですか、それとも無料のオプションですか?それらの文字列のどれだけ「フレーバー」が無料ですか?
— Iszi

2
コンソールなし?? コンソールコーダーは反乱!冗談だ。良いアイデア。幸せな休日。
— Darren Stone

@Iszi必須ではありません。私はそれらを無料で提供したので、人々が実際に素晴らしい出力をしたい場合、それほど多くの文字を失うことはありません。
— ランチャー

1
クリスマスの真夜中はクリスマスの終わりではありませんか?
— DavidC 2013

2
いいえ、通常、真夜中は新しい日の0番目の瞬間です。「ミッドナイトクリスマス」はクリスマスが始まるときです。
— ブレッドボックス2013

回答:


5

Ruby with Shoes、96-33 = 63

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

まあ、私たちができないと言ったことはありません。;)

スクリーンショット

フレームごとに1回更新します。

マジックナンバー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ああ、それでは大丈夫。次に、役に立たないテキストの多くを編集する
— ドアノブ

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

これは、コードとしてもウィンドウとしても、最も美しいものではありませんが、機能します。

1つの良い点は、これが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

Mathematica 167-44 = 123

以下は、クリスマスの日が始まるまでの日、時間、分、秒(1000分の1)を示すテーブルを継続的に更新します。無料の文字列の割引をどのようにカウントするかわかりません。

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"同様にすることができます。
— ランチャー

説明をありがとう。ところで、文字列の外側のスペースは必須ではありません。読みやすいように挿入されています。
— DavidC 2013

数字の前に「-」があるのはなぜですか?混乱するかもしれませんが、もうクリスマスは過ぎ去ったようです。DateDifferenceの順序を変更することで修正されますか?
— たけた

私はそれらを削除してフォーマットを改善し、追加された文字で価格を支払いました。
— DavidC 2013

2

Python 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

R

以下は、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)

出力

出力は次のようになります。

ここに画像の説明を入力してください


継続的に更新する必要があります。つまり、自動的に更新されます
— ドアノブ

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

ゴルフ

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へようこそ!
— ランチャー

よろしくお願いします。私は誤解していると思います、これはそれが再実行されたときにのみ更新されます。私はすぐに編集して再投稿します
— 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)

これは改行を2文字として数えます。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.