diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2023-11-24 09:29:25 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2023-11-24 09:29:25 +0100 |
| commit | 73b1c7ec14481d7163a6f882f6450fa526813d2d (patch) | |
| tree | 5617d8f6692d322892be21d6486e0d2345a0b263 /challenge-244/lubos-kolouch/python/ch-2.py | |
| parent | 4acbea5c7345767570019fbbb9de3282d1a7e3cf (diff) | |
| download | perlweeklychallenge-club-73b1c7ec14481d7163a6f882f6450fa526813d2d.tar.gz perlweeklychallenge-club-73b1c7ec14481d7163a6f882f6450fa526813d2d.tar.bz2 perlweeklychallenge-club-73b1c7ec14481d7163a6f882f6450fa526813d2d.zip | |
feat(challenge-244/lubos-kolouch/perl,python,raku,blog): Challenge 244 LK Perl Python Raku blog
Diffstat (limited to 'challenge-244/lubos-kolouch/python/ch-2.py')
| -rw-r--r-- | challenge-244/lubos-kolouch/python/ch-2.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-244/lubos-kolouch/python/ch-2.py b/challenge-244/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..2968b5c1d8 --- /dev/null +++ b/challenge-244/lubos-kolouch/python/ch-2.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import unittest +from itertools import combinations +from typing import List + + +def group_hero_power(nums: list[int]) -> int: + total_power = 0 + for i in range(1, len(nums) + 1): + for combo in combinations(nums, i): + total_power += max(combo) ** 2 * min(combo) + return total_power + + +# Tests +class TestGroupHeroPower(unittest.TestCase): + def test_example(self): + self.assertEqual(group_hero_power([2, 1, 4]), 141) + + +if __name__ == "__main__": + unittest.main() |
