32
\$\begingroup\$

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.

Task

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

\$\endgroup\$
  • 3
    \$\begingroup\$ 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]? \$\endgroup\$ – orlp Jan 4 '17 at 13:31
  • \$\begingroup\$ @orlp Yes. Originally I wrote them in, but I found the formats silly. I'll put them in right now. \$\endgroup\$ – Adám Jan 4 '17 at 13:37
  • 2
    \$\begingroup\$ How about "😀😀😀😟😀😀" or "⛄️⛄️⛄️🌴⛄️⛄️" \$\endgroup\$ – Nick T Jan 5 '17 at 16:02
  • 3
    \$\begingroup\$ @NickT That's fine. \$\endgroup\$ – Adám Jan 5 '17 at 16:29
6
\$\begingroup\$

MATL, 49 47 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.

Try it online! Or verify all test cases.

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
\$\endgroup\$
  • \$\begingroup\$ Finally a golfing language. I was beginning to wonder... \$\endgroup\$ – Adám Jan 4 '17 at 17:17
  • 2
    \$\begingroup\$ @Adám We need an answer in APL :) \$\endgroup\$ – orlp Jan 4 '17 at 17:25
  • \$\begingroup\$ @APL is not a golfing language. 8×6=48, not 68 \$\endgroup\$ – Adám Jan 4 '17 at 17:29
  • 1
    \$\begingroup\$ @APL is not a mentionable user, neither a user at all. \$\endgroup\$ – Matthew Roh Mar 28 '17 at 10:39
43
\$\begingroup\$

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
    Next
    ''  Implicitly output font size to MS Word Font Size Selector 
End Sub

.GIF of usage

I'm a .GIF!

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

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

\$\endgroup\$
  • 1
    \$\begingroup\$ 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] \$\endgroup\$ – ETHproductions Jan 4 '17 at 15:58
9
\$\begingroup\$

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)
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – ElPedro Jan 4 '17 at 19:34
  • \$\begingroup\$ Or i+=[0,d][0<i<179] might work \$\endgroup\$ – NonlinearFruit Jan 4 '17 at 19:38
  • \$\begingroup\$ @NonlinearFruit Works but comes in at the same byte count for me (108). Looks much cooler and golfier than an if statement tho. \$\endgroup\$ – ElPedro Jan 4 '17 at 19:46
  • 1
    \$\begingroup\$ Both suggestions are incorrect. It would mean that if we hit 0 or 179 we're stuck there forever. \$\endgroup\$ – orlp Jan 4 '17 at 21:41
  • \$\begingroup\$ @orlp Good point. Missed that one. \$\endgroup\$ – ElPedro Jan 4 '17 at 21:43
6
\$\begingroup\$

Octave, 93 89 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

\$\endgroup\$
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ – Adám Jan 4 '17 at 16:49
  • \$\begingroup\$ @Adám Good idea, but then it only works in Octave \$\endgroup\$ – Luis Mendo Jan 4 '17 at 16:56
  • \$\begingroup\$ @LuisMendo, thanks, fixed it. \$\endgroup\$ – Mohsen Nosratinia Jan 4 '17 at 17:13
  • 1
    \$\begingroup\$ @LuisMendo So? Change the language to Octave only. \$\endgroup\$ – Adám Jan 4 '17 at 17:13
  • 2
    \$\begingroup\$ [1:11 [6:14 18 24 36 40:5:815 819]*2] some bytes can be saved! \$\endgroup\$ – rahnema1 Jan 4 '17 at 20:26
4
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Perl 5, 123 bytes

122 bytes of code + 1 for -a

@a=1..12;push@a,map$_*2,7..14;push@a,map$_*($i=10),3.6,4.8,7.2,8..163,163.8;$i=($"=$i+$_)<0?0:$">179?179:$"for@F;say$a[$i]

Try it online!

Input format:

32 -32 12 4 -2
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.