# Paper and Envelope Sizes

Given a letter (A, B, C), and a number (0-10), output the size of the matching standard paper size (Series A and B) or the matching standard envelope size (C series) in millimetres in the format aaaa x bbbb where aaaa and bbbb are the width and height measurements in millimetres as per ISO216 (Series A & B) or ISO296 (Series C)

To make things easier I will quote from Wikipedia's table of Paper Sizes

ISO paper sizes in portrait view
Format  A series    B series    C series
Size     mm × mm      mm × mm    mm × mm
0       841 × 1189  1000 × 1414 917 × 1297
1       594 × 841    707 × 1000 648 × 917
2       420 × 594    500 × 707  458 × 648
3       297 × 420    353 × 500  324 × 458
4       210 × 297    250 × 353  229 × 324
5       148 × 210    176 × 250  162 × 229
6       105 × 148    125 × 176  114 × 162
7        74 × 105     88 × 125   81 × 114
8        52 × 74      62 × 88    57 × 81
9        37 × 52      44 × 62    40 × 57
10       26 × 37      31 × 44    28 × 40


So examples of input and output:

**Test case 1**
Input: A4
Output: 210 x 297

**Test Case 2**
Input: B6
Output: 125 x 176

**Test Case 3**
Input: C2
Output: 458 x 648


Things to note:

1. The format "210 x 297" or "1000 x 1414" etc. While this is the preferable format, You can choose to omit the " x " from your output, i.e. in the form of an array or two numbers or whatever tickles your fancy as long as the width measurement is outputted before the height.
2. The ratio between the height and the width is roughly equivalent to the square root of 2, so in the calculation of the heights, the width is multiplied by sqrt(2), and then rounded up or down to the nearest millimetre, thus resulting in the measurements in the table above. This may help golf down your code.
3. In successive sizes for a series as you go down the table, the width for one size becomes the height for the next. This may also help you golf down your code.

Rules:

1. This is code-golf. Standard rules apply as a result. The score will be based on byte count. Lowest count will win.
2. No silly loopholes, we've been there before... We shan't go through this again.
3. If you can code it, then please also consider attaching a link to a working instance of your code so that other programmers and golfers can learn how your code works. This is not mandatory, but I'd like to encourage others to do this so we can all learn off one another. I certainly would love to learn more about other golfer's languages where possible.

Best of luck.

• Bn is the geometric mean of An and An+1, and Cn is the geometric mean of An and Bn.
Nov 15, 2017 at 10:23
• – Leo
Nov 16, 2017 at 4:20

## JavaScript (ES7), 57 bytes

Saved 1 byte thanks to @WallyWest

s=>n=>[n,n-1].map(x=>.707**x*{A:841,B:1e3,C:917}[s]+.2|0)

• Nice work... you can make it 57 with s=>n=>[n,n-1].map(x=>.707**x*{A:841,B:1e3,C:917}[s]+.2|0) and it will still have the same precision in your output. Nov 15, 2017 at 5:44
• @WallyWest Thanks for the tip. I'd played around with various replacements for .7071 and .2 for a while and just kinda gave up when I found something that worked :P Nov 15, 2017 at 16:42
• No worries, all in the name of code golf... ;) I didn't realize map allowed one to reference unquoted keys within an object like that...? I'll have to use that sometime soon... Nov 15, 2017 at 19:41
• @WallyWest That has nothing to do with .map, you can use {key1:1,key2:2,key3:3}[myKey] anytime you wish. You only need to quote the keys if they are not valid variable names. Nov 15, 2017 at 19:58
• Brilliant, thanks for the tip... Nov 15, 2017 at 19:59

# C (gcc), 1131119078 70 bytes

It needs -lm to run on TIO, but works well on my computer without the option.

Saved 20 bytes thanks to pizzapants184.

Return values by pointer.

f(a,b,c,d)int*c,*d;{float x=1e3*pow(.707,b+a%3/4.)+.2;*c=x,*d=x/.707;}


Explanation:

f(a,b,c,d)int*c,*d;{          // calling by char, but receive as int
float x = 1e3 * pow(.707, // float gives enough precision
a % 3 / 4.        // series: a%3/4.=.5,0,.25 when a=65,66,67
+ b) - .2;        // magic number to get correct roundings
*c = x, *d = x / .707;
}

• 94 bytes + -lm by taking input as a char and int Nov 15, 2017 at 4:15
• 91 bytes + -lm by changing (a^66?a^67:0.5:0.25:0) to abs(a-66)/(a-63.) Nov 15, 2017 at 4:31

# Python 2, 10397938483 81 bytes

def f(l,n):w=[841,1000,917][ord(l)-65];h=int(w/.707);exec"w,h=h/2,w;"*n;print w,h


Try it online!

## Batch, 105 bytes

@set/aA=1189,B=1414,C=1297,h=%1,w=h*29/41
@for /l %%i in (1,1,%2)do @set/at=w,w=h/2,h=t
@echo %w% x %h%


41/29 ≅ √2

• Are decimals not possible in Batch, @Neil? I would have thought h*.707 would be better than h*41/29? Mind you, ingenious use of approximation! Nov 15, 2017 at 11:13
• @WallyWest No, 32-bit signed integers only.
– Neil
Nov 15, 2017 at 11:19
• Oh, I see! Learn something new everyday! Nov 15, 2017 at 11:20

# JavaScript, 53 bytes

L=>N=>[N+1,N].map(p=>1091/2**(p/2+~{B:2,C:1}[L]/8)|0)


f=

L=>N=>[N+1,N].map(p=>1091/2**(p/2+~{B:2,C:1}[L]/8)|0)

document.write('<table><tr><th><th>A<th>B<th>C',[...Array(11)].map((_,i)=>'<tr><th>'+i+['A','B','C'].map(j=>'<td>'+f(j)(i)).join).join);

Save many bytes by using alternative output format, thanks to Neil.

• 66 bytes: L=>N=>(g=p=>1000.2/2**(N/2+p-{A:2,B:4,C:3}[L]/8)|0)(.5)+' x '+g(0)
– Neil
Nov 15, 2017 at 10:13
• Or 58 bytes if you use the alternative output format: L=>N=>[N+1,N].map(p=>1000.2/2**(p/2-{A:2,B:4,C:3}[L]/8)|0)
– Neil
Nov 15, 2017 at 10:16
• @Neil edited. And also reduced to 56 bytes
– tsh
Nov 15, 2017 at 11:01

# Java (OpenJDK 8), 59 bytes

f->s->new double[]{s=1e3*Math.pow(.707,s+f%3/4d)-.2,s/.707}


Try it online!

Inspired by @Colera Su's C entry, then improved by myself.

• 14 bytes saved thanks to Kevin Cruijssen
• 1000 can be 1e3. Nov 15, 2017 at 9:18
• 75 bytes Nov 15, 2017 at 9:30

# MATL, 3433 30 bytes

917 841 1000.5vjo)t2X^*hi2/W/k


Saved 4 byte thanks to Luis Mendo

# APL (Dyalog), 31 28 bytes

-2 thanks to ngn.

Full program body. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems. Prompts for number, then letter, both from STDIN. Prints to STDOUT.

⌊.2+1E3÷2*8÷⍨('BC'⍳⍞)+4×⎕-⍳2


Try it online!

A slightly modified version lets us test all possibilities at once: Try it online!

⍳2 first two ɩndices, i.e. 0 and 1

⎕- subtract that from numeric input

4× multiply four with that

()+ add the following

⍞ character input…

'BC'⍳ …'s ɩndex in this string ("A" will give 2, as the index beyond the last)

8÷⍨ divide that by 8

2* raise 2 to the power of that

1E3÷ 1000 divided by that

.2+ add ⅕ to that

⌊ floor (round down)

# Befunge, 6956 55 bytes

"}"8*~3%:"L"*7vv\p00-1_$..@ ")"*":":-*!!\+<>2/00g:^:&\/  Try it online! Explanation We don't have the luxury of floating point or anything like a power function in Befunge, so we calculate the base size for the given format character, f, as follow: fn = f % 3 width = 1000 - (n * 76 + 7) * !!n height = width * 58 / 41  We then repeatedly rotate and divide these dimensions to get to the appropriate subdivision for the given size number. "}"8* Push 1000 for later use in the width calculation. ~ Read the format character from stdin. 3% Convert into a number in the range 0 to 2. :"L"*7v Calculate width = 1000 - (fn * 76 + 7) * !!fn -*!!\+< where fn is the format number derived above. ")"*":": / Calculate height = width * 58 / 41. \ Swap so the width is above the height on the stack. v:& Read the numeric size from stdin and duplicate for testing. _ While not zero, go left. p00-1 Decrement the size and move it from the stack into memory. v/ Swap the width and height. >2/ Divide the new width by 2. 00g: Restore the size from memory and duplicate for testing. _ While not zero, repeat this loop.$      When zero, continue to the right and drop the size.
..@   Output the width and height, then exit.