# Insulate the Window Glass and Foil of your house

## Introduction:

The best options for the glass of your house will:
1. Let through as little heat as possible in both directions (insulation-value Ug).
(2. Let through as much sunbeams as possible from the outside to the inside.)
(3. Let through as much light as possible from the outside to the inside.)

We only care about the first one for this challenge.

In addition, there are different types of glass changing the Ug: regular single glass; regular double glass; HR double glass; HR+ double glass; HR++ double glass; HR+++ double glass.
HR = High Rendement glass; regular double glass with have air between both layers, but HR will have a noble gas between both layers.

Sources (not very useful for most though, because they are in Dutch, but added them anyway): Insulate and save money and What is HR++ glass?

## Challenge:

Input: A string indicating glass and window foil (below the possible input-strings are explained)
Output: (Calculate and) output the heat-transition Ug

Here a table with all glass options and the expected output Ug-values:

Glass (optional foil)    Ug-value    Description

|                        5.8         Single-layered regular glass
||                       2.7         Double-layered regular glass
| |                      1.85        HR glass
|+|                      1.45        HR+ glass
|++|                     1.2         HR++ glass
|+++|                    0.7         HR+++ glass
|r                       3.4         Single-layered regular glass with reflective foil
||r                      2.1         Double-layered regular glass with reflective foil
|f                       2.8         Single-layered regular glass with regular window-foil
||f                      2.0         Double-layered regular glass with regular window-foil

|g                       4.35        | with insulating curtain
||g                      2.025       || with insulating curtain
| |g                     1.3875      | | with insulating curtain
|+|g                     1.0875      |+| with insulating curtain
|++|g                    0.9         |++| with insulating curtain
|+++|g                   0.525       |+++| with insulating curtain
|rg                      2.55        |r with insulating curtain
||rg                     1.575       ||r with insulating curtain
|fg                      2.1         |f with insulating curtain
||fg                     1.5         ||f with insulating curtain

/                        8.7         Diagonal |
//                       4.05        Diagonal ||
/ /                      2.775       Diagonal | |
/+/                      2.175       Diagonal |+|
/++/                     1.8         Diagonal |++|
/+++/                    1.05        Diagonal |+++|
/r                       5.1         Diagonal |r
//r                      3.15        Diagonal ||r
/f                       4.2         Diagonal |f
//f                      3.0         Diagonal ||f

/g                       6.525       Diagonal | with insulating curtain
//g                      3.0375      Diagonal || with insulating curtain
/ /g                     2.08125     Diagonal | | with insulating curtain
/+/g                     1.63125     Diagonal |+| with insulating curtain
/++/g                    1.35        Diagonal |++| with insulating curtain
/+++/g                   0.7875      Diagonal |+++| with insulating curtain
/rg                      3.825       Diagonal |r with insulating  curtain
//rg                     2.3625      Diagonal ||r with insulating curtain
/fg                      3.15        Diagonal |f with insulating curtain
//fg                     2.25        Diagonal ||f with insulating curtain


Some things to note about the values: the first ten are all the different default values (taken from the two linked sources). Adding a g (insulating curtain) lowers that value by 25%. Having a / (diagonal window) increases that value by 50%.

## Challenge rules:

• You can ignore any floating point precision errors
• You can use the default decimal output-format of your languages, so if 3.0 is output as 3 instead; or if 0.9 is output as 0.900 or .9 instead, it doesn't matter.
• You'll only have to worry about the input-options given above. Inputting anything else may result in undefined behavior (weird outputs, errors, etc.)

## General rules:

• This is , so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
• Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
• Default Loopholes are forbidden.
• One never has too much isolation during a (Dutch) heat wave. – JayCe Jun 11 '18 at 12:54
• @Giuseppe You're completely right. In Dutch it's "isoleren", hence the translation error. Dutch to English it's "isoleren" = "insulating" and "isolatie" = "isolation". Should be fixed now. – Kevin Cruijssen Jun 11 '18 at 16:10
• The order for diagonal/insulating curtain shouldn't matter, since they correspond to multiplication (i.e. Ug*1.5*0.75=Ug*0.75*1.5) – boboquack Jun 12 '18 at 9:25
• @boboquack You're indeed correct. Not sure why I added it in the first place.. Removed. Thanks. – Kevin Cruijssen Jun 12 '18 at 9:33

# Python 2, 172147128117112 99 bytes

lambda w:ord('8%06(*D0t0'[sum(map(ord,w.strip('g')))%77%24%13])*(2+('/'in w))*(4-('g'in w))/160.


Try it online!

Explanation:

Encodes the window as a sum of the ordinals of each char (without trailing g):

sum(map(ord,w[:(w+'g').find('g')]))

|      ->   124                /      ->   47
||     ->   248                //     ->   94
| |    ->   280                / /    ->   126
|+|    ->   291                /+/    ->   137
|++|   ->   334                /++/   ->   180
|+++|  ->   377                /+++/  ->   223
|r     ->   238                /r     ->   161
||r    ->   362                //r    ->   208
|f     ->   226                /f     ->   149
||f    ->   350                //f    ->   196


These are modded (%77%24%13), which gives values from 0 to 12):

sum(map(ord,w[:(w+'g').find('g')]))%77%24%13

|      ->   124   ->   10      /      ->   47    ->   10
||     ->   248   ->   4       //     ->   94    ->   4
| |    ->   280   ->   1       / /    ->   126   ->   1
|+|    ->   291   ->   12      /+/    ->   137   ->   12
|++|   ->   334   ->   2       /++/   ->   180   ->   2
|+++|  ->   377   ->   8       /+++/  ->   223   ->   8
|r     ->   238   ->   7       /r     ->   161   ->   7
||r    ->   362   ->   6       //r    ->   208   ->   6
|f     ->   226   ->   0       /f     ->   149   ->   0
||f    ->   350   ->   5       //f    ->   196   ->   5


The Ug values are multiplied by 20 and mapped to chars:

[0.7,    1.2,    1.45,   1.85,  2.0,  2.1,  2.7,  2.8,  3.4, 5.8]
[14,     24,     29,     37,    40,   42,   54,   56,   68,  116]
['\x0e', '\x18', '\x1d', '%',   '(',  '*',  '6',  '8',  'D', 't']


These chars are then ordered accordingly to the window-types, and padded with '0's. This new strign is used to look up the value based on the index.

'8%\x1806(*D\x0e0t0\x1d'#[sum(map(ord,w[:(w+'g').find('g')]))%77%24%13])


Lastly the given character is converted back into a number, and multiplied be the diagonal window and isolating curtain factors

*(2+('/'in w))*(4-('g'in w))/160.
equivalent to:
*2/2 or 3/2   * 4/4 or 3/4  /20


Saved

• -5 bytes, thanks to ovs
• -13 bytes, thanks to Lynn
• -5 bytes by a shorter way to remove the (trailing) g. – ovs Jun 11 '18 at 14:13
• w.strip('g') is even shorter. – Lynn Jun 11 '18 at 15:07
• + You can replace the \x sequences with actual low-ASCII chars for 99 bytes. – Lynn Jun 11 '18 at 15:13
• @Lynn I didn't know about the strip thing, thanks – TFeld Jun 12 '18 at 6:22

# Java (JDK 10), 110 bytes

s->"8%06(*D0t0".charAt(s.split("g")[0].chars().sum()%77%24%13)*(s.charAt(0)%2+2)*(s.endsWith("g")?3:4)/160d


Try it online!

## Credits

• -1 byte changing s.matches("/.*") to s.charAt(0)==47. – Kevin Cruijssen Jun 11 '18 at 13:14

# JavaScript (ES6), 111 109 bytes

s=>'_FQLKIe%f:}'.charCodeAt((g=c=>~-s.split(c).length)(/\W/)+3*g +6*gr+8*gf)*5%117/(gg?8:g|?6:4)*.3


Try it online!

### How?

We define the helper function g() as:

g = c => ~-s.split(c).length


split() takes either a string or a regular expression as input. Hence, so does g().

We define:

- N = g(/\W/) = number of non-alphanumeric characters
- S = g(' ')  = number of spaces
- R = g('r')  = number of "r"
- F = g('f')  = number of "f"
- G = g('g')  = number of "g"
- P = g('|')  = number of "|"


The formula n = N + 3S + 6R + 8F gives a unique identifier in [1..10] for all default values:

 input   | N | S | R | F | n
---------+---+---+---+---+----
"|"     | 1 | 0 | 0 | 0 | 1
"||"    | 2 | 0 | 0 | 0 | 2       NB: because 'g' characters are ignored in this formula
"| |"   | 3 | 1 | 0 | 0 | 6           and because a '/' is counted the same way as a '|',
"|+|"   | 3 | 0 | 0 | 0 | 3           the 2 other sets of inputs give the same results.
"|++|"  | 4 | 0 | 0 | 0 | 4
"|+++|" | 5 | 0 | 0 | 0 | 5
"|r"    | 1 | 0 | 1 | 0 | 7
"||r"   | 2 | 0 | 1 | 0 | 8
"|f"    | 1 | 0 | 0 | 1 | 9
"||f"   | 2 | 0 | 0 | 1 | 10


We use this identifier to pick the corresponding entry from the following 1-indexed array, which contains the default values multiplied by 20:

[116, 54, 29, 24, 14, 37, 68, 42, 56, 40]


This array is encoded as the string "FQLKIe%f:}". For each character, we multiply the ASCII code by 5 and apply a modulo 117:

 char | code | * 5 | mod 117
------+------+-----+---------
'F'  |   70 | 350 |   116
'Q'  |   81 | 405 |    54
'L'  |   76 | 380 |    29
'K'  |   75 | 375 |    24
'I'  |   73 | 365 |    14
'e'  |  101 | 505 |    37
'%'  |   37 | 185 |    68
'f'  |  102 | 510 |    42
':'  |   58 | 290 |    56
'}'  |  125 | 625 |    40


Finally, we divide this value by:

• 80 / 3 if G is non-zero
• 60 / 3 if P is non-zero
• 40 / 3 otherwise

# Excel & CSV, 194 bytes

,"=HLOOKUP(SUBSTITUTE(SUBSTITUTE(A1,""g"",),""/"",""|""),2:3,2,)*IF(CODE(A1)=47,1.5,1)*IF(RIGHT(A1,1)=""g"",0.75,1)"
|,||,| |,|+|,|++|,|+++|,|r,||r,|f,||f
5.8,2.7,1.85,1.45,1.2,0.7,3.4,2.1,2.8,2


Input entered before the first ,n and saved as CSV. When opened in Excel, Cell B1 displays result.

Sample usage:

/+++/g,"=HLOOKUP(SUBSTITUTE(SUBSTITUTE(A1,""g"",),""/"",""|""),2:3,2,)*IF(CODE(A1)=47,1.5,1)*IF(RIGHT(A1,1)=""g"",0.75,1)"
|,||,| |,|+|,|++|,|+++|,|r,||r,|f,||f
5.8,2.7,1.85,1.45,1.2,0.7,3.4,2.1,2.8,2


Opens as:

/+++/g  0.7875
|       ||      | |     |+|     |++|    |+++|   |r      ||r     |f      ||f
5.8     2.7     1.85    1.45    1.2     0.7     3.4     2.1     2.8     2