New answers tagged

1

Jelly, 6 bytes I%12ỊẸ Try it online! A monadic link taking the list of [middle, top, bottom] as its argument and returning 1 for snap and 0 for no snap.


1

T-SQL 2008, 40 bytes PRINT 1/-~abs((@-@2)%11/2*((@-@3)%11/2)) Try it online


1

Japt, 7 bytes d_aV <2 Try it


2

Charcoal, 12 bytes ›²⌊﹪↔⁻E²NN¹² Try it online! Port of @Grimy's answer. Takes input as three separate values bottom, middle, top, and outputs using Charcoal's default Boolean format of - for true, nothing for false. Explanation: ² Literal 2 › Is greater than ⌊ Minimum of ↔ Absolute value of (...


0

Forth (gforth), 58 bytes : f 0 over begin 10 /mod >r + r> ?dup 0= until 2* mod 0= ; Try it online! Code Explanation : f \ start a new word definition 0 over \ create an accumulator and copy the input above it on the stack begin \ start an indefinite loop 10 /mod \ divide by 10 and get quotient and remainder >r +...


0

Runic Enchantments, 11 bytes i:'+A2*%0=@ Try it online! Explanation i: Read input, duplicate it '+A Sum its digits 2* Multiply by 2 % Modulo input with digit sum 0= Compare to 0 @ Print and terminate


1

K (ngn/k), 15 bytes {(2*+/10\:x)!x} Try it online! 0 is truthy


1

C (gcc), 47 43 bytes f(b,m,t){return(1<<t-m|1<<t-b)&0x80101003;} Try it online!


1

Jelly, 6 bytes ạ%12ṠƑ Try it online!


1

Perl 5 -ap, 31 bytes $t=<>}{$\|=abs($t-$_)%12<2for@F Try it online! Input: bottom middle top Actually, the order of the middle and bottom doesn't matter. Output: 0 for false; 1 for true


1

Pyth, 12 11 bytes Takes input as [bottom, top, middle] or [middle, top, bottom] (both work). Outputs [] (Falsy in Pyth) if there's no valid snap, a non-empty array otherwise. f>2%.aT12.+ Try it online! If a consistent truthy/falsy value is required, add .A in front for +2 bytes. Then output will be True or False. Explanation f # Filter ...


4

Python 3, 38 bytes lambda x,y,z:{x-y,x-z}&{0,1,12,-1,-12} Try it online! Returns a non-empty set (truthy) if valid, empty set (falsey) if not. Takes input in order top-middle-bottom, but can be rearranged for same code size.


2

JavaScript (ES6), 29 bytes Takes input as ([bottom, middle])(top). The output is inverted. a=>c=>a.every(n=>(n-c)/2%6|0) Try it online! JavaScript (ES6),  37  30 bytes Saved 1 byte thanks to @Grimy Takes input as ([bottom, middle])(top). a=>c=>a.some(n=>(n-=c)*n%72<2) Try it online!


3

Perl 6, 16 bytes 3>(*-(*|*)+1)%13 Try it online! Anonymous whatever lambda that takes input as top, middle, bottom and returns a Junction that evaluates to True or False


3

05AB1E, 7 bytes α12%ß2‹ Try it online! Takes inputs as [middle, bottom], top. α # absolute difference 12% # mod 12 ß # minimum 2‹ # less than 2?


2

J, 12 bytes 1 e.2>12||@- Try it online! Taking bottom middle as left arg, top as right arg. original answer taking input as one list J, 24 bytes 1 e.2>#:@3 5(12||@-/)@#] Try it online! #:@3 5 The numbers 3 and 5 in binary are 0 1 1 and 1 0 1 which are the masks for the middle/top and bottom/top cards respectively (12||@-/)@# We filter the input ...


2

K (ngn/k), 29 23 bytes {~|/(&/s@&1<s)!s:#'=:x} Try it online! edit: removed some unnecessary colons (i know when a monadic is required but it's not always clear to me if there's ambiguity so i default to including the colon) and changed the mod x-y*x%y to ngn/k's y!x, which meant i could remove a variable assignment


2

Python 3, 89 68 bytes -21 bytes thanks to AdmBorkBork def a(b,c): for i in b: if i==c[:1]: c=c[1:] return len(c)==0 Takes input as a(string, acronym). Try it online!


1

Python 3, 85 bytes def f(s,w): for c in s: if c==w[0]: w.pop(0) if len(w)==0:return 1 return 0 Try it online!


1

Retina 0.8.2, 20 19 bytes +`(.)(.*¶)\1? $2 ¶$ Try it online! Takes the phrase and acronym on separate lines, but the link includes a header that formats the test suite appropriately. Explanation: +` Process all of the letters of the phrase. (.)(.*¶)\1? $2 For each letter of the phrase delete the next letter of the acronym if it is the same. ¶$ Check ...


1

Haskell, 40 bytes r@(a:c)#(b:d)|a==b=c#d|1>0=r#d x#y=x=="" Try it online!


0

AsciiDots, 16 bytes .-#?{&}$# .-#1/ Outputs 0 if even, and 1 if odd. Basically just a Boolean AND with 1. Try it online!


4

C (gcc), 47 bytes f(a,b)char*a,*b;{a=!*b||*a&&f(a+1,b+(*a==*b));} Try it online!


1

Pyth, 3 bytes }Ey Try it online!


3

J, 21 bytes <@[e.]<@#~2#:@i.@^#@] Try it online! Note: Some of the longer test cases omitted because they this solution is O(2^n). They would pass with infinite memory. Explanation: We create all 2 ^ (length of haystack) possible substrings, and check if the needle is an element of that list.


2

JavaScript, 26 bytes Port of Kevin's Java solution so please +1 him, too. Takes the string as a string via parameter s and the acronym as a character array via parameter a. Outputs false for true and true for false. s=>a=>!s.match(a.join`.*`) Try it online! (Footer reverses output for easier verification)


1

Emacs Lisp, 52 bytes (lambda(a b)(string-match(mapconcat'string b".*")a))


1

SNOBOL4 (CSNOBOL4), 88 bytes T =INPUT S T LEN(1) . X REM . T :F(M) M =M ARB X :(S) M INPUT M :F(END) OUTPUT =1 END Try it online! Prints 1 for Acronymizable, and does nothing for not. T =INPUT ;* read in the Target S T LEN(1) . X REM . T :F(M) ;* extract the first letter of T ;* and ...


2

Gaia, 5 bytes $z@$Ė Try it online! Powerset approach.


1

MathGolf, 7 bytes -±_B,╓≥ Try it online! Other valid 7-byters include: -±7rñ§≥ -7rñ╡§≥ I found a 4-byter which solves every test case, but doesn't solve the problem in general: -±Σ≥ Try it online! The approach of the 7-byters are basically ports of existing 7-byte solutions. The 4-byter relies on the fact that the digit sum of the absolute difference ...


1

JavaScript, 50 bytes h=>n=>[...n].reduce((a,l)=>a+1?h.indexOf(l,a):a,0) Try it online! take input as f(haystack)(needle) h=>n=> // inputs [...n] // transform n from string to array of char .reduce((a,l)=> ,0) // for ...


6

Brachylog, 1 byte ⊇ Try it online!


1

Zsh, 35 bytes [[ $1 = *${~${(j:*:)${(s::)2}}}* ]] Outputs via exit code. Try it online! [[ $1 = *${~${(j:*:)${(s::)2}}}* ]] ${ 2} # second parameter ${(s::) } # split into characters ${(j:*:) } # join with * ${~ } # enable globbing *${...


1

Jelly, 4 bytes eŒP} Try it online!


1

Stax, 4 bytes äΦv> Run and debug it


3

APL (Dyalog Unicode), 17 bytes Full program. Prompts for phrase, then acronym. 0∊⊃(⍳⍨↓⊢)/⍞,⊂⌽0,⍞ Try it online! ⍞ prompt for phrase   "HELLO WORLD"   "HELLO WORLD" 0, prepend a zero   [0,'H','E','L','L','O',' ','W','O','R','L','D']   [0,'H','E','L','L','O',' ','W','O','R','L','D'] ⌽ reverse   ['D','L','R','O','W',' ','O','L','L','E','H',0]   ['D','L','...


4

Java 8, 46 39 38 bytes a->b->a.matches(b.replaceAll("",".*")) -7 bytes thanks to @tsh. -1 byte thanks to @NahuelFouilleul. Try it online. Explanation: a->b-> // Method with two String parameters and boolean return-type a.matches( // Check if the first input matches the regex: b // The second input, .replaceAll(...


1

C#, 152 bytes public class P{public static void Main(string[]a){int q=0;int e=a[1].Length;foreach(char c in a[0])if(q!=e&&c==a[1][q])q++;System.Console.Write(q==e);}} Try Online


1

Python 3, 63 bytes f=lambda s,t:(t[:1]in{*s}and f(s[s.find(t[0]):],t[1:]))**len(t) Try it online! Recursive function. Will check for each letter in the acronym t, whether it is found in the string s. If it is, the function is called recursively with the part of the string after the current test character t[0] as the new input string s. When the test ...


3

Python 2, 48 bytes lambda s,a:re.search('.*'.join(a),s)>0 import re Try it online!


1

Japt, 4 bytes à øV Try it here


3

05AB1E, 3 bytes æIå Try it online! æ # power set of the first input I # second input å # does a contain b? # implicit output


1

C#, 158 bytes using System;public class P{public static void Main(string[]a){int w=Math.Abs(int.Parse(a[0])-int.Parse(a[1]));Console.Write((w>6?12-w:w)<=int.Parse(a[2]));}} Try Online


4

Keg, 19 17 characters ?{!1<|=[|0.(_)]}1 Explanation: ? # read input { # while !1< # stack length greater than 1? | # end of while condition and beginning of while block = # compare the 2 top values in the stack [ # if (the condition is the top of stack) | # end of ...


1

C#, 190 bytes public class P{public static void Main(string[]a){bool d=true;if(a[0].Length%(double)2>0)d=false;else for(int i=0;i<a[0].Length;i+=2){d=a[0][i]==a[0][i+1]?d:false;}System.Console.Write(d);}} Try Online


0

C# .NET 135 bytes public class P{public static void Main(string[]a){System.Console.Write(a[0]!=""&&a[0].Split('a').Length-1==a[0].Split('b').Length-1);}} Try online


0

brainfuck and bfasm, 995 and 119 bytes Quite easy to outgolf. Generated using following assembly code: mov r4,.a lbl 1 in_ r1 jz_ r1,3 eq_ r1,r4 jnz r1,2 inc r3 dec r2 lbl 2 inc r2 jmp 1 lbl 3 eq_ r2,r3 out r2 And then optimized by hand. +>+[<[>>+>+<<<-]>>[<<+>>-]>[[-]>>>>--[----->+<]>----...


1

Swift, 109 bytes func a(b:String){let c=Array(b),l=c.count;var d=0,i=0;while i<l-1{if c[i]==c[i+1]{d+=1};i+=2;};print(d*2==l)} Try it online!


2

JavaScript, 37 bytes r=>b=>g=a=>a-12<b-r?g(a+12):a-12<=b+r Try it online!


1

C# (Visual C# Interactive Compiler), 78 bytes 80 bytes 72 bytes (a,b,r)=>Enumerable.Range(b-r,2*r+1).Select(x=>(x+12)%12).Contains(a%12) Try it online! Edit: Range was incorrect, I forgot to count the item itself, adding 2 bytes. But I bit the bullet dealing with C#'s modulus actually being remainder, saving 8 bytes. Technically, this code actually ...


Top 50 recent answers are included