Task 1: Binary Date
"Date to Bits: Convert Each Component to Binary!"
Given an ISO-8601 date string (YYYY-MM-DD), convert each component to binary and join them with hyphens.
The Strategy: Parse the date into year, month, and day. Convert each to binary using sprintf('%b', ...) and join with hyphens.
Perl Implementation
sub binary_date ($date) {
($date) = $date_check->($date);
my ( $year, $month, $day ) = split /-/xms, $date;
return join q{-}, map { sprintf '%b', $_ + 0 } ( $year, $month, $day );
}
Python Implementation
def binary_date(date: str) -> str:
"""Convert ISO date components to binary, joined by hyphens."""
year, month, day = date.split("-")
return "-".join(bin(int(x))[2:] for x in (year, month, day))