New answers tagged

0

Haskell, 36 bytes (a:b)%(c:d)=([a|a/=c]++b)%d s%t=s<=t Try it online! 37 bytes (.map concat.mapM(\c->["",[c]])).elem Try it online! I think mapM postdates this challenge. If we can assume the characters are printable, we can do 36 bytes (.map(filter(>' ')).mapM(:" ")).elem Try it online! 37 bytes (null.).foldr(?) c?(h:t)|c==h=t c?s=s ...


0

Python 2, Python 3 - 78 bytes lambda a,b:' '.join(('How much',a,'would a',a+b,b,'if a',a+b,'could',b,a))+'?' Try it online! no format strings, a tad shorter than @Tryer 's format


0

Perl 6, 34 bytes {$^a;&{?/<{~('.*'X$,|$a.comb)}>/}} Try it online! Anonymous code block that takes input curried, like f(X)(Y). This does the familiar join by .* and evaluate as a regex as other answers, but takes a few extra shortcuts.


1

Piet, 20 codels If you are using npiet, you might want to use the -q option to stop the interpreter from printing a prompt for each character. Rundown If STDIN contains no character, Piet's input functions will not lock or throw an error, but simply fail quietly. To know if we reached the end of the string, we therefore push a sentinel 0 to the stack to ...


0

Red, 82 bytes func[x y][parse/case y collect[foreach c x[keep reduce['to c 'skip]]keep[to end]]] Try it online!


0

Brachylog, 10 bytes "!"w.∋w?w⊥ Try it online! Takes input through the output variable, and unifies the input variable with "!", printing the output. "!"w Print "!", which is the input variable. .∋w Print an element of the output variable. ?w Print the input variable again. ⊥ Fail.


0

Japt, 4 bytes Repost from a duplicate challenge. Takes input in reverse order (Y, then X). à øV Try it


0

JavaScript, 26 bytes Repost of a port of Kevin's Java solution to a duplicate challenge, modified in case my choices for I/O weren't standards at the time this challenge was posted. x=>y=>!!y.match([...x].join`.*`) Try it online! (will update with this challenge's test cases when I get back to a computer)


2

MarioLANG, 95 94 90 bytes +++++++++++> ==========@",+[ +++++++++++)==< @==========. - +++++++++++!(.= ===========#== Try it online! First time trying out MarioLANG, that was a lot of fun! Explanation: So, as the name implies, MarioLANG is made to execute like a game of Super Mario Bros. It operates similarly to BF, with memory arranged in a tape ...


0

Julia 1.0, 56 bytes a/b="How much $a would a $a$b $b if a $a$b could $b $a?" Try it online!


0

Perl 5 -pa, 61 bytes $_="How much 0 would a 01 1 if a 01 could 1 0?";s/\d/$F[$&]/g Try it online!


0

Batch, 56 bytes @echo How much %1 would a %1%2 %2 if a %1%2 could %2 %1?


0

Emacs Lips, 79 bytes (lambda(a b)(concat"How much "a" would a "a b" "b" if a "a b" could "b" "a"?"))


0

x86-16 Assembly, 11 bytes Binary: 00000000: 41ac f2ae e303 4a75 f83b ca A.....Ju.;. Unassembled listing: 41 INC CX ; Loop counter is 1 greater than string length SCAN_LOOP: AC LODSB ; load next char of acronym into AL F2/ AE REPNZ SCASB ; search until char AL is ...


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


0

Bash, 58 bytes echo "How much $1 could a $1$2 $2 if a $1$2 could $2 $1?" Takes input as command line arguments. Try it online!


1

C# .NET, 193 bytes class P{static void Main(string[]a){var z="ABCDEFGHIJKLMNOPQRSTUVWXYZ";var b=a[0];System.Console.Write(b.Length>1?b:z.IndexOf((b[0]))>-1?z:z.ToLower().IndexOf((b[0]))>-1?z.ToLower():b[0]+"");}} Try Online EDIT: Variable assignment with if statements is stupid


0

Lua, 82 bytes a,b=...print((('How much x would a xy y if a xy could y x?'):gsub('.',{x=a,y=b}))) Try it online! Full program, take input as arguments. Nothing special here. Hope that there's shorter version, but no obvious ways to shorten this at first glance.


0

C# .NET, 151 bytes class P{static void Main(){for(int i=0;i<26;i++)for(int j=65;j<91;j++)System.Console.Write($"{(j+i>90?(char)(j+i-26):(char)(j+i))}{(j>89?"\n":"")}");}} Try Online EDIT: Removed unnecessary curly brackets


1

AsciiDots, 27 bytes %$A .>#a?*>$_a#A A^ \$_a# Note that this halts in an error, which is allowed. Probably can be golfed quite a lot. Try it online!


0

C# .NET, 144 bytes class P{static void Main(string[]a){foreach(var c in a[0].ToUpper().Split(' '))if(c!="OR"&c!="AND"&c!="BY"&c!="OF")System.Console.Write(c[0]);}} Try Online


1

Haskell, 40 bytes r@(a:c)#(b:d)|a==b=c#d|1>0=r#d x#y=x=="" 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!


0

PowerShell, 21 bytes "$args"-replace"","!" Try it online! Boring regex replacement is boring. ;-)


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

Forth (gforth), 116 bytes : x 2over type ; : y 2dup type ; : f ." How much "x ." would a "x y ." "y ." if a "x y ." could "y ." "x ." ?"; Try it online! Code Explanation \ x = output the first word : x \ start a new word definition 2over type \ copy the "first" word to the top of the stack and print it ; \ end ...


0

Java (JDK), 76 bytes a->b->"How much "+a+" would a "+a+b+" "+b+" if a "+a+b+" could "+b+" "+a+"?" Try it online!


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

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


2

Applesoft BASIC, 77 76 bytes 1INPUTA$,B$:?"How much "A$" would a "A$B$" "B$" if a "A$B$" could "B$" "A$"? The above may not look like proper BASIC, but Applesoft allows for a few shortcuts when using the PRINT statement: Use of ? in place of PRINT when entering the statement Concatenation characters (either ; or +) may be omitted If the statement ends in ...


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


1

VBA, 107 bytes Function q(a,b) b=b&" " c="ould " q="How much "&a&" w"&c&"a "&a&b&b&"if a "&a&b&"c"&c&b&a&"?" End Function Should run as VBScript too, I used two shortcuts: "ould " is repeating and "chuck" never appears without an additional space.


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 bytes a->b->a.matches(b.replaceAll("|",".*")) -7 bytes thanks to @tsh. 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("|",".*")) // where ...


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


0

C#, 159 bytes public class P{public static void Main(string[]a){var f="";foreach (char c in a[0]){f+=" |"+c+"|\n";}System.Console.Write(@" | /_\ "+f+@" |_| /___\ VvV");}} Try Online


2

Keg, 52 characters ?(\|'\| \ )\\\_\/ \ \| ^\ \|\_\|\ \/\_\_\_\\\ VvV Only tricky point is that Keg has no strings, the input is pushed to stack character by character. So the processing order is: read input (?) and turn it into middle section, append top section reversed, reverse them all (^), append bottom section. (Note that the interpreter (TIO ...


Top 50 recent answers are included