Skip to content

Instantly share code, notes, and snippets.

View faethonm's full-sized avatar

Faethon faethonm

  • Loopup
  • San Francisco
View GitHub Profile
@faethonm
faethonm / QueueWith2Stacks
Created March 9, 2014 22:12
Queue Implementation using 2 stacks. Includes implementation of get minimum
import java.util.Collections;
import java.util.Stack;
public class QueueWith2Stacks {
private Stack<Integer> stack1 =null;
private Stack<Integer> stack2 =null;
private ArrayList<Integer> minList =null;
@faethonm
faethonm / lucky_strings.rb
Created December 18, 2015 17:42
A string is called lucky if no two consecutive characters are equal. How many lucky strings can you get by reordering letters in a given string *s*? *s* itself counts, too, if it is lucky. 1 <= length(*s*) <= 10 *s[i]* is in 'a'..'z' Example 1 input: "ab" output: 2 Two lucky strings - "ab" and "ba". Example 2 input: "aaab" output: 0 It's impossi…
def permutations(string)
permutations = string.split('').permutation.map(&:join).uniq
end
def lucky_strings(string)
permutations(string).select{|s| s.squeeze == s}.count
end
lucky_strings('ab') #=> 2
lucky_strings('aaab') #=> 0
@faethonm
faethonm / min_differences.rb
Created December 18, 2015 17:44
If X and Y are two strings of equal length N, then the difference between them is defined as the number of indices i where the i-th character of X and the i-th character of Y are different.
def distance(a,b)
a.split('').zip(b.split('')).select{|a,b| a!=b}.count
end
def min_differences(a,b)
distances = (0..(b.length - a.length)).map do |index|
b_sub = b[index...a.length+index]
distance(a,b_sub)
end
distances.min
@faethonm
faethonm / shippable.yml
Created April 27, 2016 06:22
An example shippable.yml that should enable any rails 5 project
language: ruby
rvm:
- 2.3.0
env:
- CI_REPORTS=shippable/testresults COVERAGE_REPORTS=shippable/codecoverage
before_install:
- sudo apt-get -y update
- sudo apt-get -y install libpq-dev
before_script:
# ensure the test output and coverage dirs are created
<div class="row ">
<div class="field">
<%= f.label :start_time %>
<%= f.time_select :start_time, ignore_date: true %>
</div>
</div>