46

Word VBA, 199 147 126 116 102 100 87 85 Bytes Why emulate when you can do?! Declared function in the ThisDocument module that takes input n in the form of Array(true,true,false,true) and outputs to the Word font size selector :P Golfed: Sub a(n):Set f=Content.Font:For Each i In n If i Then f.Grow Else f.Shrink Next:End Sub Ungolfed: Sub a(n) Set f=...


43

Brainfuck, 46 45 (63 with printable characters in input) Compatible with Alex Pankratov's bff (brainfuck interpreter used on SPOJ and ideone) and Thomas Cort's BFI (used on Anarchy Golf). The printable version takes the array first as a string, followed by a tab, followed by the starting string with no trailing newline. Demonstration on ideone. -[+>,--...


30

Python 2, 46 45 bytes f=lambda n,k=1:`k`in bin(n^n/2)and-~f(n,k*10) Try it online! How it works By XORing n and n/2 (dividing by 2 essentially chops off the last bit), we get a new integer m whose unset bits indicate matching adjacent bits in n. For example, if n = 1337371, we have the following. n = 1337371 = 101000110100000011011₂ n/2 = 668685 = ...


24

Ruby, 50 44 43 bytes FGITW answer. Gotta go fast! Thanks to @Neil for saving 6 bytes. Oh right, crossed out 44 is still 44 ->m,t{m.gsub(/\d+/){eval$&+t.sub(?^,'**')}}


24

Wolfram Language (Mathematica), 34 bytes 0~Range~19~Binomial~i~Sum~{i,0,#}& Try it online! The tier \$n\$ metasequence is the sum of the first \$n+1\$ elements of each row of the Pascal triangle.


18

Haskell, 34 bytes (iterate(init.scanl(+)1)[1..20]!!) Uses 0-indexed inputs (f 4 returns tier 5.) Haskell, 36 bytes f 1=[1..20] f n=init$scanl(+)1$f$n-1 Try it online! Uses 1-indexed inputs (f 5 returns tier 5.) Explanation scanl (+) 1 is a function that takes partial sums of a list, starting from (and prepending) 1. For example: scanl (+) 1 [20,300,...


17

Python 2, 46 bytes f=lambda n,r=1:max(r,n and f(n/2,1+~-n/2%2*r)) Try it online Extracts binary digits from n in reverse by repeatedly taking n/2 and n%2. Tracks the length of the current run r of equal digits by resetting it to 0 if the last two digits are unequal, then adding 1. The expression ~-n/2%2 is an indicator of whether the last two digits are ...


15

Perl, 36 34 bytes s/\d+/"0|$&$^I"=~s#\^#**#r/gee The source code is 30 bytes long and it requires the switches -pi (+4 bytes). It takes the first input from STDIN, the second input as an argument to -i. Thanks to @DenisIbaev for golfing off 2 bytes! Test it on Ideone.


15

Jelly, 1 byte ṡ Jelly has a single byte dyadic atom for this very operation Try it online! (the footer splits the resulting list with newlines, to avoid a mushed representation being printed.)


14

CJam, 15 bytes rr{_C#)/(C@s}fC Try it online. How it works rr e# Read two whitespace-separated tokens from STDIN. { }fC e# For each character C in the second string. _ e# Duplicate the first string. C# e# Compute the index of the character in the string. )/ e# Add 1 and split the string ...


14

05AB1E, 6 bytes b.¡€gM Try it online! Explanation b # convert to binary .¡ # split at difference €g # map length on each M # take max


12

C, 62 bytes f(char*s,char*c){while(*s-*c||putchar(*c++),*s)putchar(*s++);} Well, this is surprisingly competetive. We define a function f(char*, char*) that takes the string as its first input and the array of characters to duplicate as its second input. Some testing code: int main (int argc, char** argv) { f("onomatopeia", "oao"); ...


12

Python 2, 95 bytes l=[];n=input() exec"a=min(set(range(n))-{2*b-c for b,c in zip(l,l[1::2])});print-~a;l=[a]+l;"*n The main trick is in generating the numbers the new value must avoid. Keeping the reversed sequence so far in l, let's look at what elements might form a three-term arithmetic progression with the value we're about to add. ? 4 2 2 1 ...


12

Jelly, 10 7 bytes BṡRḄFS_ Try it online! How it works BṡRḄFS_ Main link. Input: n B Convert n to base 2. R Yield [1, ..., n]. ṡ Get all overlapping slices of lengths 1 to n. This yields empty arrays if the slice size is longer than the binary list. Ḅ Convert each binary list to integer. F Flatten the ...


12

Python 2, 88 bytes def f(a,b,c,o=""): for q in a:x=q==b[:1];o+=c[:x]or q;b=b[x:];c=c[x:] print[o,a][c>''] A function that takes in the three strings and outputs the result to STDOUT. The function simply does one pass over the string, taking the appropriate char and updating b,c as we go. For testing (after replacing the print with return): S = """ &...


12

JavaScript (ES6), 103 101 bytes Takes input as an array of -1 / 1. a=>a.map(k=>[1,12,28,36,48,72,80,1630,1638].map((v,i)=>n+=n>v&&k*[1,1,6,4,12,-16,2,-2,-8][i]),n=11)|n Test let f = a=>a.map(k=>[1,12,28,36,48,72,80,1630,1638].map((v,i)=>n+=n>v&&k*[1,1,6,4,12,-16,2,-2,-8][i]),n=11)|n console.log(f([])); ...


12

J, 11, 9 8 bytes -1 byte thanks to miles! [:+//.]\ How it works? The left argument is s, the right one - L ]\ - splits L into sublists with length s /. - extracts the oblique diagonals (anti-diagonals) +/ - adds them up [: - makes a fork from the above verbs Here's an example J session for the first test case: a =. 1 2 3 4 5 6 7 8 9 ] 3 ]\ a ...


12

Java 8, 48 39 33 bytes s->"ROYGBRO BGYORBG".indexOf(s)|7 -6 bytes thanks to @RickHitchcock, so make sure to upvote him as well! Takes uppercase color as input-String. Outputs -1 for none, 7 for clockwise, and 15 for counterclockwise. Try it online. Explanation: s-> // Method with String parameter and integer return-type "...


12

J, 23 21 20 bytes >&#*]e.1}:@}.-&#]\.[ Try it online! -1 byte thanks to Bubbler Return true if: >&# left arg is strictly longer than right (see the "friend"/"friend" test case) * and... ] the right arg e. is an element of the list formed by... 1 }:@}. removing the first and last elements of... -&# ]\. [ all the outfixes \. of the ...


11

CJam, 15 bytes rr{:X/(XX+@X*}/ An alternative CJam approach. Try it online Explanation For each character in the second string, we do two things. Split the current suffix of the string by the character, e.g. "beeper" "e" -> ["b" "" "p" "r"] Uncons the first string in the array, insert two of the character, then rejoin the rest of the array with the ...


11

Pyth, 17 16 bytes 1 byte thanks to Jakube iR2cJ.BQx1qVJ+dJ Demonstration A nice, clever solution. Uses some lesser known features of Pyth, like x<int><list> and c<str><list>. iR2cJ.BQx1qVJ+dJ Q = eval(input()) J.BQ Store in J the input in binary. qV Vectorize equality function ...


11

Python, 52 bytes lambda w,d:len({len(x)for x in d if x in w})==len(w) An anonymous function that takes a word w and dictionary d. It takes the words in d that are substrings of w, makes a set of their lengths, and then checks that there as many distinct lengths as there are letters in w.


11

Python 2, 68 63 bytes f=lambda s,n=1:s==2*s[:n]or''<s[n:]>-f(s,n+1)<f(s[n:])*f(s[:n]) Returns True or False. Test it on Ideone.


11

Brachylog, 8 bytes ~c¬{∋¬∈} Try it online! This is really slow. Took about 37 seconds for the "Hello, world!" test case on my PC, and timed-out on TIO. This takes the string through the Input variable and the list through the Output variable Explanation String = ?, List = . It is possible to find… ~c …a ...


11

Python 3 + SciPy, 396 390 385 351 336 355 bytes from scipy.optimize import* n=int(input()) r=range(n) def f(u): s=linprog(r,u,[-n]*len(u),options={'tol':.1});c=s.success;y=sorted(range(c<<n),key=lambda a:s.x.round()@[a>>i&1for i in r]) for a,b in zip(y,y[1:]): v=[(a>>i&1)-(b>>i&1)for i in r] if~-(v in u):c+=f(u+[[-z ...


11

JavaScript (ES6),  75 73  71 bytes Saved 1 byte thanks to @Shaggy Saved 2 bytes thanks to @Neil s=>/1|7|(2[^07]|3[578]|42|599?|50|6[789]|8[0578]|9[679]|.)./.exec(s)[0] Try it online!


10

Java, 99.04 98.46 97.66 lcs() calls How it works Exaple: Our line that is to be reconstructed is 00101. First we find out how many zeros there are, by comparing (here comparing = computing lcs with the original string) by a zeros only string 00000. Then we go through each position, flip the 0 to a 1 and check if we now have a longer common substring. If ...


10

Jolf, 15 14 bytes ρi«\d+»dC!6+HI Try it here! Explanation ρi«\d+»dC!6+HI ρ «\d+» replace all digits i in the input d (functional replace) !6 eval (using jolf's custom infix eval) +H the number as a string plus I the second input C floor the result (integer truncate) ...


10

Python 2, 45 43 bytes -2 bytes thanks to @TFeld s=[] for c in input():s+=c,-1;s.remove(c-1) Try it online!


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