Hot answers tagged

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 ...


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!


8

Perl 6, 33 bytes {[+] 1..Date.new(24,|@_).week[1]} Try it online! Takes input as month,day. This initialises a date in the year 24 (since that year starts on Monday and is a leap year), and calculates the sum of the range of 1 to the current week number.


8

JavaScript (ES6),  188 ... 168  160 bytes Assumes that the system is set up to UTC time (as the TIO servers are) Returns a Date instance. y=>(D=d=>new Date(y,8,n+=d))(((g=y=>D((n=80,d=D((3*-~(y/100)>>2)+1.554*(x=12*-~y%19)+y%4/4-y/314.6-.9).getDay())%2+2*(n%!d>.63&x>6))/864e5)(++y)-g(--y)+5)%30<1) Try it online! Or ...


7

Zsh, 14(?) bytes If N is substituted in place of $1 (as described in the prompt), then 14 bytes. If N is given as an argument, then 16 bytes. time (: {0..$1}) Try it online! Uses the builtin time (you can verify that this is a Zsh builtin: run type time). The time to expand the brace expansion increases with the input. You might think to use time sleep $...


6

APL (Dyalog Unicode), 12 bytesSBCS Full program. Returns elapsed time in seconds, followed an "s". Runtime on TIO is roughly linear with N, with a coefficient of about 6×10-10. Uses the dfns library, but per OP, import isn't counted. 's',⍨cmpx'⍳N' Try it online! '⍳N' expression generating the ɩntegers 1 through N cmpx time the execution of that ...


6

JavaScript (ES6),  53  51 bytes Takes input as (month)(day). This is longer than my other answer but does not use any date built-in. m=>g=d=>--m?g(d+31+~m%9%2-(m==2)):~(d=~-d/7)*~-~d/2 Try it online! Commented version m => // m = month g = d => // g is a recursive function taking the day d --m ? ...


6

Python 3, 149 \$\cdots\$ 145 140 bytes from datetime import* def f(d): n,s=(date(*d)-date(1,1,1)).days+1137143,"" for i in[144000,7200,360,20,1]:s+=f".{n//i}";n%=i return s[1:] Try it online! Takes Gregorian date as [year, month, day] list and returns Mayan date as f"{B'ak'tun}.{K'atun}.{Tun}.{Winal}.{Day}"(loosely as a python f-string).


5

JavaScript (ES6),  61 50 49  47 bytes Assumes that the system is set up to UTC time (as the TIO servers are) Takes input as (month)(day). m=>d=>(n=new Date(68,m-1,d+738)/6048e5|0)*-~n/2 Try it online! How? Given the month \$m\$ and the day \$d\$, we generate the corresponding date in \$1968\$ (the closest leap year before Epoch) with an ...


5

R, 29 28 bytes cat(system.time(!1:9e6)[3],"s") Try it online! A full program printing the number of seconds elapsed complete with unit. The 9e6 is not counted per the rules and can be replaced with any other number. Thanks to @RobinRyder for saving a byte! An alternative would be paste(system.time(!1:9e6),"s"), but this also prints our four other times (...


4

JavaScript (ES6), 96 bytes Assumes that the system is set up to UTC time (as the TIO servers are) Takes input as 3 distinct parameters (year, month, day). (y,m,d)=>[144e3,7200,360,20,1].map(k=>n/(n%=k,k)|0,n=new Date(y+4e3,m-1,d+395335)/864e5).join`.` Try it online! How? We can't safely pass a year \$y<100\$ to the Date constructor, as it gets ...


4

Red, 38 bytes func[d][(t: pick d - 2 14)*(t + 1)/ 2] Try it online! Takes input as a date in any reasonable format: dd-mm-yyyy, yyyy-mm-dd, dd-MMM-yyyy. Red's date datatype fourteenth field holds the week nember.


4

05AB1E, 20 19 bytes •Σ₁t•ºS₂+6šI£O+7÷LO -1 byte thanks to @Arnauld. Input in the order month, day, year (although the year is ignored). Try it online. Explanation: •Σ₁t• # Push compressed integer 5354545 º # Mirror it: 53545455454535 S # Convert it to a list of digits: [5,3,5,4,5,4,5,5,4,5,4,5,3,5] ...


4

J, 16 14 19 bytes (20 - 1 for N) echo's',~":6!:2'i.N' Try it online! -2 bytes thanks to Adam -- after looking at his answer I realized I didn't need to sum the integers, just generate them +6 bytes thanks to Adam for pointing out I missed the unit Generates the integers 0..N-1, times it, and prints it to stdout. 's',~ prepends the unit s for seconds.


4

05AB1E, 12 10 bytes ƒžc})¥O's« -2 bytes thanks to @ExpiredData. Either add the \$n\$ as leading portion (i.e. 100ƒžc})¥O's«) or simply use \$n\$ as STDIN input. Outputs the execution time in whole seconds (without space). Try it online. Explanation: ƒ # Loop in the range [0, n]: žd # Push the current time in seconds }) # ...


4

PowerShell, 38 bytes param($n)$a={1..$n};Measure-Command $a Try it online!


3

Python 3.8 (pre-release), 94 \$\cdots\$ 82 77 bytes lambda d:(n:=(date(*d)-date(2020,1,1)).days//7+1)*-~n/2 from datetime import* Try it online! Function takes date as a (year, month, day) tuple and returns the number of ACUs. Tests ported from Arnauld's answer.


3

JavaScript (Node.js), 74 bytes d=>(i=5,g=(a,m=20-8%--i)=>i?g(a/m|0)+'.'+a%m:a)(new Date(d)/864e5+1856305) Try it online! Input as yyyy-MM-dd format string. Thanks Arnauld, save 4 bytes.


3

05AB1E, 54 52 bytes 365*Š3‹¹α4т‚DPª÷®β•ë˜¿•ºS₂+²£`•H`Ø•OŽQív₂y-‰R`})R'.ý Try it online! First step: compute the day number. 365 # literal 365 * # multiply # => 365*year is left on the stack for now Š # get the other two inputs # => day is left on the stack 3‹ ...


3

C# (Visual C# Interactive Compiler), 108 bytes An alternate version suggested by @Adám, with a distinct output format for the edge case 2239. using System.Globalization;string f(int y)=>y<2239?new DateTime(y+3761,3,24,new HebrewCalendar())+"":"1221"; Try it online! C# (Visual C# Interactive Compiler),  134 130 122  121 bytes Saved 8 ...


3

Raku (18 or 25) Depending on one's definition of a "standard" library for Raku... use Timer; # uncounted import line say timer {[+] ^N} or [+] ^N;say now -BEGIN now $/=now;[+] ^N;say now -$/ [+] ^N sums all numbers from 0 to N, so the bigger it gets, the more ops it does. The now - BEGIN now bit is a common idiom in Raku that virtually makes such ...


3

Python 2.7 - 32 20 bytes print t(number=N),'s' We can take advantage of the different scoring rules here. timeit.timeit has been in the standard library since 2.6, so we get to ignore the from timeit import timeit as t and hence 31 bytes that would have cost. timeit is designed to be able to take a statement for execution as a parameter, but has a ...


2

APL (Dyalog Unicode), 86 85 bytesSBCS Now that Arnauld has posted his C# solution, I can reveal my equivalent anonymous tacit prefix function. ⎕NEW{⎕USING←'System'⋄0::1221⋄⍺⍺DateTime((3761+⍵)3 24,⍺⍺Globalization.HebrewCalendar)} Can't try it online as this only works under Windows. (.NET Core support is planned for this year!) ⎕NEW{…} function derived ...


2

Perl 5, 313 278 bytes sub f{sub t{timegm_nocheck(0,0,0,pop,8,pop)}$Y=pop;eval'(R,N,Q)=map{X=12*(_%19+1)%19;N=1.554*X-2.9-_/314.4+_%4/4+_/100%99-_/400%9;I=intN;D=t(_,I)/86400%7;M=N-I;P=D=~/[361]/||D==4&&M>1?1:D==5&&M>=.63&&X>6?2:0;t(_,I+P),I+P}Y,Y+1;t(Y,N+82+((Q-R)/432e3)=~/1|7$/)'=~s/[A-Z_]/\$$&/gr} Try it online! ...


2

C# (Visual C# Interactive Compiler), 186 163 bytes string f(int[]t){int x,n=(int)(new DateTime(t[0],t[1],t[2])-new DateTime(1,1,1)).TotalDays+1137143;return string.Join(".",new[]{144000,7200,360,20,1}.Select(e=>{x=n/e;n%=e;return x;}));} Try it online! Edit: Use int[] as input instead of DateTime to meet the specification better. Thanks @keizerharm for ...


2

PHP, 67 59 57 bytes <?=(($d=(int)(date(z,strtotime($argv[1]))/7+1))+$d*$d)/2; Try it online!


2

C (gcc), 34 32 38 34 32 bytes g(n){n=n/604800-2607;n=n*-~n/2;} Takes as input the number of seconds since January 1st, 1970 (the Unix epoch) at 0:00 AM UTC time. Explanation: n=n/604800-2607; Divide by number of seconds in a week and subtract the number of weeks from Jan 1 1970 to Jan 1 2020 minus one so we don't have to increment later. n=n*-~n/2; ...


2

PowerShell, 48 bytes Thanks to @mazzy (1..(((Date|% DayOfYear)/7)+1)|measure -sum).sum Try it online! Originally 76 bytes [Linq.Enumerable]::Sum([Linq.Enumerable]::Range(1,(Get-Date).DayOfYear/7+1)) Try it online!


2

Ruby, 42 bytes A function that takes the month and date. Time#yday returns the day of the year. ->m,d{k=1+~-Time.gm(4,m,d).yday/7;k*-~k/2} Try it online!


2

Perl 5 -ap -MTime::Local -MTime::Piece, 61 bytes $_=($w=(gmtime timegm 0,0,0,$F[0],$F[1]-1,24)->week)*($w+1)/2 Try it online!


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