Cuộn chọn kích thước phông chữ của Word


32

Word và các nút thay đổi kích thước phông chữ theo các quy tắc sau:A

  1. Cỡ chữ bắt đầu là 11.
  2. Nếu được nhấn khi kích thước phông chữ là 1, kích thước vẫn là 1.
  3. Kích thước phông chữ thay đổi với 1 điểm trong phạm vi 1 - 12.
  4. Cỡ chữ thay đổi với 2 điểm trong phạm vi 12 - 28.
  5. Các lựa chọn là 28, 36, 48, 72 và 80 trong phạm vi 28 - 80.
  6. Cỡ chữ thay đổi với 10 điểm trong phạm vi 80 - 1630.
  7. Cỡ chữ thay đổi với 8 điểm trong phạm vi 1630 - 1638.
  8. Nếu được nhấn khi kích thước phông chữ là 1638, kích thước vẫn là 1638.A

Bài tập

Trong càng ít byte càng tốt, xác định kích thước phông chữ kết quả khi được cung cấp một bộ nút nhấn ở bất kỳ định dạng hợp lý nào.

Ví dụ

[3,-1,2], nghĩa là : Kết quả là 18.AAAAA

Một số định dạng có thể là '^^^v^^', [1 1 1 -1 1 1], [True,True,True,False,True,True], ["+","+","+","-","+","+"], "‘‘‘’‘‘", "⛄️⛄️⛄️🌴⛄️⛄️", 111011, "CaB", vv ...

[2]: 14

[-1]: 10

[13]: 80

[-11,1]: 2

[11,-1]: 36

[170,-1]: 1630

[2000,-2,100]: 1638


3
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

@orlp Yes. Originally I wrote them in, but I found the formats silly. I'll put them in right now.
Adám

2
How about "😀😀😀😟😀😀" or "⛄️⛄️⛄️🌴⛄️⛄️"
Nick T

3
@NickT That's fine.
Adám

Câu trả lời:


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

Finally a golfing language. I was beginning to wonder...
Adám

2
@Adám We need an answer in APL :)
orlp

@APL is not a golfing language. 8×6=48, not 68
Adám

1
@APL is not a mentionable user, neither a user at all.
Matthew Roh

43

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

1
+1 (I'd give more if I could). Why do you Set f=.Size = 12?
Adám

1
Also, do you need to select the whole story? isn't the current selection enough?
Adám

1
No need to allow multiple runs. You may assume a clean environment.
Adám

1
Btw, I change the OP title so that there is no implication that actual emulation must be done. Real use is fine too!
Adám


11

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

Saved 2 bytes thanks to ETHproductions


1
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]
ETHproductions

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)

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

Or i+=[0,d][0<i<179] might work
NonlinearFruit

@NonlinearFruit Works but comes in at the same byte count for me (108). Looks much cooler and golfier than an if statement tho.
ElPedro

1
Both suggestions are incorrect. It would mean that if we hit 0 or 179 we're stuck there forever.
orlp

@orlp Good point. Missed that one.
ElPedro

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


1
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).
Adám

@Adám Good idea, but then it only works in Octave
Luis Mendo

@LuisMendo, thanks, fixed it.
Mohsen Nosratinia

1
@LuisMendo So? Change the language to Octave only.
Adám

2
[1:11 [6:14 18 24 36 40:5:815 819]*2] some bytes can be saved!
rahnema1

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!


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.


1

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
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.