--- id: 699c8e045ee7cb94ed2322dd title: "Challenge 222: Equinox Shadows" challengeType: 29 dashedName: challenge-222 --- # --description-- Today is the equinox, when the sun is directly above the equator and perfectly overhead at noon. Given a time, determine the shadow cast by a 4-foot vertical pole. - The time will be a string in `"HH:MM"` 24-hour format (for example, `"15:00"` is 3pm). - You will only be given a time in 30 minute increments. Rules: - The sun rises at 6am directly `"east"`, and sets at 6pm directly `"west"`. - A shadow always points opposite the sun. - The shadow's length (in feet) is the number of hours away from noon, cubed. - There is no shadow before sunrise (before 6am), after sunset (6pm or later), or at noon. Return: - If a shadow exists, return `"(length)ft (direction)"`. For example, `"8ft west"`. - Otherwise, return `"No shadow"`. For example, given `"10:00"`, return `"8ft west"` because 10am is 2 hours from noon, so 23 = 8 feet, and the shadow points west because the sun is in the east at 10am. # --hints-- `get_shadow("10:00")` should return `"8ft west"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("10:00"), "8ft west")`) }}) ``` `get_shadow("15:00")` should return `"27ft east"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("15:00"), "27ft east")`) }}) ``` `get_shadow("12:00")` should return `"No shadow"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("12:00"), "No shadow")`) }}) ``` `get_shadow("17:30")` should return `"166.375ft east"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("17:30"), "166.375ft east")`) }}) ``` `get_shadow("05:00")` should return `"No shadow"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("05:00"), "No shadow")`) }}) ``` `get_shadow("06:00")` should return `"216ft west"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("06:00"), "216ft west")`) }}) ``` `get_shadow("18:00")` should return `"No shadow"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("18:00"), "No shadow")`) }}) ``` `get_shadow("07:30")` should return `"91.125ft west"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("07:30"), "91.125ft west")`) }}) ``` `get_shadow("00:00")` should return `"No shadow"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_shadow("00:00"), "No shadow")`) }}) ``` # --seed-- ## --seed-contents-- ```py def get_shadow(time): return time ``` # --solutions-- ```py def get_shadow(time): hour_str, minute_str = time.split(":") hours = int(hour_str) minutes = int(minute_str) time_in_hours = hours + minutes / 60 if time_in_hours < 6 or time_in_hours >= 18 or time_in_hours == 12: return "No shadow" hours_from_noon = abs(12 - time_in_hours) length = hours_from_noon ** 3 direction = "west" if time_in_hours < 12 else "east" return f"{length:g}ft {direction}" ```