Hot answers tagged

72

C (gcc), 40 36 32 29 26 24 bytes i;f(){--i&&f(sleep(7));} Try it online! -3 thanks to @gastropner. -1 recursive approach thanks to @AZTECCO. 4294967295*7/86400/365.25 ~ 952.69


36

Python 3 (Excluding CPython on Windows), 28 bytes import time time.sleep(3e10) Try it online! (Remember to put something in your will so future generations can check that it ended on time.) time.sleep(seconds) takes either an int or a float. 1000*365.2422*24*60*60/3e10 == 1.051897536 which is an error of less than 10%.


27

PHP, 936 bytes for($a=explode('-',gzinflate(base64_decode('dVTRbtswDPwV/YANKXZq+zFJ1wRts3VZtgB7Y2Mm1ipLAO0089+PtNIuHbAnAzySd+RRNkVZ6XxSJUsMdES1g66x/tgHn5iiKnSms+Q+NF7Nami7xJTajLFtE1ro1D0eDkidZJe6itnQYqfWUNsYNsV1OHgKyNHJ9G/rryfr98M7wyT2mfma8KzuYf8SG2Wx0Rqot179AK/mJ0JB8qhpZ52z0KoVehrUCoguEhjP38i2g0OS2PRK1kOqnoJ7kXAk/wn7BrjJFgYXJH2qdaHLZM0UQLW6428bSCaZZmPFHYF/...


26

APL (Dyalog Unicode), 13 12 bytesSBCS Anonymous tacit prefix function. 0-indexed. February is 29. 31-1∘=+2|7∘| Try it online! 31- thirty-one minus…  1∘= the equal-to-one'ness…   + plus…    2| the two-mod of…     7∘| the seven-mod'ness The reason I ask this near-duplicate is curiosity about mathematical patterns in the sequence of numbers. For ...


24

bash, 26 bytes I think part of the challenge here is to not have a signed 32 bit overflow, so: ping -i86400 -c365243 t.co The idea here is to make 1000 years of pings (365243), once per day (86400). "t.co" is simply a four character internet hostname (in this case, a link shortener). If your local host table has a one character hostname, you can ...


22

MATL, 6 5 bytes 35WY. This waits for 34359738368 seconds, which is a little more than 1089 years and a half. Don't try it online! Explanation 35 % Push 35 W % 2 raised to that. Gives 34359738368 Y. % Pause for that many seconds


20

Ruby, 10 bytes sleep 3e10 Try it online! There are approximately \$3*10^{10}\$ seconds in a thousand years.


18

PowerShell, 35 32 24 21 19 bytes 1..3e4|%{sleep 1mb} Try it online! Strangely, the maximum seconds value for Start-Sleep is 2147483. No, I don't know why it's such an odd value. That works out to a little over 2 megabytes (2097152). 1mb * 30000 / 86400 / 365.25 is 996.821051030497, so a little under 1000 years. I could get more exact using a different ...


18

JavaScript (ES6), 13 bytes Takes input as (h)(m). Returns true for 01:00, 02:00 and 13:00, or false for anything else. h=>m=>26%h<!m Try it online! How? Testing \$26\bmod h<\delta_m\$ is equivalent to test that we have \$m=0\$ and \$26\equiv 0\pmod h\$. For \$0<h\le23\$, we have \$26\equiv 0\pmod h\$ iff \$h\$ divides \$26\$, i.e. \$h\in\...


17

6502 Machine Code on an Apple II, 10 9 bytes Code is actually platform-independent, other than it relies on the Apple's clock speed of 1.023 MHz for timing. Code starts at address 0x0000: 0000: A2 CA F6 44 F0 FB D0 F8 F7 Saved an additional byte. Details are below original answer. Original answer: Code starts at address 0x0059: 0059: A2 08 F6 60 D0 FA ...


15

Bash, 1229 1124 bytes -103 bytes with @GammaFunction's excellent comments, removing a couple of unproductive substitutions (Adams), and refactoring the code to use the date offset from the previous date rather than the absolute date for each presidency. M=(. Ja F Mar Ap May Jun Jul Au S O N D) A=40000 B=80000 s=son a=James c=Andrew d=William e=Harri$s f=...


15

05AB1E, 6 bytes 27;°.W Inspired by the other answer in 05AB1E. Waits for 1027/2 milliseconds, or about 1002 years. Explanation: 27 push the number 27 ; divide by 2 ° replace X by 10 to the power of X .W wait that number of milliseconds Try it online!


14

JavaScript (ES6),  41 40  39 bytes Takes inputs as (h)(m). h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90 Try it online! How? Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$: $$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}...


14

Python, 45 43 38 27 bytes For inputs up until 239999: lambda n:n/100%100<60>n%100 You can try it online! Thanks @Jitse and @Scurpulose for saving me several bytes ;) For inputs above 239999 go with 36 bytes: lambda n:n/100%100<60>n%100<60>n/4e3


14

JavaScript (ES6),  62 60  59 bytes Takes input as a 0-padded string. Returns \$0\$ for false or a positive integer for true. s=>(m=s[2]+s[3])<13&31-(m^2?~m%9%2:s%4?1:2)>(s/=1e4)&&~~s*m Try it online! or Check all possible outputs against an ungolfed implementation Commented s => // s = input string (m =...


13

Poetic, 706 bytes counting a day,one month<t-o>twelve i got frustrated doing a list i do say,o,i edited a list,a month&a day count in twelve(in December)to one(January)i listed a day"s count,then the numeral months and once i am ready,o,i think i got a number to say a number,o,i know a count o,i say i am thirty if one"s short i am ready,o,i know a ...


12

Excel, 1243 1206 1180 bytes -37 bytes by subtracting from all the dates -26 bytes by by fiddling with the subtraction values =CHOOSE(MATCH(A1-65^4,{39805,119679,159679,239679,319679,399679,439679,519679,559679,559779,599679,639679,650084,679679,719679,759679,799790,839679,919679,959679,960294,999679,1039679,1079679,1119679,1160289,1239679,1279679,1359679,...


12

T-SQL, 1169 981 979 977 bytes Holy cow, I figured out string compression in SQL (available in SQL 2016 and above): SELECT TOP 1 STUFF(value,1,8,'') FROM d,STRING_SPLIT( CAST(DECOMPRESS(CAST('H4sIAAAAAAAEAHVT23LaMBD9FX1AxiMZg+1HIAWGhDaltMz0bYMXrEaWOmsc6r/vrpw27kOHB8ZnL+fs2VWqTa6NKe+DB1epA3XNz7tU61LABRCcXtSnZ2hAQCPgGgNdUB0Tteja+s6U5STmWufU0ll/...


12

Pyke, 4 bytes ~%R@ I have no idea how does this work (actually, after reading the source, I think I do, but Pyke seems extremely weird to me) as I simply used the second half of the Pyke answer by @Blue in the related question OP linked to. Try it online!


12

Javascript, 85 83 Bytes a=d=>d<0?0:d<180?6:d<276?9:d<336?10:d<444?12:d<556?15:d<588?25:d<666?27:d<745?28:27 It takes an input as a float as the months / fractions of months passed since 1958-01-01 (0 for 1958-01-01T00:00:00 and a negative number for any previous date) (Since number of days from some epoch is allowed, I assume ...


11

Jelly, 8 bytes 32œS$ȷ9¡ Try it online! A niladic link which waits for 32 seconds 1 billion times. 32,000,000,000 is within 10% of 31,557,600,000 seconds which is 1,000 years (ignoring leap seconds and ignoring the fact that centuries indivisible by 400 are not leap years).


11

Charcoal, 7 bytes F³³RXφ⁴ Try it online! Link is to verbose version of code with a speed up factor of 1e9 (obtained by changing the ⁴ into a a ¹) so that it doesn't time on TIO. Explanation: F³³ Repeat 33 times. RXφ⁴ Refresh the screen, but delay 1000⁴ milliseconds between refreshes. Although there are 33 refreshes, there are only 32 intervals, so the ...


11

Java (JDK), 23 bytes v->Thread.sleep(7L<<42) Try it online! It's hard to find a short way to write a number in Java. Thread.sleep only accepts a long number of milliseconds. So the standard answer 3e10 doesn't work because it's a double. Casting it to a long would be the appropriate action. But it would still be 1000 too small. So enter 3e13 ...


11

Bash + Core utilities, 26 25 bytes + Bonus imaginary Internet points! egrep '(.)T(11|23|0\1)00' Try it online! Thanks to @mypronounismonicareinstate for pointing out that the ISO 8601 allows omitting the colon in the time part, which saves a byte in the code. (ISO 8601 also allows omitting the hyphens in the date, but that doesn't affect the regex.) This ...


10

APL (Dyalog Extended), 20 19 bytesSBCS Anonymous tacit prefix function taking [year,month,day] as argument. 2!∘⌊7÷⍨43816-⍨⌂days Try it online! ⌂days calculate the number of days since 1899-12-31 43816-⍨ subtract 43816; days since 2019 12 18, i.e 14 days weeks extra 7÷⍨ divide by 7; weeks since 2019 12 18, i.e two weeks extra ⌊ floor; whole weeks since ...


10

Polyglot, 0 bytes When using the formats yyyy-mm-dd or mm-dd-yyyy, the list of palindrome dates are: yyyy-mm-dd: [0101-10-10, 0110-01-10, 0111-11-10, 0120-02-10, 0121-12-10, 0130-03-10, 0140-04-10, 0150-05-10, 0160-06-10, 0170-07-10, 0180-08-10, 0190-09-10, 0201-10-20, 0210-01-20, 0211-11-20, 0220-02-20, 0221-12-20, 0230-03-20, 0240-04-20, 0250-05-20, 0260-...


9

05AB1E, 587 584 568 bytes .•6}©ß þz∊‘Îнúj7a>º ·,$_+šüÑßu?PδIëàá©ā.ǝ/¬j«Ížr‹þVwô¨"¶&ˆ₃ǝαh^¼ì∞öîNÊÌ.ÚáýиÇ÷©Mèé…—¾…тŒ¹/ÈÂÓŒš/«ª³PÉÇJúΓÁ¦';X·₅ï»/„q<ƶÚÙÊtÔιuš2βƒ¼ï\~ö…3ihD·¢ðΘmζ8É9Ïγ=^$¨Ä₆ËÂÊPv5+}þ¯ÑX4hÖdÀÒuàнº₁›ǝΘ³P@¥ùnðT“É)ó_“:Èx³«äƒæ¤∞Wgþ¶š}ô|ićcÁ‘.·ƒp>Z¬Aéγê‰ù‰¥Ó₃#/›pÐT¹Â¹J3—ΛΓkÙ»(áÌ›₃z@ìqW›Â"™raÒ›₂%ïx{ _Ωb≠¹₁ľÊÌ›}çºô|ôëKÝǝÚï,‚£=A©áāY∊~"...


9

C (gcc), 27 bytes 0-indexed. Instead of indexing into a string, I get the day offset (from 28) for the month from a packed bit array. Luckily all the offsets fit in a two-bit representation, so the bit array fits in an integer: I just shift and mask the offset and add 28. f(m){m=0xEEFBB3>>m*2&3|28;} Try it online!


9

R, 56 34 bytes function(d)sum(1:format(d-2,"%V")) Try it online! A function taking an R Date as its argument and returning a number. Works because 2019-12-30 was a Monday, strftime(,"%V") returns the ISO week number and then calculates the relevant triangular number. Thanks to @Giuseppe for saving 17 bytes, and @RobinRyder a further 3!


9

05AB1E, 29 27 26 25 33 bytes ¨12βŽ₅b-‘´`<lp€¸‘Ç.¥@•¿“0p•12в<*O Try it online! Input is in the form [yyyy, mm, dd].


Only top voted, non community-wiki answers of a minimum length are eligible