John Lekberg


JUNTO Practice - "Hackerrank, "Detect the Domain Name""

Discussed on 2019-05-22.

Hackerrank, "Detect the Domain Name"


Solution - Daniel

import re
import sys

unique_re = re.compile(
    r"https?://(?:ww[w2]\.)?([a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)+)/?"
)

uniquedomains = set(
    unique_re.findall(sys.stdin.read())
)
print(";".join(sorted(uniquedomains)))

Solution - John

import sys
import re

domain_re = re.compile(
    r"""
    https?://
    (?:(?:www|ww2)\.)?
    ([a-zA-Z0-9-]+ (?: \. [a-zA-Z0-9-]+)+)
    """,
    re.VERBOSE,
)

candidates = set(
    domain_re.findall(sys.stdin.read())
)

print(";".join(sorted(candidates)))

Solution - Oscar

import re
import sys

domain_re = re.compile(
    r"https?://(?:www2?\.)?([a-z0-9\-]+(?:\.[a-z0-9\-]+)+)/?"
)

domains = set(
    domain_re.findall(
        sys.stdin.read().replace(
            "\n", " "
        )
    )
)

sys.stdout.write(
    ";".join(sorted(domains))
)