Name: Jhonson 2011-03-09 5:06
Can you help me write a program that finds what lowercase symbols are used most in a binary file?
f = open('<your file>', 'rb')
h = {}
for c in f.read():
if 'a' <= c <= 'z':
if c not in h: h[c] = 0
h[c] += 1
print sorted([(h[c], c) for c in h])
(define (hash-inc! h x (n 1))
(hash-set! h x (+ (hash-ref! h x 1) n)))
(define (|>>3
ONE WORD: THE FORCED INDENTATION OF CODE. THREAD OVER|
(in (current-input-port)))
(parameterize ((current-input-port in))
(do ((c (read-char) (read-char))
(h (make-hasheqv)))
((eof-object? c) h)
(when (char-lower-case? c)
(hash-inc! h c)))))
(|>>3
ONE WORD: THE FORCED INDENTATION OF CODE. THREAD OVER|
(open-input-string "hax my anus!"))
$ grep -o '[a-z]' subject.txt | sort | uniq -c | sort -nr | head -n1
44920 o
UNIQ(1) User Commands UNIQ(1)
NAME
uniq - report or omit repeated lines
SYNOPSIS
uniq [OPTION]... [INPUT [OUTPUT]]
DESCRIPTION
Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output).
With no options, matching lines are merged to the first occurrence.<v"one word: the forced indentation of code"0
>:!#v_::"`"`\"z"`!* #v_$
^ p5\+1g5:-"a"<
v <
>:"a"+,":",:5g"!"-.52*,1+:55*`#@_
!!!!!!!!!!!!!!!!!!!!!!!!!!
import Data.Ix
import Data.Ord
import Data.List
main =
interact $ intercalate "\n" . map (\g -> head g: ' ': show (length g)) . reverse
. sortBy (comparing length) . group . sort
. filter (inRange ('a','z'))
import Data.Ix
import Data.Ord
import Data.List
import Control.Arrow
main =
interact $ intercalate "\n" . map (uncurry (++) . ((:" ") *** show)). reverse
. sortBy (comparing snd) . map (head &&& length)
. group . sort . filter (inRange ('a','z'))
(define* (|>>3 ONE WORD: THE FORCED INDENTATION OF CODE. THREAD OVER|
(port (current-input-port)))
;; As always, I recommend Schemers use foof-loop
(let ((h (make-eqv-hashtable)))
(loop ((for char (in-port port)))
(when (char-lower-case? char)
(hashtable-update! h c add1 0)))
h))
import System.Environment (getArgs)
import System.IO (readFile)
import Data.List (sort)
import Data.Array (accumArray, assocs, inRange)
swap (x, y) = (y, x)
main = print =<< return . reverse . sort . map swap . assocs . accumArray (+) 0 ('a', 'z') . flip zip (repeat 1) . filter (inRange ('a', 'z')) . concat =<< mapM readFile =<< getArgs
[max(set(s),key=s.count)for s in[[ch for ch in open('asdf','rb').read()if ord('a')<= ord(ch)<= ord('z')]]][0]
[max(set(s),key=s.count)for s in[[ch for ch in open('asdf','rb').read()if ord('a')<=ord(ch)<=ord('z')]]][0]