New answers tagged

0

JavaScript (Node.js), 50 bytes (x,i=1,g=v=>v.toString(2))=>g(i)/x%1?f(x,++i):g(i) Try it online!


0

Haskell, 138 Bytes f x=let g z x=case x of{[]->z;a:b->if a==z!!0then g(tail z)b else g(case a of{'('->')';'['->']';'{'->'}';'<'->'>';_->' '}:z)b}in" "==g" "x de-golfed: f x= --define a function f let g z x=case x of{ ...


1

T-SQL, 680 bytes CREATE TABLE g(c INT,s geometry) INSERT g SELECT c,geometry::Point(x,y,0).STBuffer(.4) FROM(VALUES(1,7,8),(1,13,9),(1,14,9),(1,15,9),(2,2,14),(2,3,13),(2,4,12) ,(2,8,8),(2,9,9),(2,10,10),(2,11,11),(2,8,1),(2,12,4),(2,13,3),(2,14,2) ,(3,1,7),(3,2,7),(3,3,7),(3,4,7),(3,5,7),(3,6,7),(3,7,7) ,(35,8,12),(35,8,13),(35,8,14),(35,8,15))a(c,x,y) ...


1

Haskell, 38 bytes f x=filter(all(<'2').show)[x,x+x..]!!0 Try it online! Explanation We make all the multiples of x with [x,x+x..], filter them to contain only digits smaller than two filter(all(<'2').show) and then take the first one !!0


1

Japt -æ, 17 16 bytes Still very not happy with this! Takes input as a string. ²+PiU³)áNÎìl)d¥N Try it


0

C (gcc), 135 bytes s,c,i,m;f(n){for(c=s=i=m=1;m;c=(s=++i*i)*i){int a[10]={};for(;c;s/=10)a[c%10]++,!s?:a[s%10]++,c/=10;for(m=n;m*a[m%10]--;m/=10);}n=--i;} Try it online! Ungolfed and with better variable names: int square, cube, result, input_copy; int f(int input) { for(cube = square = result = input_copy = 1; input_copy; cube = (...


1

Oracle SQL, 126 bytes This isn't a golfing language and it doesn't have a bitwise XOR operator but: SELECT SUM(x+y-2*BITAND(x,y))FROM(SELECT LEVEL-1 x FROM T CONNECT BY LEVEL<x+2),(SELECT LEVEL-1 y FROM T CONNECT BY LEVEL<y+2) Assumes that there is a table T with columns X and Y containing one row that has the input values. So for the inputs: ...


0

Charcoal, 27 bytes ≔⁰ηWΦχ›№θIκ№⁺IXη³×ηηIκ≦⊕ηIη Try it online! Link is to verbose version of code. Explanation: ≔⁰η Start at zero. WΦχ Repeat until none of the 10 digits satisfies... ›№θIκ№⁺IXη³×ηηIκ ... the count of that digit in the input is greater than the count in the cube and the square... ≦⊕η ... increment the result. Iη Output the result.


0

Perl 5 -pF, 70 bytes $p=join'.*',sort@F;1while(join'',sort((++$\**2 .$\**3)=~/./g))!~/$p/}{ Try it online!


1

Perl 5 -pa, 36 bytes map{//;map$\+=$_^$',0..$F[0]}0..<>}{ Try it online! Takes in inputs on separate lines.


1

Ruby, 87 85 82 bytes ->s{d=n='';i=0;loop{k=s[i+=1].ord-s[i-2].ord;n+="++-"[k<=>0];d<<k.abs}rescue[d,n]} Try it online!


1

Wolfram Language (Mathematica), 89 bytes 1//.t_/;ContainsNone[Subsets[Join@@IntegerDigits[t^{2,3}],Length@#],Permutations@#]:>t+1& Try it online!


0

puts "Hello world!" Works in Ruby and Tcl


2

Jelly, 14 bytes 1*2,3DFœ&Ƒ@ʋ1# Try it online! A monadic link taking a list of digits and returning an integer in a single element list. 1 ʋ1# | Start with 1 and find the first integer where the following is true, using the input digit list as the right argument: *2,3 | - To the power of 2 and 3 D | - Convert to lists ...


0

Burlesque, 28 bytes r0{{2 3}?^im}]mj{j\\z?}j+]fi Try it online! r0 # Range from [0,inf] { {2 3}?^ # {squared, cubed} im # Concatenate }]m # Map over each and parse to string j # Swap stack { j # Swap \\ # List difference z? # Is null } j+] # Prepend input to make {input j \\ z?} fi # Find index s.t.


0

Ruby, 67 bytes Uses Arnauld's regex. Takes a list of digits. If that isn't allowed, add 6 bytes to change d.sort to d.chars.sort. ->d,i=0{i+=1until"#{i*i}#{i**3}".chars.sort*''=~/#{d.sort*'.*'}/;i} Try it online!


0

05AB1E, 39 bytes 31 9и20₂S;ǝDí«•1/K†Þ'āD•2×2ôøJº2äøŽP¶δª 05AB1E doesn't even have any date buitlins, so hard-coded it is. ;) Uses and outputs in format ddmmyyyy. Outputs as a list of triplets. Try it online (the » in the footer is to pretty-print them, but feel free to remove it to see the actual output). Explanation: 31 # Push 31 9и ...


1

05AB1E, 29 bytes •M;(Ч0—øθε;û…•…/\ Åв8ôJ6×3и» Try it online!


1

Clojure, 72 bytes (defn s[x y](apply +(for[a(range(inc x))b(range(inc y))](bit-xor a b)))) Ungolfed: (defn sumxy[x y] (apply + (for [a (range (inc x)) b (range (inc y)) ] (bit-xor a b)))) Tests: (println (s 5 46) " <-> " 6501) (println (s 0 12) " <-> " 78) (println (s 25 46) " <-> " 30671) (...


1

Uses format ddmmyyyy for the palindrome checks like the challenge description. Java 8 (hard-coded), 190 bytes v->"31100113 13100131x20011002 02011020x31011013 13011031x20022002 02022020x31122113 13122131x31033013 13033031x31055013 13055031x31077013 13077031x31088013 13088031x".replace("x"," 6556\n") As expected, a lot shorter than calculating it.. ...


0

[HARCODED] PHP, 194 bytes <?=str_replace("x"," 6556 ","31100113 13100131x20011002 02011020x31011013 13011031x20022002 02022020x31122113 13122131x31033013 13033031x31055013 13055031x31077013 13077031x31088013 13088031x"); Try it online! [WITH CAUTION]: shorter version that assumes following Kevin Cruijssen's results (I haven't verified them) that the ...


1

Burlesque, 39 bytes )**iRrtm{{0 2}sip^.-}~]Jm{0>=}j{abL[}\m Try it online! )** # Map ord() on string iR # Generate all rotations rt # Rotate once to put deriv[0] to first pos m{ # Map {0 2}si # Take the 0th and 2nd chars (either side) p^ # Push (un-array) .- # Difference } ~] # Discard last (i.e. deriv[-...


1

JavaScript (ES7), 77 bytes Takes input as a string. f=(n,k)=>([...[k*k]+k**3].sort()+'').match([...n].sort().join`.*`)?k:f(n,-~k) Try it online! Or 72 bytes if we can take input as an array of integers. Commented f = ( // f is a recursive function taking: n, // n = input k // k = ...


2

JavaScript (ES6),  115 109  108 bytes Date format: dd-mm-yyyy. _=>[-1102,-1101,-2,0,2,4,5,7,9].map(y=>([,a,b,c,d]=y+11303+'',[a+b+(m='-'+c+d+'-'+d+c)+b+a,b+a+m+a+b,6556])) Try it online!


5

05AB1E, 14 12 13 bytes -2 bytes thanks to @KevinCruijssen +1 byte thanks to @Grimmy ∞.Δ23SmJœIÅ?Z Try it online! Explanation ∞.Δ - First number that... 23Sm - Power of 2 and 3 [n^2, n^3] J - Concatenated œ - Permutations of this number IÅ?Z - any of these start ...


2

Python 2, 82 \$\cdots\$78 77 bytes Added 2 bytes to fix an error kindly pointed out by S.S. Anne. Switched to Python 2 thanks to Grimmy. Saved a byte thanks to Arnauld!!! f=lambda s,i=1:i*all((`i*i`+`i**3`).count(c)/s.count(c)for c in s)or f(s,i+1) Try it online!


2

Python 3, 78 bytes f=lambda s,n=1:n*all(f'{n*n}{n**3}'.count(i)>=s.count(i)for i in s)or f(s,n+1) Try it online!


3

Red, 305 bytes p: func[s n][at to""10 ** n + s 2]s: func[d][rejoin[p d/4 2 p d/3 2 p d/2 4]] r: func[s][s: to""s s = reverse copy s]a: to-date[1 1 1]b: collect[until[if r s a[keep a]a: a + 1 a/2 = 1e4]]repeat i l: length? b[repeat j l[if all[i < j(sort s b/:i)= sort s b/:j r t: b/:j - b/:i][print[s b/:i s b/:j"::"t]]]] Try it online! In dd-mm-yyyy ...


6

Polyglot, 0 bytes When using the format yyyy-mm-dd, the list of palindrome dates are: [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-06-20, 0270-07-20, 0280-08-...


1

Charcoal, 28 bytes ≔E⊖Lθ⁻℅§θ⊕ι℅§θ⊖ιθ⟦⭆θ‹ι⁰⭆θ℅↔ι Try it online! Link is to verbose version of code. Outputs the signs first (0=+,1=-) as otherwise the default print format will mangle the newlines. Explanation: ≔E⊖Lθ⁻℅§θ⊕ι℅§θ⊖ιθ Compute the pairs of ordinal differences, excluding the last pair (which in Charcoal would normally wrap around to 0). ⟦⭆θ‹ι⁰⭆θ℅...


1

PowerShell, 89 bytes 0..23|%{$y=$_ -join(48..94|%{('\/'[$y%8-lt4]+'\/ ')[(($_+$y)%8-lt4)+2*(($_-$y)%8-ge4)]})} Try it online!


1

PowerShell, 64 bytes 0..19|%{$y=$_ -join(0..20+19..10+11..19+20..0|%{'|~'[$_-eq$y]})} Try it online! The four-part diagram with a linear function y=x


1

Python 3, 119 \$\cdots\$ 92 91 bytes Saved 6 bytes thanks to Kevin Cruijssen!!! Added 6 bytes to handle empty string input. lambda s:zip(*[(chr(abs(S)),S<0)for S in(ord(s[i+1])-ord(s[i-1])for i in range(len(s)-1))]) Try it online! Outputs a sequence of: a tuple of characters and a tuple of True/False for negative/positive values.


1

05AB1E, 12 11 bytes Ǥš¥ü+Dd‚Äç -1 byte thanks to @ExpiredData. Uses I/O with UTF-8 encoding like the challenge description, and uses characters \0 for negative and \1 for 0 or positive. Outputs as a list of list of characters. Try it online or verify all test cases (the Join is added to pretty-print the character-lists to strings, but feel free to ...


1

05AB1E, 17 bytes Bytes used: δн3FILOPQm£¦ÅÐãêô Task 1 - every 3rd composite number: QÅmFÐOL¦ãPê3ôI£δн Try it online or verify all \$[1,50]\$ inputs. Task 2 - multiplication table: ÅFOQmê3ôãн¦£ILÐδP Try it online or verify all \$[1,20]\$ inputs. Task 3 - Fibonacci check: £3ôδнã¦LPmIÐÅFQêO Try it online or verify the first \$[0,1000]\$ inputs. Task ...


2

Ruby, 36 bytes ->x,y{(0..y+x*y+=1).sum{|r|r/y^r%y}} Try it online!


0

JavaScript (V8), 33 bytes f=i=>i.replace(/[a-z]+/g,'"$&"'); -9 Bytes thanks to manatwork Try it online!


2

J, 23 17 bytes -6 bytes thanks to Bubbler! 1#.1#.XOR/&(i.,]) Try it online! K (oK), 25 bytes {+/2/'~=/'(64#2)\''+!1+x} Try it online! Most probably can be golfed further.


1

Java 8, 58 bytes (x,y)->{int t=++x*-~y;for(y=0;--t>0;)y+=t%x^t/x;return y;} Port of @xibu's C answer, so make sure to upvote him! Try it online. Explanation: (x,y)->{ // Method with two integer parameters and integer return-type int t=++x // Increase `x` by 1 first with `++x` *-~y; // Create a temp integer `t`, with ...


3

05AB1E, 6 bytes Ý`δ^˜O Try it online or verify all test cases. Explanation: Ý # Push a list in the range [0,value] for each value in the (implicit) input-pair ` # Push both these lists separated to the stack δ # Apply double-vectorized: ^ # XOR them together ˜O # And then take the flattened sum # (after which the ...


2

Japt -x, 6 bytes ô ï^Vô Try it ô ï^Vô :Implicit input of integers U & V ô :Range [0,U] ï :Cartesian product with Vô :Range [0,V] ^ :Reduce each pair by XORing :Implicit output of sum of resulting array


2

Pure Bash, 170 bytes a=`echo {A..Z}`')!@#$%^&*("+,-./:[\]`' b=`echo {a..z}`0123456789"'=<_>?;{|}~" c=$a$b d=$b$a for((;n<164;n++));do [ "$1" = "${c:n:1}" ]&&echo ${d:n:1}&&exit;done echo "$1" Try it online! I decided to implement a solution inspired by @Noodle9's very nice answer, but using pure bash without any utilities (...


1

MUMPS, 57 bytes f i=1:1:48 w $tr(i\16,0),$e("0123456789abcdef",i#16+1),! Output >d ^xmsdgolf 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 .. 28 29 2a 2b 2c 2d 2e 2f 30 Explanation f i=1:1:48 ; loop from 1 to 48 w $tr(i\16,0) ; print i div 16, and ditch any zeros $e("0123456789abcdef",i#16+1) ; extract the nth character ...


2

W f j, 4 bytes Hmm, let's do a pure-ASCII port of that. C[gr Explanation C % Convert the string to its codepoints [ % Index into the other list r % For every indexed item: g % "g"et a random item in this list Flag:f % Flatten the output list Flag:j % Join the flattened output list ```


3

Wolfram Language (Mathematica), 28 bytes Array[BitXor,{##}+1,0,Plus]& Try it online!


1

Zsh, 31 bytes eval '<<<$[' +{0..$1}^{0..$2} ] Try it online! Uses eval to expand the <<<$[ ] after expanding the lists. The TIO link adds set -x so you can see what the brace expansion looks like.


2

Python, 75 bytes lambda n,l,m=1:all(f(n,l[1:],m<<d*l[0]|1)for d in[1,n-1])if l else m%~-2**n Try it online! Outputs True/False swapped. The idea to store visited values as a bitmask is from Arnauld. But, instead of storing our current position on the tape of bits and updating it after we move, we simply move the whole tape so that we're located at ...


1

Japt -x, 8 bytes ò@Vò^XÃc Try it


0

Python 2, 42 bytes f=lambda k,n=0:max(`n`)!='1'and k+f(k,n+k) Try it online! A recursive function. We terminate when the maximum character of the string representation is 1. We can't quite use '<2' instead because zero would trigger it, and we don't have a good way not to start at zero. The larger outputs run out of recursion depth, at least with the ...


2

C (gcc), 48 bytes R;f(x,y){R=++x*++y;for(y=0;--R;y+=R%x^R/x);x=y;} Try it online!


Top 50 recent answers are included