// ============================================================================ // 076 — Text Histogram // ============================================================================ // Build a simple text-based histogram from data. // // Run: soma run 076_histogram.cell run // Expect: // Score Distribution: // 0-59: ** // 60-79: **** // 80-89: *** // 90-100: ***** cell Histogram { on run() { let scores = list(45, 72, 88, 95, 67, 93, 82, 55, 91, 78, 85, 96, 63, 90) // Count values in each bucket let low = 0 let mid = 0 let high = 0 let top = 0 for s in scores { if s < 60 { low = low + 1 } else { if s < 80 { mid = mid + 1 } else { if s < 90 { high = high + 1 } else { top = top + 1 } } } } print("Score Distribution:") let b1 = make_bar(low) let b2 = make_bar(mid) let b3 = make_bar(high) let b4 = make_bar(top) print("0-59: {b1}") print("60-79: {b2}") print("80-89: {b3}") print("90-100: {b4}") return "done" } // Build a bar of asterisks on make_bar(count: Int) { let bar = "" let i = 0 while i < count { bar += "*" i = i + 1 } return bar } }