Fuzion Logo
flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

countwords/simple_ctrie.fz


# Inspiration: https://github.com/benhoyt/countwords

main is
  counts := CTrie string u64

  for line := io.stdin.read_line, io.stdin.read_line while line.ok do
    line.val.split.map(t -> t.lower_case).for_each (token -> counts.add token ((counts.lookup token).get 0)+1)

  for count in (counts.items.sort x,y->x.values.1>y.values.1) do
    say "{count.values.0} {count.values.1}"

  unit