This file contains 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 y2023.d2) | |
(def input (->> "input/2023/2.txt" | |
(slurp))) | |
(def cube-limits {:red 12 , :green 13, :blue 14}) | |
(defn legal-game? [game] | |
(= cube-limits (merge-with max game cube-limits))) |
This file contains 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 scratches.gapful) | |
(comment | |
Challenge from https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-361-tip-trampoline-your-tail-recursion/ | |
Some numbers are gapful, some aren't. 100 is gapful because it has at least three digits and 100 is divisible by 10 ((str 1 0), the concatenation of the first and last digit). That's the definition of gapful: it has at least three digits and is divisible by the number formed by concatenating the first and last digits. | |
Create a function that takes a number and finds the closest gapful number. The function should return its argument if the argument itself is gapful. And if there are two gapful numbers equidistant to the argument, return the lower {one.}) | |
This file contains 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 fives.core | |
(:gen-class)) | |
(defn make-collection [size max] | |
(for [n (range size)] | |
(rand-int max))) | |
(defn square [n] | |
(* n n)) |
This file contains 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 filter-factors [primes unfiltered] | |
(let [new-prime (first unfiltered) | |
new-primes (conj primes new-prime) | |
new-unfiltered (filter #(< 0 (mod % new-prime)) unfiltered)] | |
(if (zero? (count new-unfiltered)) | |
new-primes | |
(recur new-primes new-unfiltered)))) | |
(defn soe [n] | |
(filter-factors [] (range 2 (inc n)))) |
This file contains 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 ebcdic-to-string | |
"takes an EBCDIC byte array and returns the corresponding string" | |
[bytearray] | |
(String. bytearray "cp500")) |
This file contains 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 jtcompojure.ASconn | |
(:require [clojure.java.jdbc :as j]) | |
(:gen-class) | |
(:import | |
(com.ibm.as400.access AS400ConnectionPool | |
CommandCall))) | |
;; I make a list of systems I am going to connnect to... | |
;; I can add keys for anything I would like that might be different amoungst system | |
(def syslist [{:name "SPOKANE" :iseries true :address "ipaddress" :dftlib "Libary"}] |
This file contains 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 sssmakespec.c960 | |
(:require [clojure.spec.alpha :as s] | |
[clojure.spec.gen.alpha :as gen])) | |
(def correct-pieces? #(= {\R 2, \K 1, \B 2, \Q 1, \N 2} (frequencies %))) ;; The right pieces and only the right peices | |
(def bishops-opposite? #(odd? (+ (.indexOf (vec %) \B) (.lastIndexOf (vec %) \B)))) ;; one bishop on even squares one on odd | |
(def K-between-R? #(< (.indexOf (vec %) \R) (.indexOf (vec %) \K) (.lastIndexOf (vec %) \R))) ;;King between the rooks | |
(s/def ::validc960 (s/and string? | |
correct-pieces? |
This file contains 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
;;This is untested off the top of my head -- but should give you the gist.. | |
;; use https://github.com/nervous-systems/cljs-lambda as a starter -- follow their lein build steps and then replace their core with something like this. | |
(ns alexalisten.core | |
(:require [cljs-lambda.util :as lambda] | |
[cljs-lambda.context :as ctx] | |
[cljs-lambda.macros :refer-macros [deflambda]])) | |
(deflambda alexa-listen [inputjson] | |
(let [jsonstring (js->clj inputjson) |
This file contains 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
function c960seq (){ | |
var emptySquares = new Set([1,2,3,4,5,6,7,8]); | |
var peiceMap = new Map() | |
var ob = (Math.floor(Math.random() * 4)+1)*2-1; | |
var eb = (Math.floor(Math.random() * 4)+1)*2; | |
function pickasquare(){ | |
do{ | |
tsq = (Math.floor(Math.random() * 8)+1); | |
} | |
while (emptySquares.has (tsq)===false); |
This file contains 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 c960) | |
(def pclist '(B B N N Q R K R)) | |
(defn c960 [](let [c960seq (shuffle (range 1 9)) | |
oddBish (first (filter odd? c960seq)) | |
evenBish (first (filter even? c960seq)) | |
goodseq (filterv #(not= oddBish %) | |
(filterv #(not= evenBish %)c960seq))] | |
(flatten (conj [evenBish oddBish] ;Bishop numbers go first | |
(take 3 goodseq) ; then Knights and Queens | |
(sort (take-last 3 goodseq)))))) ;then Rook King ;rook (sorted) |
NewerOlder