---
id: 6a19b1062d1b153d8ac76d73
title: "Challenge 325: Lucky Number"
challengeType: 29
dashedName: challenge-325
---

# --description--

Given a string of a person's first and last name, calculate their lucky number using the following rules:

- First and last names are separated by a space
- Find the vowel and consonant count for each name
- Multiply the smaller vowel and consonant counts by each other and then by the length of the smaller name
- Do the same for the two larger counts and the larger name
- Subtract the smaller value from the larger one to get their lucky number

If the final value is zero (`0`), return `13`.

# --hints--

`get_lucky_number("John Doe")` should return `21`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_lucky_number("John Doe"), 21)`)
}})
```

`get_lucky_number("Olivia Lewis")` should return `52`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_lucky_number("Olivia Lewis"), 52)`)
}})
```

`get_lucky_number("James Wilson")` should return `18`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_lucky_number("James Wilson"), 18)`)
}})
```

`get_lucky_number("Elizabeth Hernandez")` should return `81`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_lucky_number("Elizabeth Hernandez"), 81)`)
}})
```

`get_lucky_number("Mike Walker")` should return `32`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_lucky_number("Mike Walker"), 32)`)
}})
```

`get_lucky_number("Chloe Perez")` should return `13`.

```js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_lucky_number("Chloe Perez"), 13)`)
}})
```

# --seed--

## --seed-contents--

```py
def get_lucky_number(name):

    return name
```

# --solutions--

```py
def get_lucky_number(name):
    vowels = "aeiouAEIOU"

    def name_stats(s):
        vowel_count = sum(1 for c in s if c in vowels)
        consonant_count = sum(1 for c in s if c.isalpha() and c not in vowels)
        return vowel_count, consonant_count, len(s)

    first, last = name.split(" ")
    first_vowels, first_consonants, first_len = name_stats(first)
    last_vowels, last_consonants, last_len = name_stats(last)

    larger_vowels = max(first_vowels, last_vowels)
    smaller_vowels = min(first_vowels, last_vowels)
    larger_consonants = max(first_consonants, last_consonants)
    smaller_consonants = min(first_consonants, last_consonants)
    larger_length = max(first_len, last_len)
    smaller_length = min(first_len, last_len)

    larger_value = larger_vowels * larger_consonants * larger_length
    smaller_value = smaller_vowels * smaller_consonants * smaller_length
    result = larger_value - smaller_value

    return 13 if result == 0 else result
```
