| Bytes | Lang | Time | Link |
|---|---|---|---|
| 000 | Pieday 1 | 240809T181650Z | Pi Day L |
| 229 | Pascal FPC | 230315T175316Z | roblogic |
| 226 | Pascal | 230314T151415Z | Kai Burg |
| 045 | Japt | 230315T122625Z | Shaggy |
| nan | Zsh* | 230314T165907Z | roblogic |
| nan | 05AB1e | 230314T155628Z | Kevin Cr |
| nan | Go | 230314T155836Z | bigyihsu |
| 041 | CJam | 160102T100703Z | Martin E |
| nan | PHP | 160103T033928Z | Benoit E |
| nan | Perl | 160102T093907Z | primo |
| 124 | TIBASIC | 160102T012651Z | Conor O& |
| 181 | AppleScript | 160102T192702Z | Addison |
| nan | Javascript ES6 | 160102T024223Z | nderscor |
| nan | Japt | 160102T141355Z | nicael |
| nan | Python 2 | 160102T012733Z | Zizouz21 |
| 179 | Python 3 | 160102T035135Z | Zach Gat |
| nan | Python 3 | 160102T040218Z | Aleksi T |
| 124 | Ruby | 160102T011847Z | Doorknob |
Pieday 1, 0 bytes
Pieday does this by default when no input is entered
Pascal (FPC), 263 229 bytes
uses sysutils,RegExpr;var x:array[0..2]of string=('.*:03:14','.* 03:14.*','14-3.*');y:array[0..2]of string=('Second','Minute','Day');i:word;begin
for i:=0to 2do if ExecRegExpr(x[i],DateTimeToStr(Now))then writeln('Pi ',y[i]);end.
Might be shortened by using if..then..elseif.. instead of complicated arrays & loops.
Pascal, 226 Bytes
See also FreePascal.
This program requires a processor complying to ISO standard 10206 “Extended Pascal”.
program p(output);var t:timeStamp;begin getTimeStamp(t);with t do write(subStr('Pi Day ',1,9*ord(month=3))+subStr('Pi Minute',1,9*ord(hour in[3,15]))+subStr('Pi Second',1,9*ord(minute=3)):9*ord(14 in[day,minute,second]))end.
Ungolfed:
program piDMS(output);
var
ts: timeStamp;
begin
getTimeStamp(ts);
{ `with t do ` is two characters shorter than six times `t.` }
with ts do
begin
writeLn(
{ subStr(string, firstCharacterIndex, length) }
subStr('Pi Day ', 1, 9 * ord(month = 3)) +
subStr('Pi Minute', 1, 9 * ord(hour in [3,15])) +
subStr('Pi Second', 1, 9 * ord(minute = 3))
: 9 * ord(14 in [day, minute, second])
);
end;
end.
216 characters if
- the implementation-defined value of
maxCharhas an ordinal value ≥ 59 and - neither
chr(3)orchr(14)of the implementation-defined set ofcharvalues indicate an end of line (Pascal does not permit multiline strings).
program p(output);var t:timeStamp;begin getTimeStamp(t);with t do year:=index(chr(month)+chr(day)+chr(hour mod 12)+chr(minute)+chr(second),'');write(subStr('Pi SecondPi Minute Pi Day ',37-9*t.year):9)end.
NB:
The string literal '' is chr(3) + chr(14).
Japt, 48 47 45 bytes
:\ I can definitely do better than this! Outputs undefined if it's not a Pi date/time. Second line include a trailing space.
`DÃÕsMÔSSeÖ`qÅæÏgKs6 f"%d+" ã2)e#;ìF
©i"Pi
Test it, or test:
`...`qÅæÏgKs6 f"%d+" ã2)e#;ìF\n©i"Pi
`...` :Compressed string "DaysssMinutesSecond"
q :Split on
Å : "s"
æ :Get first element to return true
Ï :When its index is passed through the following function
g : Index into
K : Date
s6 : To locale string (M/D/Y, h:m:s A/PM)
f : Match
"%d+" : RegEx /\d+/
ã2 : Sub-arrays of length 2
) : End indexing
e : Is equal to
#; : 59
ì : Converted to digit array in base
F : 15
\n :Assign to variable U
© :Logical AND with
i"Pi : U prepended with "Pi "
Zsh*, 93 88 83 (98-15) bytes
case `date` in *Mar\ 14*)t=Day;;*\ 03:14*)t=Minute;;*03:14\ *)t=Second;esac
<<<Pi\ ${t?No Pi Time}
Try it online! (98-15 bytes)
103-15 bytes
93 bytes
107-15 bytes, using associative array
Used extendedglob for matching the case patterns. If $t wasn't set (${t?}), then it prints "No Pi Time" to stderr.
05AB1e, score: 31 (46 bytes - 15 bonus)
žfžeža12%žbDžc)2ôJƵÖk”€º‚Ž™Ù…Þ”#…Pi ìć…No ìªsè
Try it online or try it online with emulated datetime.
Adding the No Pi Time bonus costed 8 bytes, so it's worth the -15. Here it is without the bonus:
žfžeža12%žbDžc)2ôJƵÖk”‚Ž™Ù…Þ ”#„Pirèðý - Try it online or try it online with emulated datetime.
Explanation:
žf # Push the current month
že # Push the current day
ža # Push the current hours (24-hours format)
12% # Modulo-12 to make it a 12-hours format
žb # Push the current minutes
D # Duplicate the current minutes
žc # Push the current seconds
) # Wrap all values on the stack into a list
2ô # Split it into pairs
J # Join each pair together
ƵÖ # Push compressed integer 314
k # Get the first 0-based index of 314 in this list (or -1 if none are)
”€º‚Ž™Ù…Þ” # Push dictionary string "Time Day Minute Second"
# # Split it on spaces: ["Time","Day","Minute","Second"]
…Pi ì # Prepend "Pi " in front of each:
# ["Pi Time","Pi Day","Pi Minute","Pi Second"]
ć # Extract head; pop and push remainder-list and first item separately
…No ì # Prepend "No " in front of it: "No Pi Time"
ª # Append it to the remainder-list:
# ["Pi Day","Pi Minute","Pi Second","No Pi Time"]
s # Swap so the earlier index of 314 is at the top
è # Use it to index into the list of strings,
# where -1 would get the last item
# (after which the result is output implicitly)
See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress large integers?) to understand why ”€º‚Ž™Ù…Þ” is "Time Day Minute Second" and ƵÖ is 314.
Go, 211 - 15 = 196 bytes
import."time"
func f(){N,s:=Now(),"Pi "
M:=N.Minute()
if _,m,d:=N.Date();m==3&&d==14{s+="Day"}else if N.Hour()%12==3&&M==14{s+="Minute"}else if M==3&&N.Second()==14{s+="Second"}else{s="No "+s+"Time"}
println(s)}
Prints to STDERR.
CJam, 41 bytes
et[3E]#"
Pi Day
Pi Minute
Pi Second
"N/=
Test it here. Alternatively use this link to stub the result of et for easier testing.
Explanation
et e# Get the current datetime as an array with the following elements:
e# - Year
e# - Month
e# - Day
e# - Hour
e# - Minute
e# - Second
e# - Millisecond
e# - Weekday
e# - Tickrate or something.
[3E] e# Push the array [3 14].
# e# Find the position of this subarray in the current datetime array. Let's see
e# what results we can get:
e# - Year 3 is in the past and there is no 14th month, so we can't get 0.
e# - Pi day will give result 1.
e# - Day 3, hour 14 would give 2.
e# - Pi minute will give result 3.
e# - Pi second will give result 4.
e# - Second 3, millisecond 14 would give 5.
e# - Weekday and tickrate won't be 14, so we'll never get 6 or 7.
e# - If [3 14] isn't found at all we get -1.
"\Pi Day\\Pi Minute\Pi Second\"
e# Push this string (with linefeeds instead of backslashes.
N/ e# Split into lines.
= e# Select the corresponding element. The non-existent "pi hour" and "pi millisecond"
e# would map to empty strings as well as the -1.
PHP, 85 - 15 = 70 bytes
<?=['No Pi Time','Pi Day','Pi Minute','Pi Second'][strpos(@date(Ymdhi_is),'0314')/4];
The main trick use here is the Ymdhi_is date format, at the time of writing, date('Ymdhi_is') returns 201501030258_5828.
md,hiandisare the values who will be replaced by0314if it's Pi-something. Note that all those strings will be always be replaced by a 4-character long string.- They are put in that specific order since
strposwill stop searching at the first occurrence of the needle, so we put them in the order of priority. - A separator between
hiandisis necessary because we don't wantstrposto match a value that would overlap both (thanks to primo for saving bytes here). - The needle is
0314because314would wrongly match 10:31:42 as Pi-Second.
The Y part is the trickiest. We need a prefix to to offset the first occurrence of Pi-something, allowing us to distinguish strpos's return values between false (not found, Pi-nothing) and 0 (found at index 0, Pi-day).
And we want this prefix to be either 4 or 5-character long, since we are planning to divide strpos's return value by 4.
Y is 4-character long, but:
- it will be 5-character long someday, and this will break the program (think about year 10314): the PHP documentation says that
Ywill be replaced by 4 digits, but it's not true. - if you come back in time, at year 314, it will break the program.
Since PHP didn't exist in year 314, and will likely not exist anymore in year 10314, I guess these bugs can be safely ignored.
Note that 0314 can overlap Ymd since:
Ymmdconfiguration: there's no 31st month.YYmmconfiguration: there's no 14th month.YYYmconfiguration: there are less than 40 months.
Also, there's a version without the bugs related to the year, which is 86 - 15 = 71 bytes:
<?=['No Pi Time','Pi Day','Pi Minute','Pi Second'][strpos(@date(D_mdhi_is),'0314')/4];
Perl, 80 - 15 = 65 bytes
print'No 'x localtime!~/(ar | 15:|03:)14/,'Pi ',(Time,Day,Minute,Second)["@-"/4]
Take 2, parsing the string representation of localtime. At present, this looks something like this:
Sun Jan 3 15:14:15 2016
The position of the matched string is used to determine the correct Pi Time.
Perl, 100 bytes
@t=localtime;$t[2]%=12;3-/3/^{@t[$_,$_+1]}->{14}||exit!print'Pi ',(Second,Minute,_,Day)[$_]for 3,1,0
localtime returns the months zero indexed, hence the need for 3-/3/.
TI-BASIC, 124 bytes
Thanks to FlagAsSpam for shaving a few bytes.
"→Str1
getTime
If min({3,14}={Ans(2),Ans(3
"Pi Second→Str1
getTime
If Ans(2)=14 and max(Ans(1)={3,14
"Pi Minute→Str1
getDate
If min({3,14}={Ans(2),Ans(3)
"Pi Day→Str1
Str1
AppleScript, 202 190 187 183 181 bytes
Hey, this isn't so bad after all.
set n to current date
set b to n's time string
if n's date string contains"March 14"
log"Pi Day"
else if b contains"3:14:"
log"Pi Minute"
else if b contains"3:14"
log"Pi Second"
end
I actually found a use for AppleScript's method calling. Go figure. Nope. Just turns out that I'm an idiot. Setting a variable is shorter.
(for those wondering, current date command returns a date-type with the contents "Saturday, January 2, 2016 at 2:46:01 PM" or the like)
Javascript (ES6), 114 112 - 15 = 97 bytes
x=>['Pi Day','Pi Minute','Pi Second'].find((x,i)=>[/ar 14/,/(03|15):14:/,/03:14/][i].test(Date()))||'No Pi Time'
Ungolfed:
x=>
['Pi Day', 'Pi Minute', 'Pi Second'] // array of outputs
.find( // find first element in the array
(x, i)=> // which returns truthy for this function
[/ar 14/, /(03|15):14:/, /03:14/] // array of regex patterns
[i] // get corresponding regex based on index
.test(Date()) // test it against current date, date is automatically cast to string
) || 'No Pi Time' // if no result, then return "No Pi Time"
Thanks for -2 bytes @edc65
Japt, 78 - 15 = 63 bytes
D=Ð)g ¥3©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te
Pretty straightforward - just checks the date for every case.
Explanation:
D=Ð)gget the current date (Ð), store it in the variableDand get the month (g). Why store it in the variable, if it's already one-letter? Because since then you can dress any part of date withDa, whereais the function, returning year, month, date, etc. But otherwise you'd have to doÐ a, see the space.¥3is==3, checking if the month is March.©is&&, i.e. "and".Dfis the day of the month.Eis 14?...:...- typical sets of ternary operatorsDd %Cthe reminder of dividing the hour (Dd) by 12 (C)Dcis the minutesDbare seconds
D=Ð"3/14/11 11:11:11";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te
D=Ð"11/11/11 3:14:11";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te
D=Ð"11/11/11 00:3:14";
Dg ¥2©Df ¥E?"Pi Day":Dd %C¥3©Dc ¥E?`Pi M©e`:Dc ¥3©Db ¥E?`Pi SeÖ:No Pi Te
Python 2, 219 186 183 Bytes (198-15)
I tried
Ungolfed:
from datetime import datetime
now = datetime.now()
output = ['Pi Day', 'Pi Minute', 'Pi Second', 'No Pi Time']
if now.month == 3 and now.day == 14:
print output[0]
elif now.hour == 2 and now.minute == 13:
print output[1]
elif now.minute = 2 and now.second == 13:
print output[2]
else:
print output[3]
Golfed:
from datetime import *
n=datetime.now()
a=n.minute
if n.month==3and n.day==14:print'Pi Day'
elif n.hour==2and a==13:print'Pi Minute'
elif a==2and n.second==13:print'Pi Second'
else:print'No Pi Time'
Python 3, 179 bytes
import functools as F,datetime as D
T,G=D.datetime.now(),getattr
F.reduce(lambda i,j:print("Pi "+i.title())if G(T,i)/G(T,j)==3/14else j,"month day hour minute second".split(" "))
Python 3, 137 - 15 = 122 bytes
import time
T=list(time.localtime())
T[3]%=12
print({1:'Pi Day',3:'Pi Minute',4:'Pi Second'}.get(bytes(T[1:6]).find(b'\x03\x0e'),'No Pi Time'))
The 12-hour requirement was unfortunate, as this would've been 118-15=103 bytes without it:
import time
print({1:'Pi Day',3:'Pi Minute',4:'Pi Second'}.get(bytes(time.localtime()[1:6]).find(b'\x03\x0e'),'No Pi Time'))
Ruby, 125 124 chars
i=[*[(t=Time.new).month,t.day,t.hour,t.min,t.sec].each_cons(2)].index [3,14];i&&$><<['Pi Day','','Pi Minute','Pi Second'][i]
Alas, the cleverer %i[month day hour min sec].map{|x|Time.new.send x} is longer.
The key here is the use of each_cons to avoid repetition (see the last few lines of the explanation below).
i= # send i (index) to...
[* # convert to array (splat)...
[
(t=Time.new).month, # the current month...
t.day,t.hour,t.min,t.sec # etc... (duh)
]
.each_cons(2) # each consecutive two elements
] # [[month, day], [day, hour], [hour, min], etc]
.index [3,14]; # first occurrence of [3, 14]
i&& # shorthand for "if i"...
$><< # output...
[
'Pi Day', # [month=3, day=14] is Pi Day
'', # [day=3, hour=14] isn't anything
'Pi Minute', # [hour=3, min=14] is Pi Minute
'Pi Second' # [min=3, sec=14] is Pi Second
][i] # index by index (obviously)