Scroll Word's font size selector

35

3

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

Adám

Posted 2017-01-04T13:27:17.997

Reputation: 37 779

3Do 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 – 2017-01-04T13:31:31.283

@orlp Yes. Originally I wrote them in, but I found the formats silly. I'll put them in right now. – Adám – 2017-01-04T13:37:11.933

2How about "" or "⛄️⛄️⛄️⛄️⛄️" – Nick T – 2017-01-05T16:02:37.530

4@NickT That's fine. – Adám – 2017-01-05T16:29:44.783

Answers

6

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

Luis Mendo

Posted 2017-01-04T13:27:17.997

Reputation: 87 464

Finally a golfing language. I was beginning to wonder... – Adám – 2017-01-04T17:17:08.837

2@Adám We need an answer in APL :) – orlp – 2017-01-04T17:25:39.967

@APL is not a golfing language. 8×6=48, not 68 – Adám – 2017-01-04T17:29:48.600

1@APL is not a mentionable user, neither a user at all. – Matthew Roh – 2017-03-28T10:39:08.780

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

.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

Taylor Scott

Posted 2017-01-04T13:27:17.997

Reputation: 6 709

1+1 (I'd give more if I could). Why do you Set f=.Size = 12? – Adám – 2017-01-04T15:38:06.167

1Also, do you need to select the whole story? isn't the current selection enough? – Adám – 2017-01-04T15:39:06.390

@Adám Thanks :) the f.size=12 should, now that I look at it actually be f.size = 11 and is there so that the sub may be run more than once, as this actually changes the size of the font every time that is is run. Also, you are completely correct in not needing the wholestory call – Taylor Scott – 2017-01-04T15:41:33.430

1No need to allow multiple runs. You may assume a clean environment. – Adám – 2017-01-04T15:42:56.287

1Btw, I change the OP title so that there is no implication that actual emulation must be done. Real use is fine too! – Adám – 2017-01-04T15:43:49.307

1A function (not complete program) is allowed per PPCG default rules. Couldn't you Return f.Size instead of printing it? – Adám – 2017-01-04T15:58:11.597

@Adám in VBA because a function requires Function a...a=n:End Function (26 bytes) calls, it is actually more byte efficient (in most cases) to use a subroutine and print the output Sub a...Debug.?n:End Sub (21 Bytes) – Taylor Scott – 2017-01-04T16:05:02.410

2

Actually, just use Word's font size selector as output method!

– Adám – 2017-01-04T16:09:00.113

1Couldn't n be an array of Booleans, so you can write If i Then? – Adám – 2017-01-04T16:34:15.680

1Does Word VBA support With? That'd probably be slightly shorter than Set for avoiding the need to repeat Selection.Font, if it works. – None – 2017-01-07T08:32:48.167

1@ais523 word vba does support with however it requires a end with call that means for code golf it is often, as in this case, more byte-efficient to use a set call – Taylor Scott – 2017-01-07T16:47:10.973

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([]));
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

Arnauld

Posted 2017-01-04T13:27:17.997

Reputation: 111 334

1A 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] – ETHproductions – 2017-01-04T15:58:14.597

9

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)

orlp

Posted 2017-01-04T13:27:17.997

Reputation: 37 067

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. – ElPedro – 2017-01-04T19:34:13.077

Or i+=[0,d][0<i<179] might work – NonlinearFruit – 2017-01-04T19:38:02.990

@NonlinearFruit Works but comes in at the same byte count for me (108). Looks much cooler and golfier than an if statement tho. – ElPedro – 2017-01-04T19:46:02.157

1Both suggestions are incorrect. It would mean that if we hit 0 or 179 we're stuck there forever. – orlp – 2017-01-04T21:41:30.620

@orlp Good point. Missed that one. – ElPedro – 2017-01-04T21:43:10.263

6

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

Mohsen Nosratinia

Posted 2017-01-04T13:27:17.997

Reputation: 171

1Save 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). – Adám – 2017-01-04T16:49:40.560

@Adám Good idea, but then it only works in Octave – Luis Mendo – 2017-01-04T16:56:01.393

@LuisMendo, thanks, fixed it. – Mohsen Nosratinia – 2017-01-04T17:13:11.283

1@LuisMendo So? Change the language to Octave only. – Adám – 2017-01-04T17:13:35.693

@Adám Yes, that was my point. I wasn't pointing it out as a drawback – Luis Mendo – 2017-01-04T17:15:46.477

2[1:11 [6:14 18 24 36 40:5:815 819]*2] some bytes can be saved! – rahnema1 – 2017-01-04T20:26:14.090

4

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!

IMP1

Posted 2017-01-04T13:27:17.997

Reputation: 510

2

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.

Titus

Posted 2017-01-04T13:27:17.997

Reputation: 13 814

1

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

Xcali

Posted 2017-01-04T13:27:17.997

Reputation: 7 671

1

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!

gastropner

Posted 2017-01-04T13:27:17.997

Reputation: 3 264

@ceilingcat Cheers! – gastropner – 2020-02-09T20:38:51.160

1

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

GammaFunction

Posted 2017-01-04T13:27:17.997

Reputation: 2 838