This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns cljproxy | |
(:require [org.httpkit.client :as client] | |
[org.httpkit.sni-client] | |
[org.httpkit.server :as server])) | |
;; minimalist local proxy for development | |
;; Usage: TARGET=https://erdos.dev PORT=8081 bb core.clj | |
(def target-root (doto (System/getenv "TARGET") assert)) | |
(def port (doto (System/getenv "PORT") assert)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.zip :as zip]) | |
(def input (slurp "day18.txt")) | |
(def lines (vec (s/split-lines input))) | |
(def vecs (map read-string lines)) | |
(defn magnitude [x] | |
(if (number? x) | |
x | |
(+ (* 3 (magnitude (first x))) (* 2 (magnitude (second x)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns aoc21-day8-2 | |
(:require [clojure.core.logic :as logic])) | |
(def lines | |
(for [line (clojure.string/split-lines (slurp (clojure.java.io/resource "input.txt"))) | |
:let [[data test] (clojure.string/split line #" \| ")]] | |
[(clojure.string/split data #" ") (clojure.string/split test #" ")])) | |
(defn- segments [xs digit & segments] | |
(logic/all (logic/member1o digit xs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dev.erdos.algo; | |
import java.util.Arrays; | |
public class SuffixArray { | |
// O(n*logn) algorithm for constructing a suffix array. | |
// Original source: https://cp-algorithms.com/string/suffix-array.html#toc-tgt-3 | |
public static int[] calculateSuffixArray(char[] s) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; root | |
; / \ \ | |
; 1 [2 3] [4 5] | |
; /\ /\ | |
; 2 3 4 5 | |
(require '[clojure.zip :as zip]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [target (the-ns 'testable-namespace)] | |
(doseq [[k v] (ns-map target) | |
:when (and (var? v) (= target (.ns v)))] | |
(eval `(defn ~(symbol (str "-" k)) [~'& args#] (apply (deref ~v) args#))))) | |
;; Now if testable-namespace has a function valled fun1 | |
;; then i am able call -fun1 from the current namespace. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns hungarian | |
(:require [clojure.string])) | |
(defn- fmt [num] | |
(cond | |
(>= num 1000_000_000) | |
(let [szorzo (quot num 1000_000_000) | |
maradek (rem num 1000_000_000)] | |
(str (fmt szorzo) "milliárd" (when (pos? maradek) (str "-" (fmt maradek))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14"> | |
<w:body> | |
<w:p> | |
<w:pPr> | |
<w:pStyle w:val="Normal" /> | |
<w:rPr /> | |
</w:pPr> | |
<w:r> | |
<w:rPr /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn rpn [s] | |
(first (reduce (fn [[s1 s2 & ss :as stack] op] | |
(case op | |
+ (cons (+ s1 s2) ss) | |
- (cons (- s1 s2) ss) | |
* (cons (* s1 s2) ss) | |
/ (cons (/ s1 s2) ss) | |
, (cons op stack))) | |
() (read-string (str \( s \)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn filt [sequences] | |
(mapv (partial apply min-key peek) (vals (group-by count sequences)))) | |
(defn rfn [seqs x] | |
(filt (concat [[x]] seqs (for [cs seqs :when (> x (peek cs))] (conj cs x))))) | |
(defn longest-subseq [xs] | |
(apply max-key count [] (reduce rfn nil xs))) |
NewerOlder