Kapan SE akan turun?


13

SE hanya akan dibaca / dibaca hari ini 2017-05-04 pukul 00:00 UTC hingga 00:20 UTC.

Tantangan Anda adalah untuk menghasilkan nilai kebenaran jika SE turun / hanya membaca dan nilai palsu jika SE tidak. Anda mungkin tidak memiliki input apa pun, dan Anda harus menggunakan date builtin untuk menentukan apakah SE hanya down / read (tidak benar-benar menanyakan SE api!) Contoh output:

12:34 UTC 03 May 2017 -> false

00:00 UTC 04 May 2017 -> true

00:20 UTC 20 May 2017 -> undefined, see below

Itu perilaku yang tidak terdefinisi, karena terlalu jauh setelah waktu. Agar lebih jelas, Anda dapat mengasumsikan program Anda akan dijalankan dari UTC 8:00hari ini (5/3/17) hingga UTC 1:00besok (5/4/17).

00:21 UTC 04 May 2017 -> false

00:20 UTC 04 May 2017 -> true

00:10 UTC 04 May 2017 -> true

Perhatikan bahwa setiap nilai kebenaran atau nilai palsu diizinkan, bukan hanya truedan false. Anda harus akurat hingga detik terdekat, dan tidak mengubah jam sistem! Anda dapat berasumsi bahwa program Anda sedang dijalankan pada mesin di +0 UTCzona waktu.


8
sudo time <insert time here> && echo true
Okx

8
Saya sarankan memperbarui kasus uji untuk menggunakan format tanggal universal daripada Amerika.
Shaggy

12
Langkah # 1, memicu tentara bot ke DDoS SE, Langkah # 2, kembalikan "1"
user2023861

9
Pertama, sebagai Manajer SO SRE, saya ingin mengatakan bahwa saya suka pertanyaan ini. Kerja bagus! Namun, saya ingin mengingatkan orang bahwa situs ini tidak akan sulit ... hanya dalam mode baca-saja. Yang mengatakan, saya akan memilih jawaban untuk pertanyaan ini untuk membantu saya menentukan kapan harus memulai prosedur.
TomOnTime

3
Itu berarti jawaban Anda sendiri tidak valid, bukan? Begitu juga banyak jawaban lain; baik revisi asli Anda maupun kasus uji saat ini tidak menyebutkan detik.
Dennis

Jawaban:


15

05AB1E , 32 26 11 9 8 byte

žažb«21‹

Penjelasan:

ža          Is the current hour &
  žb        current minute
     «      concatenated
        ‹   less than
      21    twenty one?

Cobalah online!


16

JavaScript (ES6), 26 24 23 22 21 byte

Disimpan 3 byte berkat Shaggy dan 1 byte berkat Luke .

_=>new Date/12e5%72<1

Cek apakah waktu yang berlalu pada hari ini kurang dari 1200000 ms (1200 atau 20 menit). Menganggap downtime adalah 20 menit, bukan 21, yang tampaknya merupakan kasus dalam pos tertaut. 00:20UTCadalah batas atas eksklusif.


Simpan 2 byte dengan menggunakan new Datebukan new Date().
Shaggy

<2untuk menyimpan byte lain.
Shaggy

1
Anda tidak membutuhkan +; /secara otomatis dikonversi new Dateke a Number.
Lukas

Apakah deklarasi fungsi (_ =>) diperlukan? JavaScript dapat berjalan secara global.
Brilliand

@Brilliand Ya, jika tidak, output akan dibutuhkan, makhluk terpendek alertyang jauh lebih lama
ASCII-hanya

9

Python 2 , 41 39 byte

Disimpan 2 byte berkat Erik the Outgolfer

import time
print time.time()/1200%72<1

Cobalah online!

Menggunakan algoritma yang sama dengan jawaban JS dan Arang saya.


Apakah /72<1berbeda dari <72?
xnor

@ xnor whoops sorry salah menyalin, diperbaiki sekarang
ASCII-hanya

Tidak, maksud saya bahwa saya pikir print time.time()/1200<72akan menjadi cara yang lebih pendek untuk mengekspresikan hal yang sama.
xnor

@ xnor Saya cukup yakin bahwa hanya bekerja pada hari pertama zaman
ASCII-hanya

Ups, maksud saya %1200/72<1-> %1200<72. TIO Anda tertaut ke %1200/72<1versi - apakah itu kesalahan?
xnor

7

Jelly , 9 byte

6ŒT|0Ḍ<21

Harus TZdiatur ke UTC, yang merupakan kasus untuk TIO.

Cobalah online!

Bagaimana itu bekerja

6ŒT|0Ḍ<21  Main link. No arguments.

6ŒT        Get the current time as a string, in the format HH:MM.
   |0      Bitwise OR each character with 0. This casts the characters to int and
           maps the non-digit character : to 0.
     Ḍ     Undecimal; convert from base 10 to integer.
      <21  Compare the result with 21, so 00:00 to 00:20 return 1, all others
           return 0.

(Semua orang) Outgolfed oleh Dennis! Pekerjaan yang baik!
programmer5000


If the downtime latest 'til 00:21, I could save a byte...
Dennis


4

zsh, 38 37 bytes:

date +%H\ %M|read h m;((h==0&&m<21))

4

bash, 40 bytes:

read h m< <(date +%H\ %M);((h==0&&m<21))

3

JS (ES6), 52 50 49 bytes

y=>(x=new Date).getUTCMinutes()<21&&!x.getUTCHours()

Why is Date so long? Just gets the minutes past 00:00 and returns true if they are < 21, and false otherwise.


Save 2 bytes by using new Date instead of new Date().
Shaggy

2
-1 this doesn't check the date
ASCII-only

@ASCII-only the question says it dosen't have to.
programmer5000

Save another byte with y=>(x=new Date).getUTCMinutes()<21&&!x.getUTCHours().
Shaggy

1
Save another 6 bytes by using local time instead of UTC - the question says you may assume local time is UTC.
Brilliand

3

APL (Dyalog), 14 bytes

∧/1 20>2↑3↓⎕TS

∧/ is it all-true (AND reduction) that

1 20> these numbers are greater than

2↑ the first two elements of

3↓⎕TS the current Time Stamp with three elements dropped


What character is the ?
programmer5000

@programmer5000 (Quad) is a prefix for system names in APL. It is supposed to be an empty rectangle.
Adám

3

Charcoal, 25 bytes

‹﹪÷UPtime.time⟦⟧¹²⁰⁰¦⁷²¦¹

Prints - for truthy, nothing for falsy.

Explanation

    UPtime.time⟦⟧          Python function time.time()
   ÷               ¹²⁰⁰      Divided by 1200
 ﹪                    ¦⁷²   Modulo 72
‹                         ¦¹ Less than 1

Try it online!


What does the ⟦⟧ do here? Do you need a list or arrowlist literal?
Erik the Outgolfer

Yeah, a list is required here, but now that I think about it I should make it optional
ASCII-only

Oh, so it's a list of arguments? Yeah, you should make it optional, calling the function without arguments by default.
Erik the Outgolfer

@EriktheOutgolfer Done
ASCII-only

3

Alice, 17 bytes

/o
\T@/4&;'-.C+n

Try it online!

Assumes to be run on a machine whose timezone is set to UTC (like the TIO server).

Explanation

While in Ordinal mode, the IP bounces diagonally up and down through the program. While in Cardinal mode, the IP wraps around the edges like most other Fungeoids.

/   Reflect to SE. Switch to Ordinal.
T   Push a string representing the current date and time, in the format:
    YYYY-MM-DDTHH:MM:SS.mmm±AA:BB
/   Reflect to E. Switch to Cardinal.
4&  Run the next command 4 times.
;   Discard four elements from the top of the stack. Since we're in Cardinal mode,
    this attempts to discard four integers. But the top stack value is a string so
    it gets implicitly converted to all the integers contained in the string. So
    year, month, day, hour, minute, seconds, milliseconds, timezone hour,
    timezone minute will be pushed separately. Then the last four of these
    will be discarded, so that we end up with the minute and the hour on
    top of the stack.
'  Push 21.
-   Subtract it from the minutes. Gives something negative for minutes 0 to 20.
.C  Compute the binomial coefficient n-choose-n. This gives 0 for negative
    results and 1 for non-negative ones. SE is down if both this value and
    the current hour are zero.
+   Add the two values. Iff they are both zero, we still get a zero.
n   Logical NOT of the value. Turns 0 into 1 and everything else into 0.
\   Reflect to NE. Switch to Ordinal.
o   Implicitly convert the result to a string and print it.
@   Terminate the program.

3

MATL, 10 bytes

Thanks to Dennis for several corrections

Z'1\480*7<

Try it online!

Explanation

Z'    % Push current date and time as a float. Integer part is day, decimal part is time
1\    % Modulo 1. This gives the time, in units of one day
480*  % Multiply by 480
7<    % Less than 7? Note that 21 minutes / one day equals 7 / 480. Implicitly display. 

Should that be l72 rather than 171 in your explanation?
Dennis

@Dennis Yes, thanks for catching that!
Luis Mendo

It's still 72 vs 71. Also wouldn't this return 0 at 00:20?
Dennis

@Dennis Yes, this would return 0 at 00:20, but would return 1 at 00:20 minus a small fraction of a second (given by the machine epsilon for double data type times 86400). The challenge says "you must be accurate to the nearest minute", so I understand it's acceptable
Luis Mendo

That's probably what the post on Mother Meta meant, but the challenge has 00:20 -> true as a test case. Left a comment on the question.
Dennis

3

Python 3 (NON-REPL) + time, 81 77 bytes

-4 bytes thanks to Bahrom

import time;e=str(time.strftime('%H:%M'));print(e[:2]=='00'and int(e[3:])<21)

A naïve approach, turning the current date to string and analysing its characters.


You can save a whole bunch of bytes by using a different format string, and if you're using the shell, you don't need the print function: import time;e=str(time.strftime('%H:%M'));e[:2]=='00'and int(e[2:])<21. This can probably be golfed even further too.
Bahrom

(pretty new to golfing and the rules) but in the shell this also seems to output the correct results: import time;time.localtime();_.tm_hour==0 and _.tm_min<21. We're not beating ASCII-only anyway lol
Bahrom

Ok, I cannot edit now, maybe later
Mr. Xcoder


2

Bash, 55 53 51 50 bytes

-1 byte from @robbie0630's comment.

a=`date +%s`;echo $[1493856000<a&a<1493857200?1:0]

Try it online!

The advantage of this solution is that it works for any date (so will return 1 only for the period defined in the challenge, as it uses epoch time).


2
Shave off a byte by replacing $(...) with `...`
robbie

1

Swift + Foundation, 178 bytes

import Foundation;var d=String(describing:Date());func g(_ s:Int)->String{return String(d[d.index(d.startIndex,offsetBy:s)])};print(g(11)+g(12)=="00" ?Int(g(14)+g(15))!<21:false)

Quite short by swift standards. Check it out!

As in my Python answer, I basically converted the current Date to a string and have analysed its digits, depending on which I printed the bool.


1

R, 65 bytes

library(lubridate)
x=Sys.time()
print(all(!hour(x)&minute(x)<21))

Checks if the hour == 0 and the minute < 21.


1

PostgreSQL, 43 characters

select now()between'170503'and'170503 0:20'

Just because I prefer SQL for date/time calculations.

Sample run:

bash-4.3$ psql -c "select now()between'170503'and'170503 0:20'"
 ?column? 
----------
 f
(1 row)
Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.