Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -1,14 +1,15 @@
|
|||
(defun tally-letter-frequency-in-file ()
|
||||
(let ((alphabet "abcdefghijklmnopqrstuvwxyz")
|
||||
(current-letter)
|
||||
(count)
|
||||
(case-fold-search t)) ; ignores case
|
||||
(find-file "~/Documents/Elisp/MobyDick.txt") ; identify file to work with
|
||||
(while (>= (length alphabet) 1) ; as long as there is at least 1 letter left in alphabet
|
||||
(beginning-of-buffer)
|
||||
"Open a file and count the number of times each letter appears."
|
||||
(let ((alphabet "abcdefghijklmnopqrstuvwxyz") ; variable to hold letters we will be counting
|
||||
(current-letter) ; variable to hold current letter we will be counting
|
||||
(count) ; variable to count how many times current letter appears
|
||||
(case-fold-search t)) ; ignores case
|
||||
(find-file "~/Documents/Elisp/MobyDick.txt") ; open file in a buffer (or switch to buffer if file is already open)
|
||||
(while (>= (length alphabet) 1) ; as long as there is at least 1 letter left in alphabet
|
||||
(beginning-of-buffer) ; go to the beginning of the buffer
|
||||
(setq current-letter (substring alphabet 0 1)) ; set current-letter to first letter of alphabet
|
||||
(setq count (how-many current-letter)) ; count how many of this letter in file
|
||||
(end-of-buffer)
|
||||
(insert (format "\n%s%s - %7d" current-letter (upcase current-letter) count))
|
||||
(setq alphabet (substring alphabet 1 nil))) ; remove first letter from alphabet
|
||||
(setq count (how-many current-letter)) ; count how many of this letter in file
|
||||
(end-of-buffer) ; go to the end of the buffer
|
||||
(insert (format "\n%s%s - %7d" current-letter (upcase current-letter) count)) ; write how many times that letter appears
|
||||
(setq alphabet (substring alphabet 1 nil))) ; remove first letter from alphabet
|
||||
(insert "\n")))
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
val .countLetters = fn(.s) {
|
||||
for[=h{}] .s2 in split(replace(.s, RE/\P{L}/)) {
|
||||
_for[.s2; 0] += 1
|
||||
val countLetters = fn(s) {
|
||||
for[={:}] s2 in split(replace(s, RE/\P{L}/)) {
|
||||
_for[s2; 0] += 1
|
||||
}
|
||||
}
|
||||
|
||||
val .counts = .countLetters(readfile "./fuzz.txt")
|
||||
writeln join "\n", map fn(.k) $"\.k;: \.counts[.k];", keys .counts
|
||||
val counts = countLetters(readfile("./fuzz.txt"))
|
||||
writeln join("\n", map(fn(k) { "{{k}}: {{counts[k]}}" }, keys(counts)))
|
||||
|
|
|
|||
48
Task/Letter-frequency/Refal/letter-frequency.refal
Normal file
48
Task/Letter-frequency/Refal/letter-frequency.refal
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
$ENTRY Go {
|
||||
, <Arg 1>: {
|
||||
= <Prout 'No filename given'>;
|
||||
e.File, <ReadFile 1 e.File>: e.Text,
|
||||
<Tally e.Text>: e.Counts
|
||||
= <ShowLetterCounts (e.Counts) <Letters>>;
|
||||
};
|
||||
};
|
||||
|
||||
Letters {
|
||||
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
};
|
||||
|
||||
ShowLetterCounts {
|
||||
(e.T) = ;
|
||||
(e.T) s.L e.Ls,
|
||||
<Upper s.L>: s.UL, <Item (e.T) s.UL>: s.ULN,
|
||||
<Lower s.L>: s.LL, <Item (e.T) s.LL>: s.LLN,
|
||||
<+ s.ULN s.LLN>: s.Total
|
||||
= <Prout s.UL s.LL ': ' <Symb s.Total>>
|
||||
<ShowLetterCounts (e.T) e.Ls>;
|
||||
};
|
||||
|
||||
ReadFile {
|
||||
s.Chan e.Filename =
|
||||
<Open 'r' s.Chan e.Filename>
|
||||
<ReadFile (s.Chan)>;
|
||||
(s.Chan), <Get s.Chan>: {
|
||||
0 = <Close s.Chan>;
|
||||
e.Line = e.Line '\n' <ReadFile (s.Chan)>;
|
||||
};
|
||||
};
|
||||
|
||||
Tally {
|
||||
(e.T) = e.T;
|
||||
(e.T) s.X e.Xs = <Tally (<Inc (e.T) s.X>) e.Xs>;
|
||||
e.Xs = <Tally () e.Xs>;
|
||||
}
|
||||
|
||||
Inc {
|
||||
(e.1 (s.I s.N) e.2) s.I = e.1 (s.I <+ 1 s.N>) e.2;
|
||||
(e.X) s.I = e.X (s.I 1);
|
||||
};
|
||||
|
||||
Item {
|
||||
(e.1 (s.I s.N) e.2) s.I = s.N;
|
||||
(e.X) s.I = 0;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue