Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
87
Task/Anagrams/Emacs-Lisp/anagrams-1.l
Normal file
87
Task/Anagrams/Emacs-Lisp/anagrams-1.l
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
(defun code-letters (str)
|
||||
"Sort STR into alphabetized list of individual letters."
|
||||
(sort (split-string str "" t) #'string<))
|
||||
|
||||
(defun code-letters-to-string (str)
|
||||
"Sort STR alphabetically and combine into one string."
|
||||
(apply #'concat (code-letters str)))
|
||||
|
||||
(defun remove-periods (str)
|
||||
"Remove periods (full stops) from STR."
|
||||
(string-replace "." "" str))
|
||||
|
||||
(defun list-pair (str)
|
||||
"Create paired list from STR, STR (unchanged) and alphabetized order of STR."
|
||||
;; Remove periods from alphabetized order to make regex matching easier
|
||||
(let ((letter-list (remove-periods (code-letters-to-string str))))
|
||||
(list letter-list str)))
|
||||
|
||||
(defun pair-up (words)
|
||||
"Make list of lists of paired words, one alphabetized one original."
|
||||
(let ((paired-list)
|
||||
(temp-pair))
|
||||
(dolist (word words)
|
||||
(setq temp-pair (list-pair word))
|
||||
(push temp-pair paired-list))
|
||||
paired-list))
|
||||
|
||||
(defun create-list-of-numbers (my-list)
|
||||
"Create list of numbers from MY-LIST."
|
||||
(let ((list-of-numbers))
|
||||
(dolist (one-pair my-list)
|
||||
(push (car one-pair) list-of-numbers))
|
||||
list-of-numbers))
|
||||
|
||||
(defun get-largest-number (my-list)
|
||||
"Find largest number in MY-LIST."
|
||||
(let ((list-of-numbers))
|
||||
(setq list-of-numbers (create-list-of-numbers my-list))
|
||||
(apply #'max list-of-numbers)))
|
||||
|
||||
(defun make-list-matching-words (coded-word-and-original number-and-code-pair)
|
||||
"List original words whose code matches code in NUMBER-AND-CODE-PAIR."
|
||||
(dolist (word-pair coded-word-and-original)
|
||||
;; test if coded word in CODED-WORD-AND-ORIGINAL matches
|
||||
;; coded word in NUMBER-AND-CODE-PAIR
|
||||
(when (string= (nth 0 word-pair) (nth 1 number-and-code-pair))
|
||||
;; insert the original word
|
||||
(insert (format "%s " (nth 1 word-pair)))))
|
||||
(insert "\n"))
|
||||
|
||||
(defun count-anagrams ()
|
||||
"Count the number of anagrams in file wordlist.txt"
|
||||
(let ((coded-word-and-original)
|
||||
(just-coded-words)
|
||||
(unique-coded-words)
|
||||
(count-and-code)
|
||||
(number-of-anagrams)
|
||||
(largest-number))
|
||||
;; Path below needs to be adapted to individual case
|
||||
(find-file "~/Documents/Elisp/wordlist.txt")
|
||||
(beginning-of-buffer)
|
||||
;; create list of lists of coded words and originals
|
||||
(setq coded-word-and-original (pair-up (split-string (buffer-string) "\n")))
|
||||
(find-file "temp-all-coded")
|
||||
(erase-buffer)
|
||||
(dolist (number-and-code-pair coded-word-and-original)
|
||||
;; make list of just the coded words
|
||||
(push (nth 0 number-and-code-pair) just-coded-words))
|
||||
(dolist (one-word just-coded-words)
|
||||
;; write list of coded words to buffer for later processing
|
||||
(insert (format "%s\n" one-word)))
|
||||
;; create a list of coded words with no repetitions
|
||||
(setq unique-coded-words (seq-uniq just-coded-words))
|
||||
(dolist (one-code unique-coded-words)
|
||||
(find-file "temp-all-coded")
|
||||
(beginning-of-buffer)
|
||||
;; count the number of times ONE-CODE appears in buffer
|
||||
(setq number-of-anagrams (how-many (format "^%s$" one-code)))
|
||||
(if (>= number-of-anagrams 1) ; eliminate "words" of zero length
|
||||
(push (list number-of-anagrams one-code) count-and-code)))
|
||||
(find-file "anagram-listing")
|
||||
(erase-buffer)
|
||||
(setq largest-number (get-largest-number count-and-code))
|
||||
(dolist (number-and-code-pair count-and-code)
|
||||
;; when the number in NUMBER-AND-CODE-PAIR = largest number of anagrams
|
||||
(when (= (nth 0 number-and-code-pair) largest-number)
|
||||
(make-list-matching-words coded-word-and-original number-and-code-pair)))))
|
||||
74
Task/Anagrams/Emacs-Lisp/anagrams-2.l
Normal file
74
Task/Anagrams/Emacs-Lisp/anagrams-2.l
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
(defun code-letters (str)
|
||||
"Sort STR into alphabetized list of individual letters."
|
||||
(sort (split-string str "" t) #'string<))
|
||||
|
||||
(defun code-letters-to-string (str)
|
||||
"Sort STR alphabetically and combine into one string."
|
||||
(apply #'concat (code-letters str)))
|
||||
|
||||
(defun add-to-hash (key value table)
|
||||
"If KEY exists, add VALUE to list of values.
|
||||
If KEY does not exist, associate value with KEY."
|
||||
(let ((current-values))
|
||||
(if (gethash key table)
|
||||
(progn
|
||||
(setq current-values (gethash key table))
|
||||
(setq current-values (push value current-values))
|
||||
(puthash key current-values table))
|
||||
(puthash key (list value) table))))
|
||||
|
||||
(defun create-list-of-numbers (hash-table)
|
||||
"Create a list of numbers from HASH-TABLE."
|
||||
(let ((current-number)
|
||||
(list-of-numbers))
|
||||
(setq list-of-numbers (list)) ; omit?
|
||||
(maphash (lambda (key value)
|
||||
(setq current-number (car (gethash key hash-table)))
|
||||
(push current-number list-of-numbers))
|
||||
hash-table)
|
||||
list-of-numbers))
|
||||
|
||||
(defun find-largest-number-in-hash (hash-table)
|
||||
"Find largest number in HASH-TABLE."
|
||||
(let ((list-of-numbers))
|
||||
(setq list-of-numbers (create-list-of-numbers hash-table))
|
||||
(apply #'max list-of-numbers)))
|
||||
|
||||
(defun find-longest-lists-of-anagrams (&optional file)
|
||||
"Find the set(s) of largest number of anagrams in file wordlist.txt"
|
||||
(let ((largest-number)
|
||||
(hash-key)
|
||||
(dictionary-table (make-hash-table :test 'equal)))
|
||||
;; Path and filename below needs to be adapted to individual case if
|
||||
;; FILE is *not* passed to this function
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (or file "~/Documents/Elisp/wordlist.txt"))
|
||||
(beginning-of-buffer)
|
||||
;; set up hash table with key and word(s)
|
||||
;; key = letters of word, but with letters in
|
||||
;; alphabetical order. Create list word(s) associated
|
||||
;; with key.
|
||||
(dolist (current-word (split-string (buffer-string) "\n"))
|
||||
(setq hash-key (code-letters-to-string current-word))
|
||||
(add-to-hash hash-key current-word dictionary-table))
|
||||
;; Count number of anagram words
|
||||
(maphash (lambda (key value)
|
||||
"Add number of anagram words to VALUE."
|
||||
(add-to-hash key (length (gethash key dictionary-table)) dictionary-table))
|
||||
dictionary-table)
|
||||
;; find the size of the largest list(s) of anagrams
|
||||
(setq largest-number (find-largest-number-in-hash dictionary-table)))
|
||||
;; set up empty buffer to show results
|
||||
(with-current-buffer (pop-to-buffer "anagram-listing")
|
||||
(erase-buffer)
|
||||
;; show results
|
||||
(maphash (lambda (key value)
|
||||
"Display longest lists of anagrams."
|
||||
(when (= largest-number (car (gethash key dictionary-table)))
|
||||
(mapc
|
||||
(lambda (element)
|
||||
"Insert ELEMENT followed by one space in buffer."
|
||||
(insert (format "%s " element)))
|
||||
(cdr (gethash key dictionary-table)))
|
||||
(insert "\n")))
|
||||
dictionary-table))))
|
||||
7
Task/Anagrams/PascalABC.NET/anagrams.pas
Normal file
7
Task/Anagrams/PascalABC.NET/anagrams.pas
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
begin
|
||||
var s := System.Net.WebClient.Create.DownloadString('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt');
|
||||
var words := s.Split;
|
||||
var groups := words.GroupBy(word -> word.Order.JoinToString);
|
||||
var maxCount := groups.Max(gr -> gr.Count);
|
||||
groups.Where(gr -> gr.Count = maxCount).PrintLines;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue