This file contains 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
#include <iostream> | |
using namespace std; | |
#define N 4 | |
#define LEGAL 1 | |
#define ILLEGAL 0 | |
int counter = 0; | |
void count_paths(int x, int y, int n, int m, int array[N+2][N+2]){ | |
if(x == n && y == m){ |
This file contains 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 word_frequencies(string, k) | |
words = string.split(/\s/) # O(n) ## delimit by whitespace | |
max = 0 | |
min = Float::INFINITY | |
# create hash table for word --> frequency # | |
frequencies = words.inject(Hash.new(0)) do |hash,word| # O(n) | |
occurrences = hash[word] += 1 | |
max = occurrences if occurrences > max |
This file contains 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
#include <iostream> | |
using namespace std; | |
void print_combos(string s){ | |
int len = s.length(); | |
int iterations = 1 << len; //this makes iterations 2 to the power of length | |
for(int i = 0; i < iterations; i++){ |
This file contains 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
#include <iostream> | |
using namespace std; | |
void combos(string soFar, string rest, string full){ | |
if(rest == ""){ | |
int len = full.length(); | |
for(int i = 0, j = 0; i < len; i++) | |
{ | |
if(i == (int)(soFar[j] - '0')){ |
This file contains 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
public class NQueens | |
{ | |
final static int N = 12; | |
private static boolean possibleQueen(boolean[][] board, int row, int column){ | |
for(int i = 0; i < N; i++) | |
if(board[row][i] && i != column) | |
return false; | |
for(int i = 0; i < N; i++) |
This file contains 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
public class NQueens | |
{ | |
final static int N = 15; | |
private static boolean possibleQueen(boolean[][] board, int row, int column){ | |
for(int i = 0; i < N; i++) | |
if(board[row][i] && i != column) | |
return false; | |
for(int i = 0; i < N; i++) |
This file contains 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 find_pivot(array) | |
return -1 if array.empty? | |
left = 0 | |
right = array[1..-1].inject(0,:+) | |
for i in 0...array.length | |
return i if left == right | |
left += array[i] | |
right -= array[i+1] || 0 |
This file contains 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
class CreateProducts < ActiveRecord::Migration | |
def change | |
create_table :products do |t| | |
t.string :title | |
t.integer :seller_id | |
t.timestamps | |
end | |
end | |
end |
This file contains 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
#include <iomanip> | |
#include <iostream> | |
using namespace std; | |
void bottomLeft(int** array, int x1, int y1, int x2, int y2); | |
void topRight(int **array, int x1, int y1, int x2, int y2){ | |
for(int i = x1; i<= x2; i++){ | |
cout << array[y1][i] << " "; | |
} |
This file contains 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
class Integer | |
def printMySquare | |
print self * self | |
print "\t" | |
return self | |
end | |
end | |
puts 4.printMySquare |