I found an interesting problem on https://www.codewars.com/kata/59e1254d0863c7808d0000ef:
# Fourier transformations are hard. Fouriest transformations are harder.

This Kata is based on the SMBC Comic on fourier transformations.

A fourier transformation on a number is one that converts the number to a base in which it has more `4`s ( `10` in base `6` is `14`, which has `1` four as opposed to none, hence, fourier in base `6` ).

A number's fouriest transformation converts it to the base in which it has the most `4`s.  
For example: `35353` is the fouriest in base `6`: `431401`.

This kata requires you to create a method `fouriest` that takes a number and makes it the fouriest, telling us in which base this happened, as follows:

```python
fouriest(number) -> "{number} is the fouriest ({fouriest_representation}) in base {base}"
```

## Important notes

* For this kata we don't care about digits greater than `9` ( only `0` to `9` ), so we will represent all digits greater than `9` as `'x'`: `10` in base `11` is `'x'`, `119` in base `20` is `'5x'`, `118` in base `20` is also `'5x'`

* When a number has several fouriest representations, we want the one with the LOWEST base

```if:haskell,javascript
* Numbers below `9` will not be tested
```

```if:javascript
* A `BigNumber` library has been provided; documentation is [here](https://mikemcl.github.io/bignumber.js/)
```

## Examples

```python
"30 is the fouriest (42) in base 7"
"15 is the fouriest (14) in base 11"
```

I tried it in Python, but could not do it. Can you solve it?
def change_base(n, b):
    result = ''
    while n > 0:
        rem = n % b if n % b <=9 else 'x'
        result = str(rem) + result
        n //= b
    return result

def fouriest(n):
    bb, br = None, 0
    for i in range(2, n):
        res = list(change_base(n, i))
        nf = res.count('4')        
        if br >= len(res):
            break
        elif nf > br:
            br, bb = nf, i
            
    return f"{n} is the fouriest ({change_base(n, bb)}) in base {bb}"