คริสต์มาสนับถอยหลัง


10

ในจิตวิญญาณของวันหยุดและในขณะที่มีคนเริ่มธีมฤดูหนาว ( สร้างมนุษย์หิมะ! ) ฉันเสนอความท้าทายใหม่

พิมพ์จำนวนวันชั่วโมงนาทีและวินาทีจนถึงวันคริสต์มาส (เที่ยงคืน (00:00:00) 25 ธันวาคม) บนหน้าต่างแบบสแตนด์อะโลน (ไม่ใช่คอนโซล) ในรูปแบบที่ชัดเจนใด ๆ ที่คุณเห็นสมควรและอัปเดตอย่างต่อเนื่องเช่นนี้ การเปลี่ยนแปลงค่า

อินพุต - ไม่มีอะไรต้องอ่านเวลาของระบบ

รหัสที่สั้นที่สุดชนะ :) สตริง "วัน", "ชั่วโมง", "นาที", "วินาที" และ "จนถึงคริสต์มาส" เป็นรหัสฟรี คุณยังสามารถเพิ่มรสชาติให้กับมันหากคุณต้องการ การทำให้รสขึ้นเป็นอย่างยิ่งเพื่อจุดประสงค์ในการสร้างผลผลิตที่ดี คุณไม่สามารถลิ้มรสสตริงเพื่อจุดประสงค์ในการสร้างหมายเลขเวทย์เพื่อบันทึกรหัส


คุณหมายถึงอะไรโดย "ปรุงรสให้มัน"? "วัน", "ชั่วโมง", "นาที", "วินาที" และ "จนถึงวันคริสต์มาส" เป็นสิ่งจำเป็นในผลลัพธ์หรือเพียงแค่ตัวเลือกฟรี "การแต่งกลิ่น" ของสายเหล่านั้นฟรีเท่าไหร่?
Iszi

2
ไม่มีคอนโซล ?? คอนโซลตัวแปลงสัญญาณประท้วง! ผมล้อเล่น. ความคิดดี. สุขสันต์วันหยุด.
Darren Stone

@Iszi พวกเขาไม่จำเป็นต้องใช้ ฉันให้อิสระกับพวกเขาเพื่อที่ว่าหากผู้คนต้องการสร้างผลงานที่ดีจริงๆพวกเขาจะไม่สูญเสียตัวละครมากมาย
Cruncher

1
เที่ยงคืนของคริสมาสต์ไม่ใช่จุดสิ้นสุดของวันคริสต์มาสใช่ไหม
DavidC

2
ไม่ปกติเที่ยงคืนจะเป็นศูนย์ทันทีในวันใหม่ "Midnight Christmas" คือเมื่อคริสมาสต์เริ่มต้น
breadbox

คำตอบ:


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

ดีที่คุณไม่เคยบอกว่าเราทำไม่ได้ ;)

ภาพหน้าจอ

อัพเดททุกเฟรม

จำนวนมายากล1387951200คือคริสมาสต์ - 25 ธ.ค. 2013 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 แต่จะใช้งานได้ในปีใดก็ได้ตั้งแต่เวลา 00:00 น. ของวันที่ 1 มกราคมจนถึง 00:00 นของวันที่ 25 ธันวาคม

คำเตือน: หน้าต่างอาจไม่ตอบสนอง - มันจะทำการอัปเดตต่อไป แต่คุณอาจไม่สามารถย้ายหรือปิดหน้าต่างได้

ป้อนคำอธิบายรูปภาพที่นี่

เลิกเล่นกอล์ฟพร้อมแสดงความคิดเห็น

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

ต่อไปนี้จะอัปเดตตารางที่แสดงวันชั่วโมงนาทีและวินาที (เป็นพัน) อย่างต่อเนื่องจนกระทั่งเริ่มต้นวันคริสต์มาส ฉันไม่แน่ใจว่าจะนับส่วนลดสำหรับสตริงฟรีได้อย่างไร

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

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

นี่คือวิธีแก้ปัญหาสำหรับ R โดยใช้ GTK + ผ่านแพ็คเกจ gWidgets นี่เป็นโค้ดที่น่าเกลียดเพราะฉันไม่คุ้นเคยกับแพ็คเกจ 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


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));}}

Ungolfed

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

ขอบคุณดีใจที่ได้มาอยู่ที่นี่! ฉันเดาว่าฉันเข้าใจผิดนี่จะอัปเดตก็ต่อเมื่อมีการเรียกใช้ซ้ำเท่านั้น ฉันจะแก้ไขและประกาศใหม่เร็ว ๆ นี้
เจมส์ซี

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.