코드로 우주평화

1208. A Strange Trip to the Market 본문

나는 이렇게 학습한다/Algorithm & SQL

1208. A Strange Trip to the Market

daco2020 2022. 12. 8. 23:28

You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to shift octaves by 8 pitches or something silly like that, it dawns on you that you have been watching the musician for some 10 odd minutes. You ask, "how much do people normally tip for something like this?" The artist looks up. "It's always gonna be about tree fiddy."

It was then that you realize the musician was a 400 foot tall beast from the paleolithic era! The Loch Ness Monster almost tricked you!

There are only 2 guaranteed ways to tell if you are speaking to The Loch Ness Monster: A) it is a 400 foot tall beast from the paleolithic era; B) it will ask you for tree fiddy.

Since Nessie is a master of disguise, the only way accurately tell is to look for the phrase "tree fiddy". Since you are tired of being grifted by this monster, the time has come to code a solution for finding The Loch Ness Monster. Note that the phrase can also be written as "3.50" or "three fifty".



Solution:

def is_lock_ness_monster(string):
    a = string.find("3.50")
    b = string.find("tree fiddy")
    c = string.find("three fifty")
    return sum([a,b,c]) != -3
def is_lock_ness_monster(s):
    return any(i in s for i in ('tree fiddy', 'three fifty', '3.50'))
import re
def is_lock_ness_monster(string):
    return bool(re.search(r'three fifty|tree fiddy|3\.50', string))
import re
def is_lock_ness_monster(string):
    return bool(re.findall("(?:tree fiddy|3\.50|three fifty)", string))


'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

1210. Bumps in the Road  (0) 2022.12.11
1209. Grasshopper - Combine strings  (0) 2022.12.09
1207. Vowel Count  (0) 2022.12.07
1206. Sum of positive  (0) 2022.12.06
1205. Sum of Cubes  (0) 2022.12.05