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 UTFstream | |
{ | |
// Given a stream of UTF8 bytes, verify if it's valid | |
public static boolean validateUtf8(byte[] stream) { | |
boolean expectedBytes = 0; | |
for(int i = 0; i < stream.length; i++) { | |
if(expectedBytes > 0) { | |
// 10xx xxxx | |
if(stream[i] >= 0x80 && stream[i] <= 0xBF) { |
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
#!/usr/bin/env/python | |
grid = [' '] * 9 | |
curTurn = 'O' | |
#Print the X and O grid representing current game state | |
def displayBoard(board): | |
print "%s | %s | %s" % (board[0], board[1], board[2]) | |
print "---------" | |
print "%s | %s | %s" % (board[3], board[4], board[5]) |
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> | |
#include <vector> | |
using namespace std; | |
vector<string> emails; | |
void printVector() | |
{ | |
for(vector<string>::iterator it = emails.begin(); it != emails.end(); it++) |
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
#!/usr/bin/env/python | |
n = input('Please specify n for the nth fibonacci number: ') | |
#Base Case | |
fiblist = [0,1] | |
#Build list up until n | |
#+1 for off-by-one adjustment | |
while len(fiblist) < n+1: |
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
/************************************************************************ | |
Problem: | |
Given a number of an unspecified type, consider it's binary representation. | |
Given a configuration, make the necessary changes and find the resulting number. | |
Example: | |
typeX num = 0x55 |
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
// Pseudo code | |
// See original problem at https://gist.github.com/h2rashee/3b93f99ee78d16804740 | |
// Proposed by Mike Li | |
int order[] = [7,6,5,4,3,2,1,0]; | |
long x = 85; | |
int main() { | |
long y = 0; | |
for (int i = 0; i < order.length(); 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 <stdio.h> | |
#define BIT(x) (0x1 << x) | |
int set(int val, int pos) | |
{ | |
return (val |= BIT(pos)); | |
} | |
int unset(int val, int pos) |
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
import java.io.*; | |
import java.util.*; | |
class Coolness | |
{ | |
public static void main(String[] args) | |
{ | |
long num; | |
long num1 = Long.parseLong(args[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
/* | |
Problem 1: Given n, which is the length of a set starting from 'a', ex n = 3, set = { 'a', 'b', 'c' }, | |
return all possible permutations from the full set in dictionary order. | |
Ex input: n = 3 | |
Ex output: abc acb bac bca cab cba | |
1 2 3 4 5 6 | |
*/ | |
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
import fileinput | |
for line in fileinput.input(): | |
for word in line.split(): | |
print word + " ..." |
OlderNewer