Skip to content

Instantly share code, notes, and snippets.

View hickst's full-sized avatar

Tom Hicks hickst

View GitHub Profile
@hickst
hickst / baseConv.core.clj
Last active July 19, 2022 17:14
Using Clojure to play around with string representations/conversions of numbers in various bases.
(ns baseConv.core
(:require [clojure.string :as str])
(:gen-class)
)
(def digitChars "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
(defn powerOf [base]
"Returns a function which takes a number and raises the given base to that number.
The returned function returns its result as a Long unless the result exceeds
;; P01
(last [1 1 2 3 5 8])
;; P02
(defn penultimate [x]
(last (butlast x)) )
;; P03
(nth [1 1 2 3 5 8] 2)
;; the missing drop-nth, versions of which, similar to this, have been floating around the Clojure forum:
;;
(defn drop-nth [n coll]
(lazy-seq
(when-let [xs (seq coll)]
(concat (take (dec n) xs) (drop-nth n (drop n xs)))
)
)
)