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

3.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69c5f3d787b1725d5f00c8b9 Challenge 255: Earth Day Cleanup Crew 29 challenge-255

--description--

Today is Earth Day. Given an array of items you cleaned up, return your total cleanup score based on the rules below.

Given items will be one of:

Item Base Value
"bottle" 10
"can" 6
"bag" 8
"tire" 35
"straw" 4
"cardboard" 3
"newspaper" 3
"shoe" 12
"electronics" 25
"battery" 18
"mattress" 38

A Rare item is represented as ["rare", value]. For example, ["rare", 80]. Rare items do not get a streak bonus.

  • Streak bonus: If the same item appears consecutively, it gets increasing bonus points.

    • First consecutive occurrence: base value
    • Second: base value + 1
    • Third: base value + 2
    • etc.
  • Fifth Item Multiplier: Every fifth item collected gets a multiplier.

    • Fifth item: *2
    • Tenth item: *3
    • etc.
  • Apply the multiplier after calculating any bonuses.

--hints--

get_cleanup_score(["bottle", "straw", "shoe", "battery"]) should return 44.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_cleanup_score(["bottle", "straw", "shoe", "battery"]), 44)`)
}})

get_cleanup_score(["electronics", "straw", "newspaper", "bottle", "bag"]) should return 58.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_cleanup_score(["electronics", "straw", "newspaper", "bottle", "bag"]), 58)`)
}})

get_cleanup_score(["shoe", "can", "can", "can", "bottle", "bottle", "straw", "straw", "straw"]) should return 79.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_cleanup_score(["shoe", "can", "can", "can", "bottle", "bottle", "straw", "straw", "straw"]), 79)`)
}})

get_cleanup_score(["mattress", ["rare", 80], "tire", "tire", "tire", ["rare", 95]]) should return 358.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_cleanup_score(["mattress", ["rare", 80], "tire", "tire", "tire", ["rare", 95]]), 358)`)
}})

get_cleanup_score(["bottle", "can", "can", "shoe", "shoe", ["rare", 56], "bottle", "bottle", "can", "can", "electronics", "bottle", ["rare", 48], "bottle", "can", "can", "can", "can", "can", "can", "can"]) should return 383.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_cleanup_score(["bottle", "can", "can", "shoe", "shoe", ["rare", 56], "bottle", "bottle", "can", "can", "electronics", "bottle", ["rare", 48], "bottle", "can", "can", "can", "can", "can", "can", "can"]), 383)`)
}})

--seed--

--seed-contents--

def get_cleanup_score(items):

    return items

--solutions--

def get_cleanup_score(items):
    values = {
        'bottle': 10, 'can': 6, 'bag': 8, 'tire': 35,
        'straw': 4, 'cardboard': 3, 'newspaper': 3,
        'shoe': 12, 'electronics': 25, 'battery': 18, 'mattress': 38
    }
    total = 0
    prev_item = None
    streak = 0
    for i, item in enumerate(items):
        is_rare = isinstance(item, list) and item[0] == 'rare'
        if is_rare:
            base = item[1]
            prev_item = None
            streak = 0
        else:
            base = values[item]
            streak = streak + 1 if item == prev_item else 0
            prev_item = item
        points = base if is_rare else base + streak
        if (i + 1) % 5 == 0:
            multiplier = (i + 1) // 5 + 1
            points *= multiplier
        total += points
    return total