Skip to content

Instantly share code, notes, and snippets.

@Crenshinibon
Created April 16, 2013 07:47
Show Gist options
  • Save Crenshinibon/5394158 to your computer and use it in GitHub Desktop.
Save Crenshinibon/5394158 to your computer and use it in GitHub Desktop.
Find isogram in local file
fs = require 'fs'
filePath = process.argv[2]
start = new Date()
fs.readFile filePath, 'utf8', (error, data) ->
if not error
longest = []
word = []
isIso = true
for i in [0.. data.length]
l = data[i]?.toLowerCase()
if l and l.match /[a-z]/
isIso = isIso and l not in word
if isIso then word.push l
else
if isIso and word.length > longest.length
longest = word
word = []
isIso = true
console.log "Longest Isogram found: #{longest.reduce ((s, e) -> s + e), ''}"
console.log "in #{(new Date()).getTime() - start.getTime()} ms"
else
console.log error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment