Skip to content

Instantly share code, notes, and snippets.

View DataKinds's full-sized avatar
💖
new blog theme! check it out at https://datakinds.github.io/

Tyler DataKinds

💖
new blog theme! check it out at https://datakinds.github.io/
View GitHub Profile
NB. https://leetcode.com/problems/spiral-matrix/
]in=: 1+3 3$i.9
]in2 =: 1+3 4$i.12
walk=: 3 : 0 NB. call with `walk in`
i=. 0 0
d=. 0 NB. R D L U
m=. ($ y) $ 0
o=. a:
NB. https://leetcode.com/problems/container-with-most-water/
height=: {{ (i. # y),. y }} 1 8 6 2 5 4 8 3 7
NB. call as ({: height) metric {. height
NB. metric=: {{ (({: y) <. {: x) * | ({. x) - {. y }}
metric=: ({:@] <. {:@[) * [: | {.@[ - {.@]
f=:>./ @ , @ (metric"1 _"_ 1~) @ {{ (i. # y),. y }}
NB. here's a validator that only works with parens
NB. call it with c d '())()()()()()()())))))(())()(()'
d=: +/\@(=&'(' + -@=&')') NB. paren nesting depth
c=: {{ */ (0&= {: y),(=&0 +/ <&0 y) }} NB. nesting depth validator
NB. here's a validator that works with all the paren types given
NB. by the spec at https://leetcode.com/problems/valid-parentheses/description/
NB. call it with isvalid '[()]{(()[]{})}'
identify=: (3&| ,. (<&3)) @ ('({[)}]'&i.) NB. returns (paren type, 0=open/1=close)
NB. https://leetcode.com/problems/longest-common-prefix/description/
lcp=:> @ }: @ (([: ~: (1&= @ $ @ ~.)"1) <;.1 {."1)
lcp (|: @: >)'flower';'flof';'flower';'flighr'
@DataKinds
DataKinds / Gemfile
Last active May 20, 2019 09:48
Directed graph of TVTropes links
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "nokogiri"
@DataKinds
DataKinds / d.hs
Last active April 27, 2019 05:52
import Numeric
import Data.Ratio
data Op =
Plus Op Op
| Mul Op Op
| Pow Op Op
| Ln Op
| E Op
| Pi Op
@DataKinds
DataKinds / repl.p6
Last active April 6, 2019 07:45
perl6 better repl
#!/usr/bin/env perl6
use MONKEY;
use nqp;
module TREPL {
### STATIC DEFINITIONS ###
role Descriptive[Str $desc] {
has Str $.Desc = $desc;
}
{-# LANGUAGE ViewPatterns #-}
import Data.List
dropPieces :: [String] -> [String]
dropPieces (top:mid:rows) =
let willDrop = zipWith (\t m -> m == '-' && t /= '-') top mid
newTopRow = (\(t,m,w) -> if w then '-' else t) <$> (zip3 top mid willDrop)
newMidRow = (\(t,m,w) -> if w then t else m) <$> (zip3 top mid willDrop)
in
@DataKinds
DataKinds / genome.py
Last active October 5, 2020 08:21
CS homework
"""
Filename: genome.py
Author: Tyler
Purpose: Construct phylogenetic trees.
"""
# ;; Consider this my final hoorah before dropping my CS major.
# ;; https://xkcd.com/224/
code="""
@DataKinds
DataKinds / Functions.hs
Last active May 6, 2018 22:40
Scheme Boi
module Functions where
import SExpr
mathF :: (Integer -> Integer -> Integer) -> String -> Literal -> Literal -> Literal
mathF op s (LNum a) (LNum b) = LNum $ a `op` b
mathF _ s _ _ = error $ "Non number passed to " ++ s
addF :: Literal -> Literal -> Literal
addF a b = mathF (+) "+" a b