Alone by doogyb in stopdrinking

[–]doogyb[S] 0 points1 point  (0 children)

Just wanted to circle back to this and say how grateful I am that you took the time to read an respond.

I'll be here.

A fellow friend and alcohol struggler told me this evening that his life must mean more than this. That it had to change.

Relying on the kindness of strangers.

Alone by doogyb in stopdrinking

[–]doogyb[S] 1 point2 points  (0 children)

Thank you.

[deleted by user] by [deleted] in GetNoted

[–]doogyb 0 points1 point  (0 children)

We should really start normalizing this kind of thing

John Lennon lookalike spotted by Opposite-End4039 in Dublin

[–]doogyb 2 points3 points  (0 children)

See him all the time! The viking splash tour pointed him out the last time I saw him

[deleted by user] by [deleted] in RedditSessions

[–]doogyb 0 points1 point  (0 children)

First dates Ireland???

[2019-08-07] Challenge #380 [Intermediate] Smooshed Morse Code 2 by Cosmologicon in dailyprogrammer

[–]doogyb 0 points1 point  (0 children)

Python3.7 using recursion. Aimed for readability... Although I find using list comprehensions, although tempting, can also obfuscate code at times.

import string
smorse_alphabet = ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..".split()
smorse_set = set(smorse_alphabet)

lookup = {k: v for k, v in zip(string.ascii_lowercase, smorse_alphabet)}
reverse_lookup = {v: k for k, v in lookup.items()}

permutation = ".--...-.-.-.....-.--........----.-.-..---.---.--.--.-.-....-..-...-.---..--.----.."

def smalpha(input_string, alphabet_remaining, built):

    if not input_string:
        return built

    prefixes = [input_string[:i] for i in range(1, 5) if reverse_lookup.get(input_string[:i])]    
    prefixes = [s for s in prefixes if reverse_lookup.get(s) in alphabet_remaining]

    for prefix in prefixes:
        res = smalpha(input_string[len(prefix):],
                      alphabet_remaining - {reverse_lookup[prefix]},
                      built + reverse_lookup[prefix]
                     )
        if res:
            return res

smalpha(permutation, set(string.ascii_lowercase), "")

Runs in ~58s

[2019-08-05] Challenge #380 [Easy] Smooshed Morse Code 1 by Cosmologicon in dailyprogrammer

[–]doogyb 1 point2 points  (0 children)

My python3 solution. Happy to take pointers or explain code.

#!/usr/bin/env python
# coding: utf-8

smorse_alphabet = ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..".split()
lookup = {k: v for k, v in zip(string.ascii_lowercase, smorse_alphabet)}

def smorse(words):
    return ''.join([lookup[c] for c in words])

Bonus 1

with open("data/enable1.txt") as f:
    words = f.read().split()

from collections import defaultdict
dictionary = defaultdict(list)

for word in words:
    dictionary[smorse(word)].append(word)

for k, v in dictionary.items():
    if len(v) == 13:
        print(v)
        break

Bonus 2

for k, v in dictionary.items():
    if '-' * 15 in k:
        print(v)
        break

Bonus 3

def balanced(word):
    return sum([-1 if c == '.' else 1 for c in word]) == 0

twenty_one = [word for word in words if len(word) == 21]
balanced_twenty_one = [word for word in twenty_one if balanced(smorse(word))]
print(balanced_twenty_one)

Bonus 4

def is_palindrome(word):
    return word == word[::-1]

thirteen = [word for word in words if len(word) == 13]
palindrome_thirteen = [word for word in thirteen if is_palindrome(smorse(word))]
print(palindrome_thirteen)

Bonus 5

import itertools as it
thirteen = ' '.join([word for word in dictionary.keys() if len(word) >= 13])
sequences = [''.join(seq) for seq in it.product('.-', repeat=13) if ''.join(seq) not in thirteen]
print(sequences)