okokokokokook

This commit is contained in:
bronku 2025-12-06 12:16:48 +01:00
parent 61dc873489
commit a47ef094af
9 changed files with 136 additions and 25 deletions

31
test/ruby/34.in Normal file
View file

@ -0,0 +1,31 @@
def count_words(text):
words = text.lower().split()
word_count = {}
for word in words:
word = word.strip('.,!?')
if word in word_count:
word_count[word] += 1
else:
word_count[word] = 1
return word_count
def find_most_common(word_count):
most_common = None
max_count = 0
for word, count in word_count.items():
if count > max_count:
most_common = word
max_count = count
return most_common, max_count
text = "Hello world hello there world hello"
counts = count_words(text)
common_word, frequency = find_most_common(counts)
print(f"Text: {text}")
print(f"Word counts: {counts}")
print(f"Most common: '{common_word}' appears {frequency} times")