Skip to content

Instantly share code, notes, and snippets.

Remove consecutive duplicates

Write a function that takes a list of numbers and a limit, and returns a list where consecutive runs exceeding the limit have been removed entirely. Things to bear in mind:

- Non-consecutive duplicates are fine
- Consecutive duplicates exceeding the limit in the output are fine
- Memory and compute constraints (within reason) are not important, at least at first

Keybase proof

I hereby claim:

  • I am sw1nn on github.
  • I am sw1nn (https://keybase.io/sw1nn) on keybase.
  • I have a public key whose fingerprint is 52B8 782B 00A3 F617 AB0F 16F0 94DE DDF0 F460 D601

To claim this, I am signing this object:

@sw1nn
sw1nn / asciidoc.el
Last active September 1, 2022 13:45
(defvar-local sw1nn/adoc-remappings nil)
(defcustom sw1nn/adoc-hide-faces
'(markup-meta-face markup-meta-hide-face)
"faces to hide in adoc"
:group 'sw1nn
:type 'list
)
(defun sw1nn/adoc-hide-meta-characters ()
(ns regroup
(:require [clojure.string :as str]
[clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
))
(defn regroup [s n]
(let [patt (re-pattern (str "(?x:\n"
@sw1nn
sw1nn / flames_repl.clj
Created May 18, 2022 13:05
Repl fns to generate a flame graph. (Not super sophisticated!)
;; Assumes https://github.com/jstepien/flames available
;; requires http://riemann.io to be installed.
(def flames (atom nil))
(defn flames-start! []
;; We resolve explicitly here, to avoid warnings when not working
;; with flamegraphs
(if-not @flames
(let [config {:port 54321, :host "localhost"}]
(reset! flames ((requiring-resolve 'flames.core/start!) config))
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
(ns euler-fizz-buzz)
;; Inspired by http://philcrissman.net/posts/eulers-fizzbuzz/
(defn mod-pow [b e m] (long (.modPow (biginteger b) (biginteger e) (biginteger m))))
(defn fizz-buzz [] (map #({6 "Fizz" 10 "Buzz" 0 "FizzBuzz"} (mod-pow % 4 15) %) (range 1 100)))
;;https://en.wikipedia.org/wiki/Euler%27s_totient_function
;;https://oeis.org/A000010
(defn parse-rfc7231-accept-charset [s]
(->> s
(re-seq rfc-7231-re)
(keep #(vector (.group % "charset")
(some-> (.group % "weight")
Float/parseFloat)))
(into {})))
(defn re-seq
"Returns a lazy sequence of successive matches of pattern in string,
using java.util.regex.Matcher.find(), each such match processed with
re-groups."
{:added "1.0"
:static true}
[^java.util.regex.Pattern re s]
(let [m (re-matcher re s)]
((fn step []
(when (. m (find))
(def input ", \t, , , UTF-8;q=0.8,shift_JIS;q=0.4,a,b")
(def rfc-7231-re #"(?x)
(?:
\s* # OWS
(?<charset>\*|[\p{Alnum}!\#\$\%\&'\*\+\-\.\^_\`\|\~]+)
(?i:
;q=
(?<weight>0\.\d{1,3}|1\.0{1,3})
)?