Back to Blog

The Biggest Model Lost! Claude Coding Challenge EP04

Sandy LaneSandy Lane

Video: The Biggest Model Lost! Claude Coding Challenge EP04 by Taught by Celeste AI - AI Coding Coach

Watch full page →

The Biggest Model Lost! Claude Coding Challenge EP04

In this coding challenge, three Claude models—Opus, Sonnet, and Haiku—each generate a Python program that counts word frequencies in a sample text and displays the top five words as a horizontal bar chart using '#' characters. The programs are evaluated on eight criteria including correctness, output formatting, documentation, and code structure.

Code

def count_words(text):
  """
  Count the frequency of each word in the given text.
  Returns a dictionary mapping words to their counts.
  """
  words = text.lower().split()
  freq = {}
  for word in words:
    freq[word] = freq.get(word, 0) + 1
  return freq

def print_bar_chart(freq, top_n=5, max_width=40):
  """
  Print a horizontal bar chart of the top_n words by frequency.
  Bars are scaled to max_width using '#' characters.
  """
  # Sort words by frequency descending
  top_words = sorted(freq.items(), key=lambda x: x[1], reverse=True)[:top_n]
  max_count = top_words[0][1] if top_words else 1

  for word, count in top_words:
    bar_length = int(count / max_count * max_width)
    bar = '#' * bar_length
    print(f"{word:10} | {bar} ({count})")

def main():
  sample_text = (
    "In this coding challenge, we count word frequencies and "
    "display a horizontal bar chart of the top words using hash characters."
  )
  freq = count_words(sample_text)
  print_bar_chart(freq)

if __name__ == "__main__":
  main()

Key Points

  • Counting word frequencies involves normalizing text and tallying occurrences in a dictionary.
  • Displaying the top words as a horizontal bar chart helps visualize relative frequencies clearly.
  • Scaling bar lengths proportionally ensures the chart fits within a fixed width and is easy to read.
  • Including a docstring and a main guard improves code clarity and usability as a standalone script.
  • Different Claude models vary in code length, documentation, and output style, with Sonnet scoring highest overall.