Created
June 22, 2020 18:59
-
-
Save curlpipe/ccb38640bbaf50b3717a877a2c579d47 to your computer and use it in GitHub Desktop.
My first proper nim project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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