#!/usr/bin/env python3 # fair warning: this program was optimized for coding time import re su = "shintekiuntamed" def anagram(s): letters = re.findall('.', s) letters.sort() return ''.join(letters) su_an = anagram(su) su_len = len(su) # f = open('grease_fire.txt', 'r') # lines = f.readlines() lines = """13:34 start From my corner seat I saw Ken stumble in. He wasn't the smoothest guy around, but he had an undeniably astute mind. "Hi Ken," I muttered. "What's the word?" "Coffee," he said, grabbing a chair as the waitress filled our cups. Her skin haunted me. It was pale and smooth and damn near perfect. A night creature, I thought. Just like me. I glanced at Ken. "You think she's ever seen the sun?" "Damn it, Ike. You've got to focus." He was right. I could tell she was nothing but a mistake waiting to happen. A thin, nude mistake. Yeah, I was focused. "Why do you sing this damn tune, Ike? That dame's no good." "I mean it, Ken. I'd shut your trap about her if I were you." "Just trying to help, pal. I'll get my thanks in due time." I sank in the tedium of our familiar dance. Ken never understood my animal urges, but he had connections. "What've we got?" I asked. "I admit that the sunken treasure angle didn't pan out," he said, suddenly serious. "And I'm the first one to recognize that the seafaring hitmen idea stunk. But this time I'm on to something." "Still on the Minnow case?" I jabbed. "This is big, Ike. The skipper had black market ties in the U.K." "Damn. Really? You think it was an inside job?" "Had to be. I'm meeting my contact in the mine at dusk, so I'll know more tomorrow morning. But meanwhile I hear they're using the same money laundering guy we used in the tank. I'm guessing the evidence is in the DNA, Ike. Must be a giant operation. "Yeah, so big that somebody jumped ship thinking nobody'd notice." Ken nodded. "I wonder who mutinied?" "Then ask around." "Yeah... got the money?" "They wouldn't throw one thin dime at us, Ken. Not a lousy dime." "Those bastards. I swear to God..." "Leave God alone, you atheist." "Me? Unkind words, Ike" Ken laughed. "Talk like that might give us dementia. Think before you speak. But I wasn't listening: she was back. I grinned out one word: "Bacon." "You on the Atkins diet, hun?" "Me?" I respnded. "Nah. I just like good meat." "I might have what you want. What's your name?" Her banter didn't daunt me. "Ike hints," I replied. "Wouldn't you prefer Mike Hunt instead?" It was sure to be a memorable night. I sent Ken packing and sat back, enjoying the view. finished 13:47 """.splitlines() words = [] for line in lines: linewords = line.split() for word in linewords: word = word.lower() explode = re.findall('[a-z]+', word) word = ''.join(explode) if not len(word): continue words.append(word) words.reverse() candidate = [] candidate_len = 0 while 1: while candidate_len < su_len and words: word = words.pop() candidate_len += len(word) candidate.append(word) if candidate_len < su_len and not words: break while candidate_len > su_len: candidate_len -= len(candidate[0]) candidate = candidate[1:] if candidate_len == su_len: word = ''.join(candidate) if anagram(word) == su_an: print (word) candidate_len -= len(candidate[0]) candidate = candidate[1:]