New answers tagged

0

Java, 318 bytes interface Q{static void main(String[]a){char q=34;String s="interface Q{static void main(String[]a){char q=34;String s=%c%s%c;System.out.print(new java.util.Scanner(System.in).nextLine().equals(String.format(s,q,s,q)));}}";System.out.print(new java.util.Scanner(System.in).nextLine().equals(String.format(s,q,s,q)));}} Try it online!


0

JavaScript, 45 bytes n=>(''+new Date(n[0]+'-'+n[1]+'-01'))[0]=='M' Takes input as an array like [2020, 6]. How it works Converts the date object to a string then checks if the first character is an M.


0

R, 62 bytes function(x,y,`[`=chartr)x[z<-Reduce(paste0,LETTERS),x]==y[z,y] Try it online! Translates (chartr) the characters or each string in order of occurrence into ABC...XYZ. After this, isomorphic strings are identical. To save bytes (at the expense of readability), we redefine the R index operator [ as an alias of the chartr function, and we ...


2

Husk, 5 4 bytes Ë´Ṫ= Try it online! -1 byte from Leo using ბიმო's answer. Explanation Ë´Ṫ= Ë check if all the elements are equal by the following predicate: ´Ṫ cartesian product with self = by equality


3

Jelly, 4 bytes ĠṢ)E Try it online! Another 4 byte version How they work ĠṢ)E - Main link. Takes [A, B] on the left ) - Over each string S in the input: Ġ - Group the indices of S by it's values Ṣ - Sort the lists of indices E - Are both equal? ẹⱮ)E - Main link. Takes [A, B] on the left ) - Over each string S in the input: Ɱ - For ...


2

Jelly, 8 bytes JịƬ"ZẈiL Try it online! Outputs 0 for False and a non-negative integer for True Jelly finally ties J! How it works JịƬ"ZẈiL - Main link. Takes the Cayley matrix n×n M on the left Z - Transpose M J - Yield [1, 2, ..., n] Ƭ - Until reaching a fixed point, do the following and replace i with the result " ...


0

05AB1E, 9 bytes εð¢}ƵĆ7вQ Try it online! εð¢}ƵĆ7вQ # full program Q # is... ¢ # the list of the number of.. ð # spaces... ¢ # in... # (implicit) current element in... ε # for each element in... # implicit input... Q # equal to... в # the list of the base... 7 # ...


3

Labyrinth, 13 bytes ,:, " -@ ""}! Try it online! That's a whole lot of no-ops, but I can't find any easy way to remove them. Prints -1 if the input is a double speak, nothing otherwise. Allowed by this I/O method. How it works ,:, Push char input (,), duplicate (:), push another char input - Subtract the top two. It can be ...


0

Factor, 44 bytes [ [ = ] [ - abs 5 = ] [ + 5 = ] 2tri or or ] Try it online! The repetition of = is annoying, but I couldn't find another way.


3

Zsh, 37 bytes >$#1$1 : (12|[34679]2|[258]1[^1345])* Try it online! Outputs via status code (0 = is in sequence, 1 = is not in sequence). Explanation: > - create the file $#1 - the length of the input $1 - followed by the input itself (12|[34679]2|[258]1[^1345])* - try to find a file matching this pattern: (||) - one of: 12 (the literal input 2 ...


0

ARM Thumb-2 machine code, 4 bytes 07c0 4770 .syntax unified .arch armv6t2 .thumb .globl is_odd .thumb_func // Standard C calling convention // Input: uint32_t r0 // Output: r0 == 0 if even, else odd is_odd: // Shift out everything but the lowest // bit, leaving odd numbers as ...


1

C (gcc), 51 bytes f(a,b)int*a,*b;{return wcschr(a,*b)&&f(a,b+1)|!*b;} Try it online! In this 51 bytes version I tweaked a little bit the 53 bytes version (see below, former answer) thanks to && : At each letter *b I check we can find it in string a. If not, it means wcschr(a,*b) equal 0, so the program will not bother to execute the second ...


2

x86-16 machine code, 14 bytes 00000000: 85c9 ac57 518b caf2 ae59 5fe1 f5c3 ...WQ....Y_... Listing: 85 C9 TEST CX, CX ; check for empty string S_LOOP: AC LODSB ; next char in string 2 57 PUSH DI ; save first string pointer 51 PUSH CX ; save first string length 8B ...


2

K (ngn/k), 5 bytes ~^&/? Try it online! A tacit function taking two arguments. ? find the indices of the first matches of the right-hand argument in the left-hand argument; returns 0N (null) if it's not present &/ take the minimum ~^ is the minimum not null?


1

Wolfram Language (Mathematica), 7 bytes SubsetQ Try it online! SubsetQ does not account for multiplicity.


2

Whispers v1, 50 43 bytes > Input > Input >> {2} >> 3⊆1 >> Output 4 Try it online! Squeezed pseudo code: >> Output ( Set(Input2) ⊆ Input 1) Explanation: As always in Whispers, we execute the last line first: >> Output 4 Outputs the result of line 4: >> 3⊆1 Returns a Boolean representing the result of line 3 being ...


0

Kotlin, 19 bytes fun a(n:Int)=n%2==0 This was surprisingly simple. And the code is pretty self explanatory.


4

Ruby, 104 96 bytes It almost looks like a complete English sentence. Which probably is a bad thing for golfing. ->n{n.digits.permutation.any?{|s|a,b=s.each_slice(s.size/2).map{|x|x.join.to_i};a%10>0&&a*b==n}} Try it online! It can be written in 94 bytes with Ruby 2.7: ->n{n.digits.permutation.any?{|s|a,b=s.each_slice(s.size/2).map{_1.join....


7

R, 156 146 143 135 bytes -10 bytes thanks to Dominic van Essen function(n,s=strsplit){for(i in 1:n)if(!n%%i&nchar(j<-n/i)==nchar(i)&all(el(s(paste0(j,i),''))%in%el(s(c(n,''),'')))&i%%10)return(T) F} Try it online!


5

JavaScript (Node.js), 88 bytes f=(n,i=1)=>n<i*i*10&&i%10&&[...''+i+n/i].sort()+''==[...''+n].sort()||n*10>++i*i&&f(n,i) Try it online! [...''+i+n/i].sort()+''==[...''+n].sort() two factors use and only use digits in original number if n/i is not an integer, it converted into a string with . and not equals to another side ...


5

05AB1E, 14 bytes œ2δäÅΔPQy€θĀà* Outputs a non-negative integer as truthy and -1 as falsey. Try it online or verify all test cases. Explanation: œ # Get all permutations of the (implicit) input δ # Map over each permutation: 2 ä # And split it into two equal-sized halves ÅΔ # Get the 0-based index of the first ...


5

C (gcc), 286 240 227 bloody bytes (o,_,o) -46 bloody bytes thanks to ceilingcat! #define S(x,y)x^=y^=x^=y o,a,b,c,r;f(int*_){r=0;c=atoi(_);v(o,_,o=strlen(_));r=r;}v(k,_,o,i)char*_;{k-1?({v(k-1,_,o);for(i=0;++i<k;v(k-1,_,o))S(_[k%2?0:i-1],_[k-1]);}):(a=atoi(_)/exp10(o/2))*(b=atoi(_+o/2))==c&&(a+b)%10?r=1:0;} Try it online! The input is a string ...


4

Charcoal, 54 bytes ⊞υ⟦ωθ⟧FυFE§ι¹⟦⁺§ι⁰κΦ§ι¹⁻λν⟧⊞υκ⊙EΦυ¬⊟ιI⪪⊟ι⊘Lθ∧Σ﹪ιχ⁼θIΠι Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for vampire, nothing if not. Explanation: ⊞υ⟦ωθ⟧ Start a breadth-first enumeration of permutations of the input string. Fυ Loop over each partial permutation so far. FE§ι¹⟦⁺§ι⁰κΦ§ι¹⁻λν⟧⊞υκ Append ...


1

Charcoal, 56 bytes ≔⍘×⊕X²¦³²N²θ¿‹Lθ⁴¹movs¿‹Lθ⁴⁹movw¿№θ×0²⁴mov¿№θ×1²⁴mvn¦ldr Try it online! Link is to verbose version of code. Explanation: ≔⍘×⊕X²¦³²N²θ Input the integer, multiply it by 2³²+1, and convert to binary. ¿‹Lθ⁴¹movs If the length is less than 41, then the original number had 8 bits or fewer, so a movs instruction will work. ¿‹Lθ⁴⁹movw ...


2

Jelly, 15 bytes Œ!ŒH€SṪ$ƇḌP€=ḌẸ Try it online! Takes a list of digits.


8

Husk, 18 17 14 13 12 bytes Edit: -3 bytes, and then another -1 byte, thanks to Leo, and -1 byte thanks to inspiration from pajonk's R answer (3rd edit) €¹mΠ†dm½f→Pd Try it online! Outputs nonzero integer if it's a vampire number, zero otherwise. Commented penultimate version: €¹ # index of input if present, zero otherwise, in mΠ ...


4

Python 2, 105 95 94 bytes -10 bytes thanks to Kevin Cruijssen! (switch to Python 2) -1 byte thanks to dingledooper! Very inefficient, segfaults for \$ n \gtrsim 18500\$ on TIO. f=lambda n,k=2,S=sorted:k<n and(k%10>n%k<(len(`k`)==len(`n/k`)<S(`k`+`n/k`)==S(`n`)))|f(n,k+1) Try it online! Commented: f=lambda n,k=2,S=sorted # recursive function ...


5

J, 43 bytes ".e.-@-:@#((0<[:".{:\)*[:*/".\)"1 i.@!@#A.] Try it online! Takes digits as a string. For each permutation i.@!@#A.], use half the digit length -@-:@# to take non-overlapping infixes -- which slices into 2 halves -- and multiply those halves([:*/".\)"1. Then (to handle the trailing zero constraint) multiply that ...


3

JavaScript (ES6), 93 bytes Assumes that the input has an even number of digits. Returns a Boolean value. f=(n,[...a]=n,p='')=>a[p.length]?a.some((v,i)=>f(n,a.filter(_=>i--),p+v)):p%10&&p*a.join``==n Try it online! JavaScript (ES6), 97 bytes Expects the integer as a string. Returns 0 or 1. f=(n,[...a]=n,p,q,k)=>a.some((v,i)=>f(n,a....


3

Python 2, 113 ... 112 109 bytes def f(n,s=sorted):x=s(`n`);l=10**(len(x)/2);return any(x==s(`i`+`n/i`)for i in range(l/10,l)if i%10and n%i<1) Try it online! -3 byte thanks Kevin Cruijssen


2

C (gcc), 105 \$\cdots\$73 72 bytes Saved 15 bytes thanks to EasyasPi!!! Saved 3 4 bytes thanks to ceilingcat!!! i;z;f(n){for(i=0;z=n>>8,i++<32&&z&&~z;)n=n*2|n<0;i=z?~z?z>>8?4:3:2:i>1;} Try it online! Returns \$0,1,2,3,4\$ for movs, mov, mvn, movw, ldr. Explanation (before some golfs) i;f(n){ // ...


3

Jelly, 29 bytes +Ø%BḊ¹¬ƭṙJ$Ḅ<⁹Ẹ ⁹²>;Ç;Ç;<⁹$TṀ Try it online! Returns 0, 1, 2, 3, 4 respectively for ldr, movw, mov, mvn and movs. Probably could be improved.


7

JavaScript (ES6), 57 bytes Returns false for "mov", true for "movs", 2 for "ldr", 3 for "mvn" or 4 for "movw". f=(n,r)=>n>>8?~n>>8?r>31?n>>16?2:4:f(n>>>31|n*2,-~r):3:!r Try it online! Commented f = ( // f is a recursive function taking: n, ...


3

Whispers v3, 31 bytes 1 tuptuO >> > 1 >> Output 1 0 > Try it online!, !enilnO tI yrT Hooray for strict parsing rules! The first and last lines are ignored, because they don't fit the right syntax. They come into action when reversed.


1

Raku, 62 bytes ->\a,\b {a~~/<{join ".*",map {" "eq$_??"."!!"'$_'"},b.comb}>/} Try it online!


0

JavaScript: 69 bytes. a=>{b=a.split(/\+|\-|\*|\//);return typeof eval(b[0])==typeof eval(b[1])} Remarks eval is a dangerous operation. I used bad JavaScript practices in the process, like implicit globals and auto-semicolons. Explanation b = ... sets the variable b to the array created by splitting a based on the dyadic operations return ... returns ...


2

Charcoal, 69 bytes FLθFL§θ⁰F⌊⟦ικ⟧F⁻ιλF⁻κλF²F²⁼θEθEρ¬∨∨∨‹ςμ›ςι∨‹τν›τκ‹λ⌊⟦⎇π⁻ςμ⁻ις⎇ξ⁻τν⁻κτ Try it online! Link is to verbose version of code. Works by enumerating all possible L shapes on the original grid looking for a match. So many nested loops, I've actually used the t variable for the first time ever. This is an important milestone, since there are no ...


2

Perl 5 (cperl), 338 bytes sub L{($w,$h,$v,$m)=@_;join$/,map{$x=$_;join'',map$_<=$w|($m?$x>$h-$w:$x<=$w)|0,1..$v}1..$h} sub r{my($i,@r);map/\n/?($i=0):$r[$i++]=~s/^/$_/,pop()=~/./gs;join$/,@r} sub d{my$_=pop;/.*/;length$&,0+split$/} sub f{$s=pop;map$s=r($s)=~s,^(0+\n)+,,r,1..4;@m=map{$m=$_;map$m=r($m),1..4}map{L(@L=($_,d($s))),L(@L,1)}1..min(d($...


3

APL (Dyalog Unicode), 44 bytes thanks @Adám for the ⍸⍣¯1 trick (⊂a)∊(⍉¨⊢,⌽¨)⍣2≥∘i¨⍳⌈/,i←⌊/↑⍳⍴a←⍸⍣¯1(⊢-⌊/)⍸⎕ Try it online! ⍸⍣¯1(⊢-⌊/)⍸ trim surrounding 0s ≥∘i¨⍳⌈/,i←⌊/↑⍳⍴a generate L-shapes (⍉¨⊢,⌽¨)⍣2 add reflections (⊂a)∊ test if the (trimmed) input is among them


3

Wolfram Language (Mathematica), 107 105 101 100 bytes FreeQ[#|r/@#,#|r@#&@{z={y=0...}...,d:{a:y,o=1..,b:o,y}..,{a:y,b:o,y}..,z}/;+b==Length@!d]& r=Reverse Try it online! The pattern identifies a vertically reflected L shape. Reversing it checks for another vertical reflection (upright); #|r/@# checks for horizontal reflection. { ...


2

Python 3.9 + NumPy, 167 bytes lambda a:min(c:=(a:=a[[slice(min(i),max(i)+1)for i in a.nonzero()]]).sum(0))-min(r:=a.sum(1))|len(c)-max(r)|sum((a[:-1]^a[1:]).any(1))*sum((a[:,:-1]^a[:,1:]).any(0))-1 Expected input is a 2D numpy array of 0/1 (or False/True) values. Returns falsey for L shape, truthy for not L shape. Explanation: First remove the "margin&...


1

Scala, 249 185 180 bytes Seq.iterate(_,8)(_.transpose.map(_.reverse)dropWhile(!_.toSet(1)))drop 4 exists{m=>Set(m,m.transpose).flatMap(_.dropWhile(!_.toSet(0)).map(_.reverse.dropWhile(_<1)).toSet).size==1} Try it online! This is shamefully long. It takes a List[List[Int]] as input (even though the type is Seq[Seq[Int]] => Boolean). The result is a ...


4

Julia, 175 170 bytes a->try r=rotr90 for _=1:4 while sum(a[1,:])<1 a=a[2:end,:]end a=r(a)end for _=1:4 a=r(a,a[end])end a[a[1]] while sum(a)>0 a[a[a[:,1],:]] a=a[2:end,2:end]end a[1]catch end Try it online! returns 0 if L-shaped and nothing otherwise It's probably not the most efficient approch but I'm glad I could match the javascript answer ...


3

Retina, 112 bytes ^\s+¶|¶\s+$ /^( .*¶)+ .*$/+m`^ /^(.* ¶)+.* $/+m` $ /^#* /&G^` /(?m)^ /&V` /^##+(¶#.*)+/+`^#+¶#|(¶)# $1 ^\s+$ Try it online! Link includes test suite with header that extracts the #-based test cases from the input and automatically right-pads them. Explanation: ^\s+¶|¶\s+$ /^( .*¶)+ .*$/+m`^ /^(.* ¶)+.* $/+m` $ Remove any ...


6

JavaScript (ES6),  175  166 bytes Expects a list of binary strings. m=>m.map(M=r=>(M|=v='0b'+r|0,m&=v||~0,v),m=~0).map(v=>v?(b=v+(v&-v))&b-1?3:v^m?2^v<M:1:0).join``.match(`^0*(1+${s=(g=m=>m?2+g(m&m-1):'')(m)}|${s}1+)0*$`)&&M*2&M/2&m^m Try it online! How? Step 1 We first convert the input matrix \$m[\:]\$ into a ...


8

05AB1E, 31 30 17 bytes ø‚O0δÚDWδåsεÔg<}Q Try it online or verify all test cases. Explanation: ø # Zip/transpose the (implicit) input-matrix, swapping rows/columns ‚ # Pair it together with the (implicit) input-matrix O # Take the sum of each row of both matrices # Remove any leading/trailing rows/columns of ...


6

APL (Dyalog Extended), 48 bytes (SBCS) Anonymous tacit prefix function. Takes Boolean (0/1) matrix with 0s indicating the shape. Requires 0-based indexing. {(=/⍵-⍥⍴e)∧i≡,e←(⊂∘⊃+∘⍳∘|1+⊃∘⌽-⊃)i←⍸⍵}1⍉⍤⌂deb⍣2⊢ Try it online! 0…⊢⁠ with 0 as left argument and the unmodified argument as right argument:  …⍣2 repeat twice   …⍤⌂deb delete ending (leading and trailing)...


3

APL (Dyalog Unicode), 104 bytes {i←0⋄{(~×/1=,⍵)∧(⍴⍵)≡+/¨1⌷¨(⍉⍵)⍵}⌽∘⍉⍣{(~⊃⌽⊖⍺)∨i=4⊣i+←1}{×≢⍵:⍵⋄,0}p∧⌿⍵∧/⍨p←⌊/0~⍨+/⍵}{(¯1+⌊⌿c)↓⍵↑⍨⌈⌿c←↑⍸⍵} Try it online! A train of two dfns which takes a matrix of 0's and 1's as argument. Can be simplified a lot using Jonah's idea. It simplifies the matrix like so: ##### ##### → #### ## # rotates it to put the ...


7

J, 51 48 79 bytes (1-'10+1'rxin'012'{~2,@,.],|:)*1&#.(,~&{:-:,&(0{#/.~)+0{,)&(|.^:({.>{:)@-.&0)+/ Try it online! +31 thanks to Bubbler for catching a bug not revealed by the original cases NOTE: All test cases are passing again when I run locally on j902, but this now fails on TIO due to a J regex bug on linux/TIO. Consider the column ...


5

JavaScript (V8), 500 bytes Lots of golfing possible. M=>{R=M.map(m=>m.join``);if(R.find(r=>r.match(/10+1/)))return;o = [];for(i=n=0;i<R[L="length"];i++)if((r=R[i]).includes`1`){if(n)return;n=0;o.push([r.indexOf`1`,r.lastIndexOf`1`])}else{if(o[L])n=1;else continue}if(o.every(r=>r[0]==o[0][0])){}else if(o.every(r=>r[1]==o[0][1]))o=...


Top 50 recent answers are included