Hot answers tagged

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

Mathematica, 220 218 bytes For[n=1,1>0,n++,For[m=1,1>0,m++,x=Array[a,{m,n}];d=Table[(Norm[x[[i]]-x[[j]]]^2-1)*(Norm[x[[i]]-x[[j]]]^2-y)==0,{i,1,m-1},{j,i+1,m}];If[Not[CylindricalDecomposition[Flatten@{d,y>0},Flatten@{y,x}]],Break[]]];Print[m-1]] Try it online! Un-golfed version: For[ n = 1, 1>0, n++, For[ m = 1, 1>0, m++, x = Array[a, {...


4

Jelly, 14 bytes ŒṖḌD$ƑƇḌQƑƇLÞṪ Try it online! A monadic link taking a list of base-10 digits and returning a list of integers. Added a byte (and switched to numbers) because of the zero padding issue. Added 5 bytes to fix a further issue with zeros pointed out by @KevinCruijssen - thanks! Explanation ŒṖ | Partitions of list ḌD$ƑƇ ...


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


3

APL (Dyalog Unicode), 2 bytesSBCS Anonymous tacit prefix function. Requires ⎕IO←0 ⊃⍒ Try it online! ⍒ gives the "grade". The indices into the argument that would stably sort it in descending order If the first element is less than the second, it gives [1,0] If the the elements are equal, it gives [0,1] If the second element is less than the second, it ...


3

Microsoft PowerPoint (33 Slides, 512 shapes to meet minimum requirements) Storage representation is in hexadecimal. Directions Click the blue square to advance the counter (or propagate the carry), or make an AutoHotKey Script to click it for you. You can view the number's digits at any time using the green buttons. (It causes unintended behavior if you ...


3

APL (Dyalog Extended), 16 bytesSBCS ⎕0+⌈3÷⍨1 2×⌊⎕×√3 Try it online! A full program that takes y then x from standard input and prints a 2-element vector of integers. How it works: the math First of all, note that any Gaussian integer will be placed on the vertical diagonal of a diamond, with the point \$Z\$ placed at \$(x,\sqrt3y)\$ for some integer \$x,...


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

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

Jelly, 7 bytes ṁ€æl/}Z A dyadic Link accepting a list of the two lists on the left and a list of their respective lengths on the right which yields a lists of lists. (A monadic Link accepting only the left argument costs 8 bytes, ṁ€Ẉæl/$Z) Try it online! Or see the test-suite. How? ṁ€æl/}Z - Link: list of lists [a, b], list [length(a), length(b)] } ...


3

R, 69 60 54 51 bytes function(a,b,x,y)cbind(rep(a,y/sum(!(1:x*y)%%x)),b) Try it online! Loosely based on my answer to this question. Takes a,b, and the lengths as x and y, respectively. Returns a two-column matrix. Thanks to Robin Ryder for saving 4 bytes, and then another 3. Relies on the identity \$xy=GCD(x,y)\cdot LCM(x,y)\$; repeats a by \$y/GCD(x,...


3

J, 14 13 bytes ,./@($&>~*./) Try it online! -1 byte thanks to Bubbler This answer takes the two lists as its left arg, and the two list lengths as its right arg. ($&>~*./) is a dyadic hook which applies gcd between the two right arg lengths *./ and the reshapes the two left arg lists $ to that length after opening them &>. At this ...


2

naz, 50 bytes 1x1f1a1o2x1v0m9a1a1o1v0x1f1f1f1f1f1f1f1f1f8s1o1s1o Explanation (with 0x commands removed) 1x1f # Function 1 1a1o # Add 1 to the register and output 2x1v # Store the new value in variable 1 0m9a1a1o # Output a newline 1v # Read variable 1 into the register ...


2

BrainFuck, 41 Bytes -[----->+>+<<]>---<++++[->+.+.<]>+.>--.-. Output 12345678910 Try it online


2

APL, 9 chars/bytes 2≡≢∪∨∘⍳⍨⎕ get the input ⎕ compute least common divisor between n and all integers from 1 to n ∨∘⍳⍨ count of unique values ≢∪ if it's exactly 2, then it's prime 2≡


2

Intcode, 22 bytes 3,0,3,1,2,0,1,2,4,2,99 Fairly basic. IO boilerplate takes up most of the bytecount, given that the language has multiplication as a builtin (2,0,1,2 would be a valid answer, if snippets were allowed)


2

Keg, 5 bytes ¿:0=+ Try it online! Explanation ¿: # Take 2 inputs 0= # Check whether the input is 0 # (Yields 1 if the input is 0) # (Yields 0 otherwise) + # Add the input with this result # i.e. 0->1, 5->5 Keg, 4 bytes Keg is not yet updated :0=+


2

Perl 6, 49 bytes {m:ex/(0|<![0]>.+)+<!{$0>set ~<<$0}>/.max(+*[0])} Try it online! Outputs a regex match with a list of submatches as the integers. Explanation: { } # Anonymous code block m:ex/ / # Match all ( )+ # ...


2

05AB1E, 10 bytes .œʒÙïJQ}éθ 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

Perl 6, 35 bytes {$^a <<,<<flat $^b xx($a lcm$b)/$b} Try it online!


2

C (clang), 70 68 bytes i;f(*a,*b,x,y){for(i=0;printf("(%d,%d)",a[i%x],b[i%y]),++i%x+i%y;);} Try it online! Takes input as pointer to a and b and the lengths, prints q to std out. We use the modulo of an iterator by the data lengths e.g. i % x and i % y to access data, when both modules are equal to 0 , i is LCM and the function terminates.


1

JavaScript (ES6), 100 bytes Takes input as a string. f=([v,...a],p=o=[],c='')=>(v&&f(a,p,c+v),c?p.includes(c)|[+c]!=c||f(a,[...p,c],v):p[o.length]?o=p:o) Try it online! Commented f = ( // f is a recursive function taking: [v, // v = next digit ...a], // a[] = array of remaining ...


1

Ruby, 115 112 114 bytes Takes input as a string. A recursive function that takes a string and a list of previously-used numbers; it gets all substrings that start with the first character, and for each gets the result of the recursive call on the rest of the string. It then decides what the longest string that still matches is. f=->s,*e{(1..l=s.size)....


1

TI-BASIC, 3 bytes Ans-0 Very simple and works the same way as the top J answer. Input is an integer in Ans. Examples: 4:Ans-0 4 4:0-Ans -4


1

W j, 7 / 2 = 3.5 points I updated the ord to support W's own code page. 0“„√*"C Explanation 0“„√*" % Define a string C % Convert to codepoints [48,15,16,23,42] Flag:j % Join the output list without a separator ```


1

Burlesque, 39 bytes riXX:nz{J2dv{{9r@}{ro}}che!<-}m[tp)im++ Try it online! ri #Read as int XX #Return list of digits :nz #Filter for non-zero { J2dv #Divisible by 2? { {9r@} #Range a, 9 {ro} #Range 1, a }che! #Run based on if divisible <- #Reverse the range }m[ #Apply to each digit tp #Transpose digits )im #...


1

05AB1E, 16 bytes 0KεDÈi9ŸëL]íõζJO Try it online or verify all test cases. Or alternatively: 0KεDÈ8*>Ÿ{R}õζJO 0Kε9Ÿ¬L‚yèR}õζJO Explanation: 0K # Remove all 0s from the (implicit) input-integer ε # Map each digit to: D # Duplicate the digit Èi # If it's even: 9Ÿ # Pop and push a list in the range [digit, 9] ...


1

C (gcc), 19 bytes #define f(n)n*-~n/2 Try it online! C (gcc), 15 bytes f(n){n*=-~n/2;} -5 bytes thanks to ceilingcat! Try it online!


1

Clojure - 19 bytes #(apply +(range %)) Boring answer is boring...


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