Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.8 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a19b1062d1b153d8ac76d73 Challenge 325: Lucky Number 29 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.

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

get_lucky_number("Olivia Lewis") should return 52.

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

get_lucky_number("James Wilson") should return 18.

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

get_lucky_number("Elizabeth Hernandez") should return 81.

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

get_lucky_number("Mike Walker") should return 32.

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

get_lucky_number("Chloe Perez") should return 13.

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

--seed--

--seed-contents--

def get_lucky_number(name):

    return name

--solutions--

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