I wanted to see how easy or hard it would be do try the old wordcount challenge in Nimrod, so I gave it a go.
It's not quite finished, because it doesn't tally the number of individual word occurrences, but I still found it fairly easy to get to this point.
Import os, strutils
proc QuickSort*(list: seq[string]): seq[string] =
if list.len == 0:
return @[]
var pivot = list[0]
var left,right: seq[string] = @[]
for value in list:
if value < pivot:
left.add(value)
elif value > pivot:
right.add(value)
result = QuickSort(left) & pivot & QuickSort(right)
if existsFile("kjv.txt"):
let src = readFile("kjv.txt")
let separators = {'\32', '(', ')', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '\39', '.', ',', ';', ':', '!', '?','\10'}
var x = src.tolower().split(separators)
echo "Total Number of Words: ", x.len
var list = x.QuickSort()
echo "Total Unique Words: ",list.len
var output = open("output.txt",fmWrite)
output.writeln("Total Number of Words: " & $x.len)
output.writeln("Total Unique Words: " & $list.len & "\n")
for x in list:
output.writeln(x)
output.close()
A.