Coding decimal numbers with factorials is a way of writing out numbers 
in a base system that depends on factorials, rather than powers of numbers.

In this system, the last digit is always `0` and is in base 0!. The digit before that is either `0 or 1` and is in base 1!.  The digit before that is either `0, 1, or 2` and is in base 2!, etc.
More generally, the nth-to-last digit is always `0, 1, 2, ..., n` and is in base n!.

Read more about it at: http://en.wikipedia.org/wiki/Factorial_number_system


## Example

The decimal number `463` is encoded as `"341010"`, because:

463 = 3×5! + 4×4! + 1×3! + 0×2! + 1×1! + 0×0!


If we are limited to digits `0..9`, the biggest number we can encode is 10!-1 (= 3628799). So we extend `0..9` with letters `A..Z`. With these 36 digits we can now encode numbers up to 36!-1 (= 3.72 × 10^(41))


## Task

We will need two functions. The first one will receive a decimal number and return a string with the factorial representation.

~~~if:java
**Note:** the input number is at most a long.
~~~

The second one will receive a string with a factorial representation and produce the decimal representation.

Given numbers will always be positive.

Difficulty: EASY
Starter code: def dec2FactString(nb):
	

Solutions:
from math import factorial
from string import digits, ascii_uppercase
DIGITS = digits + ascii_uppercase
FACTORIALS = [1, 1]
f = 1
for i in range(2, 36):
	f *= i
	FACTORIALS.append(f)

def dec2FactString(nb):
	ret = []
	for f in reversed(FACTORIALS):
		(d, nb) = divmod(nb, f)
		if d or ret:
			ret.append(DIGITS[d])
	return ''.join(ret)

def factString2Dec(string):
	return sum((DIGITS.index(d) * f for (d, f) in zip(reversed(string), FACTORIALS)))


from math import factorial
from itertools import dropwhile
DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
BASIS = [factorial(n) for n in range(len(DIGITS))]

def dec2FactString(nb):
	representation = []
	for b in reversed(BASIS):
		representation.append(DIGITS[nb // b])
		nb %= b
	return ''.join(dropwhile(lambda x: x == '0', representation))

def factString2Dec(string):
	return sum((BASIS[i] * DIGITS.index(d) for (i, d) in enumerate(reversed(string))))


base = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
fact = lambda n: fact(n - 1) * n if n else 1

def dec2FactString(nb, i=1):
	return dec2FactString(nb // i, i + 1) + base[nb % i] if nb else ''

def factString2Dec(string):
	return fact(len(string) - 1) * base.index(string[0]) + factString2Dec(string[1:]) if len(string) else 0


from string import ascii_uppercase as u
from math import factorial as f
d = list('0123456789') + list(u)
d_ = dict(map(lambda x: x[::-1], enumerate(d)))

def dec2FactString(n):
	(reminders, i) = ('', 1)
	while n:
		(n, b) = divmod(n, i)
		reminders += d[b]
		i += 1
	return reminders[::-1]
factString2Dec = lambda n: sum([d_[n[-(i + 1)]] * f(i) for i in range(len(n) - 1, -1, -1)])


from string import digits, ascii_uppercase
from math import factorial
BASE = digits + ascii_uppercase
FACT = [factorial(a) for a in range(36, -1, -1)]

def dec2FactString(nb):
	res = []
	for fact in FACT:
		(d, nb) = divmod(nb, fact)
		res.append(BASE[d])
	return ''.join(res).lstrip('0')

def factString2Dec(string):
	return sum((BASE.index(a) * FACT[c] for (c, a) in enumerate(string, -len(string))))


import itertools
import math
digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def dec2FactString(nb):
	result = []
	i = itertools.count(1)
	while nb:
		(nb, rem) = divmod(nb, next(i))
		result.append(digits[rem])
	return ''.join((i for i in result[::-1]))

def factString2Dec(string):
	return sum((digits.index(d) * math.factorial(i) for (d, i) in zip(string[::-1], itertools.count())))


import math
DIGITS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def get_digit(digit):
	return DIGITS[digit]

def dec2FactString(nb, f=0):
	if f == 0:
		return dec2FactString(nb, 1) + '0'
	elif nb == 0:
		return ''
	else:
		fact = math.factorial(f)
		digit = nb // fact % (f + 1)
		return dec2FactString(nb - digit * fact, f + 1) + get_digit(digit)

def factString2Dec(string):
	return sum((DIGITS.index(string[-(k + 1)]) * math.factorial(k) for k in range(0, len(string))))