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
| INVENTORY_CHANGE_DEBOUNCE_TIME = 1 -- seconds | |
| CHEST_COUNT = 2 | |
| VERBOSE = true | |
| local pp = (require "cc.pretty").pretty_print | |
| -- example item storage: | |
| -- { | |
| -- { | |
| -- count = 16, |
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
| math.randomseed(os.time()) | |
| local charset = "!@#$%^&*(){}|:\"\\[];',./=-_+" | |
| function string.random(length) | |
| if length > 0 then | |
| local idx = math.random(1, #charset) | |
| return string.random(length - 1) .. charset:sub(idx, idx) | |
| else | |
| return "" |
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; | |
| } |
NewerOlder