The Weekly Challenge 332

Binary Dates & Letter Frequency!

Original Challenge Link

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))

Task 2: Odd Letters

"Frequency Check: Does Every Letter Appear an Odd Number of Times?"

Given an alphabetic string, determine whether every distinct letter appears an odd number of times.

The Strategy: Build a frequency map of lowercase letters. Check that every count is odd. Return true only if all counts pass.
Perl Implementation
sub odd_letters ($word) {
    ($word) = $string_check->($word);
    my %tally;
    $tally{$_}++ for split //, lc $word;
    my $all_odd = all { $_ % 2 == 1 } values %tally;
    return $all_odd ? 1 : 0;
}
Python Implementation
def odd_letters(word: str) -> bool:
    """Check if every distinct letter appears an odd number of times."""
    from collections import Counter
    return all(v % 2 == 1 for v in Counter(word.lower()).values())