# Scroll Word's font size selector

Word's A and buttons change the font size according to these rules:

1. The starting font size is 11.
2. If is pressed when the font size is 1, the size stays 1.
3. The font size changes with 1 point in the range 1 – 12.
4. The font size changes with 2 points in the range 12 – 28.
5. The choices are 28, 36, 48, 72, and 80 in the range 28 – 80.
6. The font size changes with 10 points in the range 80 – 1630.
7. The font size changes with 8 points in the range 1630 – 1638.
8. If A is pressed when the font size is 1638, the size stays 1638.

In as few bytes as possible, determine the resulting font size when given a set of button presses in any reasonable format.

### Examples

[3,-1,2], meaning AAAAA: The result is 18.

Some possible formats are '^^^v^^', [1 1 1 -1 1 1], [True,True,True,False,True,True], ["+","+","+","-","+","+"], "‘‘‘’‘‘", "⛄️⛄️⛄️🌴⛄️⛄️", 111011, "CaB", etc...

[2]: 14

[-1]:10

[13]:80

[-11,1]: 2

[11,-1]: 36

[170,-1]: 1630

[2000,-2,100]: 1638

• Do we have to take the set of button presses in that exact format? For example, would some or all of these be fine as well: "^vvv^v^^^v", [-1, 1, 1, -1, 1, -1], [0, 1, 0, 1, 1, 0, 1]?
– orlp
Jan 4 '17 at 13:31
• @orlp Yes. Originally I wrote them in, but I found the formats silly. I'll put them in right now.
Jan 4 '17 at 13:37
• How about "😀😀😀😟😀😀" or "⛄️⛄️⛄️🌴⛄️⛄️" Jan 5 '17 at 16:02
• @NickT That's fine.
Jan 5 '17 at 16:29

# 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=ThisDocument.Content.Font
For Each i In n
If i Then
f.Grow
Else
f.Shrink
End if
Next
''  Implicitly output font size to MS Word Font Size Selector
End Sub


## Thanks

-21 thanks to @Adám (removed Selection.WholeStory: call)

-10 thanks to @Adám (assume clean environment; remove f.size=11: call)

-14 thanks to @Adám (cheeky output word font size selector)

-2 thanks to @Adám (bool ParamArray)

-13 for changing ParamArray n() to n and expecting input as Boolean Array

-2 for moving from a code module to the ThisDocument module

## Old Version 114 Bytes

Takes input n as a ParamArray, in the form of true,true,false,true and outputs word vbe immediates window

Sub a(ParamArray n()):Set f=Selection.Font:For Each i In n
If i Then f.Grow Else f.Shrink
Next:Debug.?f.Size:End Sub


## Older version, 199 Bytes

Takes input in the form of 170,-4,6,-1 (accepts numbers larger than 1 in magnitude)

Sub a(ParamArray n()):Selection.WholeStory:Set f=Selection.Font:f.Size=12:For Each i In n
If i>1 Then
For j=i To 0 Step -1:f.Grow:Next
Else
For j=i To 0:f.Shrink:Next:End If:Next:Debug.?f.Size:End Sub

• +1 (I'd give more if I could). Why do you Set f=.Size = 12?
Jan 4 '17 at 15:38
• Also, do you need to select the whole story? isn't the current selection enough?
Jan 4 '17 at 15:39
• No need to allow multiple runs. You may assume a clean environment.
Jan 4 '17 at 15:42
• Btw, I change the OP title so that there is no implication that actual emulation must be done. Real use is fine too!
Jan 4 '17 at 15:43
• Actually, just use Word's font size selector as output method!
Jan 4 '17 at 16:09

## 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([]));
console.log(f([1]));
console.log(f([-1]));
console.log(f([1,1,1,-1,1,1,1,1,1,1,1,1]));
console.log(f(Array(2000).fill(1)));

Saved 2 bytes thanks to ETHproductions

• A tip: whenever you have a&&(b=c), you can save a byte with a?b=c:0. Here though, I think you can even save two with n+=n>v&&k*[...][i] Jan 4 '17 at 15:58

# Python 2, 111 107 bytes

i=10;r=range
for d in input():i+=d*(0<i+d<179)
print(r(1,12)+r(12,29,2)+[36,48,72]+r(80,1631,10)+[1638])[i]


Requires input to be in the [-1, 1, 1, -1, ...] format. It works with the examples for some bytes extra:

for d in input():i=min(max(0,i+d),179)

• You can save 3 bytes by using  if 0<i<179:i+=d inside the for loop. Costs you a linefeed and a space indent otherwise would be 5. Jan 4 '17 at 19:34
• Or i+=[0,d][0<i<179] might work Jan 4 '17 at 19:38
• @NonlinearFruit Works but comes in at the same byte count for me (108). Looks much cooler and golfier than an if statement tho. Jan 4 '17 at 19:46
• Both suggestions are incorrect. It would mean that if we hit 0 or 179 we're stuck there forever.
– orlp
Jan 4 '17 at 21:41
• @orlp Good point. Missed that one. Jan 4 '17 at 21:43

# MATL, 4947 45 bytes

11: 9:E10+'$*H'o8:163 10*1638v11ihl180h&Ys0))  Input format is [1 1 -1 1 1 -1 -1 -1] or [2 -1 2 -3], with optional commas. ### Explanation 11: % Push [1 2 ... 11] 9: % Push [1 2 ... 9] E10+ % Times 2, plus 10: gives [12 14 ... 28] '$*H'       % Push this string
o           % Convert to double: gives ASCII codes, that is, [36 48 72]
8:163       % Push [8 9 ... 163]
10*         % Times 10: gives [80 90 ... 1630]
1638        % Push 1638
v           % Concatenate everything into a column vector
11          % Push 11
ih          % Input array and concatenate with 11
l180h       % Push [1 180]
&Ys         % Cumulative sum with limits 1 and 180
0)          % Get last value
)           % Index into column vector of font sizes. Implicitly display

• Finally a golfing language. I was beginning to wonder...
Jan 4 '17 at 17:17
– orlp
Jan 4 '17 at 17:25
• @APL is not a golfing language. 8×6=48, not 68
Jan 4 '17 at 17:29
• @APL is not a mentionable user, neither a user at all. Mar 28 '17 at 10:39

# Octave, 9389 87 bytes

The input array can have integers larger than 1 or smaller than -1 to represent multiplicity of action

L=11;for k=input(''),L=min(max(L+k,1),180);end;[1:11 [6:14 18 24 36 40:5:815 819]*2](L)


Thanks to Adám, Changed language to Octave only to be able to use direct indexing into an array.

Saved 2 bytes thanks to rahnema1.

## Test

On Ideone

• Save 3 bytes by removing the first statement, and changing the last to [1:12,14:2:28,36,48,72,80:10:1630,1638](L).
Jan 4 '17 at 16:49
• @Adám Good idea, but then it only works in Octave Jan 4 '17 at 16:56
• @LuisMendo, thanks, fixed it. Jan 4 '17 at 17:13
• @LuisMendo So? Change the language to Octave only.
Jan 4 '17 at 17:13
• [1:11 [6:14 18 24 36 40:5:815 819]*2] some bytes can be saved! Jan 4 '17 at 20:26

# Ruby, 106 bytes

I managed to shave a couple of bytes off the python solution (and it took a while of shaving).

->n{[*1..12,*(14..28).step(2),36,48,72,*(80..1630).step(10),1638][n.inject(11){|a,b|[0,179,a+b].sort[1]}]}


It's an anonymous function that takes the input in the form of [1, -1, 1, 1, ...]. It seems to deal quite well with input in the form [170,-12] as well, but I can't guarantee it will work 100% of the time, so I'll play it safe and say it works with [1, -1, 1, 1, ...].

## Tricks I used:

• [0,179,a+b].sort[1]: This clamps a+b to be between 0 and 179, which are the valid indexes of the font-size array.

• Using the splat operator on ranges converts them into arrays, so the available font sizes is generated from [*1..12,*(14..28).step(2),36,48,72,*(80..1630).step(10),1638]. Which is a flat array containing the values from each of the flattened elements:

• 1..12 is a range from 1 to 12 (inclusive). The splat operator turns it into the values 1, 2, 3, ..., 11, 12.
• (14..28).step(2) is an enumerator for the given range, where each step goes up by 2. The splat operator turns it into the values 14, 16, 18, ..., 26, 28.
• The individual values (36, 48, 72, 1638) are all concatenated in their position into the great font-size array.
• I used the inject(/reduce) method, which uses each element of the input array, while reducing them down into a 'memo' variable (as ruby puts it). I initialise this to 11, and the body of each inject iteration is to set this memo variable to the result of adding the current element of the input to the current memo value, and then clamping it between 0 and 180.

All hail the splat operator!

# PHP, 116 bytes

first generates the size index (from 1 to 180 inclusive),
then maps that to the point size and prints the result.

for($s=11;$d=$argv[++$i];$s=min($s+$d,180)?:1);echo$s>12?$s>20?$s>23?$s*10-160-2*($s>179):24+(12<<$s-21):$s*2-12:$s;  takes +N and -1 from command line arguments. (-N is also accepted; just take care that the size does not hop below zero!) Run with -nr. # Perl 5, 123 106 bytes @a=(1..12,map$_*2,7..14,18,24,36,map$_*5,8..163,163.8);$i=10;$\=$a[$i=($"=$i+$_)<0?0:$">179?179:$"]for@F}{


Try it online!

Input format:

32 -32 12 4 -2


# C (gcc), 157 154 bytes

-3 bytes thanks to ceilingcat.

Takes a string of + (step up) and non-+ (step down). Returns the final font size.

n,d;f(char*s){for(n=11;*s;n=n>28&n<81?index("\34$0HP",n-d)[2*d-1]:n-d+((n>1&n<29)+(n>12&n<29)+(n>80&n<1639)*8+(n>80&n<1631)*2)*(2*d-1))n+=d=*s++==43;s=n;}  Try it online! • @ceilingcat Cheers! Feb 9 '20 at 20:38 # Zsh, 98 bytes a=({1..12} {14..28..2} 36 48 72 {8..163}0 1638) r=11 for i;((r+=i,r=(r>$#a)?$#a:(r?r:1))) <<<$a[r]


Try it online!

Iterate through the arguments, clamping our index between 1 and $#a (length of $a).