In Sinatra, we have
'''ruby get "/posts/:id" do @post = ... erb :post end '''
/* Here is your chance to take over Socrates! | |
Spend 10 minutes on each of the following hacks to the socrates website. | |
Enter them in the console to make sure it works and then save | |
your results here. | |
Choose a new pair for each. Add your names to the section you complete. | |
*/ |
In Sinatra, we have
'''ruby get "/posts/:id" do @post = ... erb :post end '''
class Integer | |
def printMySquare | |
print self * self | |
print "\t" | |
return self | |
end | |
end | |
puts 4.printMySquare |
#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] << " "; | |
} |
class CreateProducts < ActiveRecord::Migration | |
def change | |
create_table :products do |t| | |
t.string :title | |
t.integer :seller_id | |
t.timestamps | |
end | |
end | |
end |
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 |
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++) |
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++) |
#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')){ |
#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++){ |