Advertisement
Guest User

Untitled

a guest
Nov 7th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.51 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local handle,content = fs.open(args[1],"r"),false
  4. content = handle.readAll()
  5. handle.close()
  6.  
  7. local chars = {}
  8.  
  9. for match in content:gmatch(".") do
  10.   if(not chars[match]) then
  11.     chars[match] = 1
  12.   else
  13.     chars[match] = chars[match]+1
  14.   end
  15. end
  16.  
  17. local sorted = {}
  18.  
  19. for k,v in pairs(chars) do
  20.   if(not sorted[v]) then
  21.     sorted[v] = {k}
  22.   else
  23.     table.insert(sorted[v],k)
  24.   end
  25. end
  26.  
  27. handle = fs.open("output","w")
  28. handle.write(textutils.serialize(sorted))
  29. handle.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement