Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems.

To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command you can take a look at the [wikipedia page](https://en.wikipedia.org/wiki/Chmod).

`chmod` provides two types of syntax that can be used for changing permissions. An absolute form using octal to denote which permissions bits are set e.g: 766.
Your goal in this kata is to define the octal you need to use in order to set yout permission correctly.

Here is the list of the permission you can set with the octal representation of this one.

- User
  - read (4)
  - write (2)
  - execute (1)
- Group
  - read (4)
  - write (2)
  - execute (1)
- Other
  - read (4)
  - write (2)
  - execute (1)
  
The method take a hash in argument this one can have a maximum of 3 keys (`owner`,`group`,`other`). Each key will have a 3 chars string to represent the permission, for example the string `rw-` say that the user want the permission `read`, `write` without the `execute`.
If a key is missing set the permission to `---`

**Note**: `chmod` allow you to set some special flags too (`setuid`, `setgid`, `sticky bit`) but to keep some simplicity for this kata we will ignore this one.

Difficulty: introductory

Starter code:

def chmod_calculator(perm):
	

Solutions:
def chmod_calculator(perm):
    perms = { "r": 4, "w": 2, "x": 1 }
    value = ""
    for permission in ["user", "group", "other"]:
        value += str(sum(perms.get(x, 0) for x in perm.get(permission, "")))
        
    return value

def chmod_calculator(perm):    
    return str(sum([wbin(perm[k]) * {"user":100, "group":10, "other":1}[k] for k in perm])).zfill(3)

def wbin(w):
    return int(w.translate(str.maketrans('rwx-', '1110')), 2)

def chmod_calculator(perm):
    dic = {'rwx':'7', 'rw-': '6', 'r-x':'5', 'r--':'4', '-wx':'3', '--x': '1', '-w-':'2', '---':'0', '0':'0'}
    if not perm:
        return '000'
    else:
        def m(r):
            return dic[perm.get(r, '0')]
        return  m('user') + m('group') + m('other')

from functools import partial

trans = str.maketrans("rwx-", "1110")
base2 = partial(int, base=2)

def chmod_calculator(perm):
    return "{}{}{}".format(*map(base2, (perm.get(k, '---').translate(trans) for k in ("user", "group", "other"))))

def chmod_calculator(p):
    d = {'r':4,'w':2,'x':1,'-':0}
    ob = {'user':'0','group':'0','other':'0'}
    for i,j in p.items():
        ob[i]=str(sum(map(lambda x:d[x],j)))
    return ''.join(ob.values())

TABLE  = str.maketrans('rwx-','1110')
FIELDS = 'user group other'.split()

def chmod_calculator(perm):
    return ''.join( str(int( perm.get(p,'---').translate(TABLE), 2 )) for p in FIELDS )

from functools import reduce
from operator import or_

SHIFTS = {'user': 6, 'group': 3, 'other': 0}

def chmod_calculator(perm):
    return format(reduce(or_, (
        (('r' in p) << 2 | ('w' in p) << 1 | ('x' in p)) << SHIFTS[user]
        for user, p in perm.items()
    ), 0), '03o')

def chmod_calculator(perm):
    oct = ""
    for j in ['user', 'group', 'other']:
        try:
            oct += str(sum([ 2 ** (2 - i[0]) for i in list(enumerate(perm[j], 0)) if i[1] != '-']))
        except:
            oct += "0"
    return oct

def chmod_calculator(perm):
    val = {"r": 4, "w": 2, "x": 1, "-": 0}
    scope = ("user", "group", "other")
    return "".join(str(sum(val[c] for c in perm.get(s, "---"))) for s in scope)

def chmod_calculator(perm):
    try:
        u = sum(2**(2-i)  for i, x in enumerate(perm['user']) if x != "-")
    except:
        u = 0
    try:
        g = sum(2**(2-i)  for i, x in enumerate(perm['group']) if x != "-")
    except:
        g = 0
    try:
        o = sum(2 ** (2 - i) for i, x in enumerate(perm['other']) if x != "-")
    except:
        o = 0
    return str(u) + str(g) +str(o)