Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C

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?

Name: Anonymous 2011-03-09 5:09

No.

Name: Anonymous 2011-03-09 5:11

Sure.

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])

Name: Anonymous 2011-03-09 5:40



(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!"))

Name: Anonymous 2011-03-09 5:45

>>4
s/x 1/x 0/

Name: Anonymous 2011-03-09 6:29

http://site.icu-project.org/

CharacterIterator

use the Lowercase property

Name: Anonymous 2011-03-09 6:36


$ grep -o '[a-z]' subject.txt | sort | uniq -c | sort -nr | head -n1
  44920 o


challenge: why does this use so much memory, how would you implement it on low memory systems?

Name: Anonymous 2011-03-09 6:40

>>7
Do you actually need the first sort?

Name: Anonymous 2011-03-09 6:55


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.


tl;dr yes

Name: Jhonson 2011-03-09 7:47

I'm just a beginner guys and can't understand shit what just happened in this thread

Name: Anonymous 2011-03-09 7:52

<v"one word: the forced indentation of code"0
 >:!#v_::"`"`\"z"`!* #v_$
 ^        p5\+1g5:-"a"<
v    <
>:"a"+,":",:5g"!"-.52*,1+:55*`#@_
!!!!!!!!!!!!!!!!!!!!!!!!!!

Name: Anonymous 2011-03-09 7:56

>>10
http://www.linuxliveusb.com/en/supported-linuxes (eg lubuntu)

make a super usb stick:
* boots linux
* runs linux from within windows
* does persistence

now add encryption etc...

Name: Anonymous 2011-03-09 8:01

>>11
VALID PERL CODE

Name: Anonymous 2011-03-09 8:11

>>10
I lol'd

Name: Anonymous 2011-03-09 8:39

>>11
Damn; that looks beautiful.

Name: Anonymous 2011-03-09 10:11

Eh, what the hell, have some dead dog too.
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'))

Name: Anonymous 2011-03-09 10:13

>>16
g ->
Not pointless? Terrible!

Name: Anonymous 2011-03-09 10:30

>>17
There. Not much of a point in doing this, though, since it's actually longer than the original.

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'))

Name: Anonymous 2011-03-09 10:48

>>18
Not much of a point in doing this, though,
That's why it's pointless.

Name: Anonymous 2011-03-09 10:50

>>19
I'm glad you saw what I did there.

Name: Anonymous 2011-03-09 11:09

>>15
Thanks. It's Befunge code. It doesn't sort the output, though.

Name: Anonymous 2011-03-09 12:27

>>7
U MENA cat "subject.txt" | grep -o '[a-z]' | sort | uniq -c | sort -nr | head -n1

Name: Anonymous 2011-03-09 12:35

>>4
abusing parameters
using do for anything
not writing a port iterator
reinventing hashtable-update!

Bad Scheme Programmer! Bad!

(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))

Name: Anonymous 2011-03-09 13:10

>>7

>>22

use `sort -u` FFS

Name: Anonymous 2011-03-09 13:20

>>23
abusing parameters
reinventing hashtable-update!

You're right, and I forgot about hash-update!.

using do for anything
not writing a port iterator

do is good and you know it.

Name: Anonymous 2011-03-09 13:49

>>3

Considered unpythonic and wrong.

Name: Anonymous 2011-03-09 14:47

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

Name: Anonymous 2011-03-09 14:48

Too easy and I believe we had this homework question before, and not only that, I even HELPED HIM!

Name: Anonymous 2011-03-09 14:53

>>27
Actually, you can replace swap with uncurry (flip (,)).

Name: Anonymous 2011-03-09 15:27

>>24
0/10

Name: Anonymous 2011-03-09 20:32

[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]

Name: Anonymous 2011-03-09 20:33

>>31
Shit, missed a few spaces.
[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]
Much better.

Don't change these.
Name: Email:
Entire Thread Thread List