a touch of unsubmitted golf
This commit is contained in:
parent
9e6354db43
commit
504b82a11b
3 changed files with 58 additions and 0 deletions
31
golf/distinct-chars-and-distinct-sizes.rkt
Normal file
31
golf/distinct-chars-and-distinct-sizes.rkt
Normal file
|
@ -0,0 +1,31 @@
|
|||
#lang racket
|
||||
; https://codegolf.stackexchange.com/questions/277441/distinct-characters-and-distinct-sizes?answertab=modifieddesc#tab-top
|
||||
|
||||
(define solve
|
||||
(λ(s'set-count,list->set)[apply +',s{set->list,(map length [group-by(λ(x)x){sort s <}])}])
|
||||
)
|
||||
|
||||
(define tests
|
||||
(hash
|
||||
"" 0
|
||||
"a" 2
|
||||
"aa" 3
|
||||
"aaa" 4
|
||||
"ab" 3
|
||||
"aab" 5
|
||||
"aaab" 6
|
||||
"abab" 4
|
||||
"abc" 4
|
||||
"abccbcb" 7
|
||||
"abaccac" 7
|
||||
"abcaaccac" 8
|
||||
"emmmmmmmm" 11
|
||||
"abcc" 6
|
||||
"aabcc" 6
|
||||
"aabbcc" 5))
|
||||
|
||||
(define ez-solve (compose solve bytes->list string->bytes/utf-8))
|
||||
|
||||
(require rackunit)
|
||||
(for ([(in out) tests])
|
||||
(check-equal? (ez-solve in) out in))
|
26
png.lisp
Normal file
26
png.lisp
Normal file
|
@ -0,0 +1,26 @@
|
|||
(ql:quickload "flexi-streams")
|
||||
|
||||
(defpackage :mehpng
|
||||
(:use :common-lisp :flexi-streams))
|
||||
(in-package :mehpng)
|
||||
(load "utils.lisp")
|
||||
|
||||
(defmacro hexbytes (&rest bytes)
|
||||
(map '(vector flex:octet) (λ (x) (reread "#x" x)) bytes))
|
||||
|
||||
(defparameter signature
|
||||
(hexbytes 89 50 4E 47 0D 0A 1A 0A))
|
||||
|
||||
(defgeneric bmatch (obj stream)
|
||||
(:documentation "attempt to match OBJ with the binary input stream STREAM.
|
||||
returns (VALUES BOOLEAN T)"))
|
||||
|
||||
(defmethod bmatch ((obj vector) stream)
|
||||
(values
|
||||
(block nil
|
||||
(loop for exp across signature
|
||||
for got = (read-byte stream nil nil)
|
||||
do (unless (and got (= exp got))
|
||||
(return)))
|
||||
t)
|
||||
nil))
|
|
@ -1,5 +1,6 @@
|
|||
;;; fun
|
||||
(proclaim '(inline last1 single append1 conc1))
|
||||
;; TODO: packagify and such
|
||||
|
||||
;; has a lot of goodies
|
||||
;; hey whaddayaknow, pg has a with-gensyms
|
||||
|
|
Loading…
Reference in a new issue