Skip to content

Instantly share code, notes, and snippets.

View msszczep's full-sized avatar

Mitchell Szczepanczyk msszczep

View GitHub Profile
@msszczep
msszczep / subanagram2.pl
Created August 22, 2016 09:20
Subanagram Generator in Perl, version 2
#!/usr/bin/perl
# subanagram.pl
# This program receives as input an English word, and then
# delivers as output those English words which can be spelled with the
# letters in the input word.
# This script is Copyleft 2002 by Mitchell Szczepanczyk under the
# terms of the General Public License. Anyone is free to copy, modify,
@msszczep
msszczep / gist:56189ad10e9a1625178fa6ca4c7b5c85
Created November 13, 2016 16:01
Most Z's on a MLB Team Roster, Mathematica
Count[Characters@ToLowerCase@WolframAlpha["1971 texas rangers roster", {{"Result", 1},  "Plaintext"}, PodStates -> {"More"}], "z"];
MLBTeams = Drop[StringSplit[WolframAlpha["all major league baseball teams", {{"Result", 1},  "Plaintext"}, PodStates -> {"More", "More"}], {"(", "|"}], -1];
Grid[Take[Reverse@SortBy[First@Table[{team, yr, Count[Characters@ToLowerCase@WolframAlpha[ToString[yr] <>  " " <>  team <>  " roster", {{"Result", 1},  "Plaintext"}, PodStates -> {"More"}], "z"]}, {team, MLBTeams}, {yr, Range[1903, 2016]}], Last], 40], Frame-> All]
@msszczep
msszczep / faceoff.clj
Created June 10, 2017 15:51
Faceoff: America's favorite new card game -- in Clojure
(ns faceoff.core)
;; Make deck of cards, shuffle
;; loop:
;; does a player have zero cards?
;; if yes: game over
;; if no: faceoff
;; determine winner, winner gets cards added
;; if tie:
;; does 1 player have < 5 cards
@msszczep
msszczep / SubanagramGenerator.elm
Created September 4, 2017 19:54
Subanagram Generator in Elm
port module SubanagramGenerator exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App as App
import String exposing (toLower, toList)
import Ni2Dictionary
import Char exposing (isLower)
import Dict exposing (Dict)
| Surround parens | M-shift-9 |
| slurp right | ctrl-shift-right_arrow |
| barf right | ctrl-shift-left_arrow |
| slurf left | ctrl-shift-9 |
@msszczep
msszczep / gist:08dda9b2f4e1cdad2c00
Last active January 6, 2018 07:01
Subanagram Generator Draft in Clojure
(defn subanagram-generator [submitted-word]
(let [words (->> (slurp "/Users/msszczep1/Scripts/npr_puzzle_scripts/ni2.txt")
(clojure.string/split-lines))
submitted-word-freqs (merge
(zipmap "abcdefghijklmnopqrstuvwxyz" (repeat 26 0))
(frequencies (clojure.string/lower-case submitted-word)))]
(->> words
(filter (fn [word]
(let [lc-word (clojure.string/lower-case word)]
(every? #(<= ((frequencies lc-word) %)
@msszczep
msszczep / command_line_arguments.py
Last active February 1, 2018 16:06
Python Toolbox files (with some shell and Perl as well)
import sys
text = sys.argv[1]
print text
@msszczep
msszczep / scramboni.clj
Last active April 1, 2018 04:06
Scramboni in Clojure
(defn scramboni [rack]
"Find all playable words in a given Scrabble rack. Use asterisks for blanks."
(letfn [(every-but-n? [n pred coll]
(->> coll
(map (comp (fn [x] (if x :true :false)) pred))
frequencies
(merge {:false 0})
:false
(>= n)))]
(let [scrabble-words (->> "/home/mitchells/Desktop/npr_sunday_puzzle_solutions/resources/ospd3.txt"
@msszczep
msszczep / p112.clj
Created April 8, 2018 21:17
In progress solutions for 4Clojure problem #112
(defn p112-take1 [n d]
(letfn [(recast-to-vec [acc]
(let [num-left (count (re-seq #"\[" (apply str acc)))
num-right (count (re-seq #"\]" (apply str acc)))
updated-seq (concat acc (repeat (- num-left num-right) "]"))]
(read-string (apply str (interpose " " updated-seq)))))
(recast-to-int [s]
(Integer. (clojure.string/replace s #"[\]\[]" "")))]
(loop [acc-value 0
acc-structure []
@msszczep
msszczep / lton.clj
Created May 4, 2018 04:01
letters->numbers in Clojure
(defn letters->numbers [letters]
(let [letter-map (zipmap (map char "abcdefghijklmnopqrstuvwxyz")
(range 1 27))]
(->> letters
(map char)
(map letter-map)
(reduce +))))