ok... so I have been working on a stupid program that takes in characters one at a time and then counts then and then prints out how many characters there are and a graph.. but I don't know how to make my graph vertical... can any one /prog/ help a fool like me?
source:
#include <stdio.h>
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
int cols;
int max = 80;
int c;
int y;
int k;
int count[26];
for (int x = 0; x < 26; x++)
count[x] = 0;
while (! cin.eof())
{
if( isalpha ( c = tolower( cin.get() ) ) )
count [ c - 'a']++ ; // for everytime a certain value appears add 1 to that values number and when it shows up again add another 1 = 2
}
for (int i = 0; i < 26; i++)
printf("[%c] = %d\n" , i+'a' , count[i]);
for (int x=0; x<26; x++)
{
if (count[x] > 1)
{
cols = max * count[x] / count[25] ;
for (int y=0; y < cols; y++)
cout.put('-') ;
cout.put ('\n');
}
}
return 0;
}
Name:
Anonymous2007-08-16 3:02 ID:jf2er3YH
That's some expert spacing you've got there.
Name:
Anonymous2007-08-16 3:16 ID:zUDRSrwb
fuck you nigger
Name:
Anonymous2007-08-16 3:32 ID:jf2er3YH
Do you kiss your mother with that mouth? You probably do.
let maxcount = the maximum value contained in your count[] array
let graphheight = the desired height of your graph
let blockratio = maxcount / graphheight
loop counter y from graphheight down to 1
loop counter x from 0 to 25
if count[x] / blockratio is less than or equal to y
then print bar chart character
else print a space
end loop x
start a new line
end loop y
start a new line
print all characters from a to z
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
use lisp!
Name:
Anonymous2007-08-16 8:31 ID:cNnPpPGu
CL-USER> (let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
; in: LAMBDA NIL
; HANDLER-CASE
; --> BLOCK COMMON-LISP:LET TAGBODY RETURN-FROM
; ==>
; (COMMON-LISP:LET ((_ #:G12))
; (RETURN))
;
; caught STYLE-WARNING:
; The variable _ is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
Okay, In earlier times, toupper was a function-like preprocessor macro and was defined to work only on lower-case letters; it misbehaved if applied to digits, punctuation, or letters which were already upper-case. Similarly, tolower worked only on upper-case letters. Therefore, old code (or code written for wide portability) tends to call islower before toupper, and isupper before tolower. The C Standard, however, says that toupper and tolower must work correctly on all characters, i.e. characters which don't need changing are left alone.
>>32 then look at the beautify, readability and expressiveness of the lisp solution
It looks like a trainwreck of parentheses and meaningless 3-letter lowercase tokens arranged in no particular order LOOP X CAR MAP % NIL FOR LAMBDA FOLDR LOOP CHAR FILE PENIS PENIS PENIS))))))))))))). I'm sure someone ELSE could have written it elegantly in lisp, but your solution looks like utter shit.
(the C++ one is worse though)
Name:
Anonymous2007-08-16 10:21 ID:cNnPpPGu
>>33
You're so fucking stupid it makes me almost want to explain the joke to you..
#include <stdio.h>
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
int cols;
int max = 30;
int c;
int y;
int count[26];
for (int x = 0; x < 26; x++)
count[x] = 0;
while (! cin.eof())
{
if( isalpha ( c = tolower( cin.get() ) ) )
count [ c - 'a']++ ; // for everytime a certain value appears add 1 to that values number and when it shows up again add another 1 = 2
}
for (int i = 0; i < 26; i++)
printf("[%c] = %d\n" , i+'a' , count[i]);
cols = count[25] / max;
for (int y = max; y > 0; y--)
{
for (int x=0; x < 26; x++)
{
if (count[x] / cols >= y)
cout.put('^') ;
else
cout.put (' ');
}
cout.put('\n');
}
return 0;
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
Name:
Anonymous2007-08-16 12:31 ID:cNnPpPGu
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
Name:
Anonymous2007-08-16 12:31 ID:cNnPpPGu
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))
(let ((freq (make-array 256 :initial-element 0)))
(with-open-file (s "/usr/share/dict/words")
(loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
(error (_) (return)))))
((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
(loop for y from 0 to 15 do
(loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\ #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))