diff --git a/README.md b/README.md index f5dd0c2..c6df21f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Feel free to explore, learn, and share your own approaches. - [ ] **3/18:** [Flight Vouchers](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-18-flight-vouchers) 🏖️ - [ ] **3/19:** [March Madness](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-19-march-madness) 🏀 - [ ] **3/20:** Cherry Blossoms 🌸 -- [ ] **3/21:** First Tweet 🐦 +- [x] **3/21:** [First Tweet](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-21-first-tweet) 🐦 - [ ] **3/22:** ❓❓❓ - [ ] **3/23:** ❓❓❓ - [ ] **3/24:** ❓❓❓ diff --git a/march-2026/3-20-first-tweet/first-tweet.py b/march-2026/3-20-first-tweet/first-tweet.py new file mode 100644 index 0000000..b3d8416 --- /dev/null +++ b/march-2026/3-20-first-tweet/first-tweet.py @@ -0,0 +1,29 @@ +def tweet_balance(tweet): + # first we split the tweet and initialize the char count + split_tweet = tweet.split(" ") + char_count = 0 + + # for each word in the split tweet + for word in split_tweet: + # if @ add 20 + if word.startswith("@"): + char_count += 20 + # if url add 23 + elif word.startswith("http://") or word.startswith("https://"): + char_count += 23 + else: + # for each character + for char in word: + # if ascii value at least 0x1F000 it means it's an emoji + if ord(char) >= 0x1F000: + char_count += 2 + else: + char_count += 1 + + # space after each word + char_count += 1 + + # no trailing space after last word + char_count -= 1 + + return (140 - char_count) \ No newline at end of file