fork download
  1. (defun read-same-characters (&optional (stream *standard-input*)
  2. (eof-error-p t)
  3. eof-value)
  4. (loop for len upfrom 1
  5. for c = (read-char stream eof-error-p nil)
  6. while c
  7. collect c into chars
  8. while (eql c (peek-char nil stream nil nil))
  9. finally (return (if c
  10. (cons c len)
  11. eof-value))))
  12.  
  13. (defun hash-table-to-alist (hash-table)
  14. (loop for key being the hash-keys in hash-table using (hash-value val)
  15. collect (cons key val)))
  16.  
  17. (let* ((stats
  18. (with-open-stream (s (open "/dev/stdin" :direction :input))
  19. (loop with stats = (make-hash-table)
  20. for (char . len) = (read-same-characters s nil nil)
  21. while char
  22. for char-maxlen = (gethash char stats 0)
  23. when (> len char-maxlen)
  24. do (setf (gethash char stats) len)
  25. finally (return (hash-table-to-alist stats)))))
  26. (maxlen (apply #'max (mapcar (lambda (x) (cdr x)) stats)))
  27. (longest-repeated-characters
  28. (remove-if (complement (lambda (x) (eql (cdr x) maxlen)))
  29. stats)))
  30. (format t "~S~%" longest-repeated-characters))
  31.  
Success #stdin #stdout 0.01s 26004KB
stdin
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912
stdout
((#\1 . 3) (#\5 . 3))