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 'pry' | |
| # stack ops | |
| def pop stack | |
| stack.pop | |
| end | |
| def push(stack, x) | |
| stack.push 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
| 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: |
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
| 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 }} |
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
| 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) |
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
| NB. https://leetcode.com/problems/longest-common-prefix/description/ | |
| lcp=:> @ }: @ (([: ~: (1&= @ $ @ ~.)"1) <;.1 {."1) | |
| lcp (|: @: >)'flower';'flof';'flower';'flighr' |
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
| # frozen_string_literal: true | |
| source "https://rubygems.org" | |
| git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
| gem "nokogiri" |
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
| import Numeric | |
| import Data.Ratio | |
| data Op = | |
| Plus Op Op | |
| | Mul Op Op | |
| | Pow Op Op | |
| | Ln Op | |
| | E Op | |
| | Pi Op |
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
| #!/usr/bin/env perl6 | |
| use MONKEY; | |
| use nqp; | |
| module TREPL { | |
| ### STATIC DEFINITIONS ### | |
| role Descriptive[Str $desc] { | |
| has Str $.Desc = $desc; | |
| } |
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
| {-# 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 |
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
| """ | |
| Filename: genome.py | |
| Author: Tyler | |
| Purpose: Construct phylogenetic trees. | |
| """ | |
| # ;; Consider this my final hoorah before dropping my CS major. | |
| # ;; https://xkcd.com/224/ | |
| code=""" |
NewerOlder