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
| # @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 |
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
| 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 |
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
| #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 |
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
| # 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: |
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
| # 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 |