Skip to content

Instantly share code, notes, and snippets.

View bootler's full-sized avatar

Alex Boutilier bootler

View GitHub Profile
# @param {Integer[]} nums
# @return {Boolean}
def check(nums)
sorted = nums.sort_by { |num| num }
(0...nums.length).each { |i| return true if sorted.rotate(i) == nums }
false
end
def is_valid_bst(root)
return true if !root
if valid_bt?(root.left, root.val, true) && valid_bt?(root.right, root.val, false)
return true && is_valid_bst(root.left) && is_valid_bst(root.right)
end
false
end
def valid_bt?(node, ancestor_value, left)
return true if !node
#parentheses problem
def remove_outer_paren(str)
decomp(str).map { |prim| prim[1...-1] }.join
end
def decomp(str)
prim_decomp = []
ct_lb = 0
ct_rb = 0
@bootler
bootler / gist.rb
Last active December 13, 2021 07:16
# Problem 5:
# Write a method anti_prime? that accepts a number as an argument.
# The method should return true if the given number has more divisors than
# all positive numbers lower than the given number. For example, 24 is an
# anti-prime because it has more divisors (1,2,3,4,6,12,24) than any positive number
# lower than 24. 16 is not anti-prime it has fewer divisors (1,2,4,8,16) than 12 (1,2,3,4,6,12)
# and 12 is lower
# The efficiency of this method can be increased by observing the prime factorization
# of anti-primes, which always take the form: (x^a)(y^b)(z^c)... where:
@bootler
bootler / dns_update.sh
Created March 1, 2019 21:29
Sync dynamic IP to domain name using RESTful API calls
# cron job to sync up a dynamic IP to a domain name
# uses the LiveDNS REST API of gandi.net to update the zone file for our domain
# Grab current IP from dig
MYIP="$(dig @ns1-1.akamaitech.net ANY whoami.akamai.net +short)"
#openssl enc -d, or something similar to ensure security of the key
APIKEY="<YOUR_API_KEY>"
# targets the A record for the domain root (@), there is only one