Skip to content

Instantly share code, notes, and snippets.

@curlpipe
Created June 22, 2020 18:59
Show Gist options
  • Save curlpipe/ccb38640bbaf50b3717a877a2c579d47 to your computer and use it in GitHub Desktop.
Save curlpipe/ccb38640bbaf50b3717a877a2c579d47 to your computer and use it in GitHub Desktop.
My first proper nim project
# Import things
import sequtils
import strutils
import regex
import os
# Read data from file
var data = paramStr(1).readFile.toLowerAscii
# Remove the parts of the file we don't want to count
data = data.replace(re"_“.*”_", "")
data = data.replace(re"\*\*.*\*\*", "")
data = data.replace(re"[^a-z0-9\s]", "")
# Clean up newlines
data = data.replace(re"(\n|\r)", " ").replace(re"[ ]{2,}", " ")
# Process and count
echo data.split(" ").filter(proc (x: string): bool = x != "").len
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment