Skip to content

Instantly share code, notes, and snippets.

View keshavsaharia's full-sized avatar

Keshav Saharia keshavsaharia

View GitHub Profile
import random
currentround = 0
rounds = 5
while currentround < rounds:
currentround + 1
answer = input("Select rock paper or scissors")
while answer != "rock" and answer != "paper" and answer != "scissors":
print "Bad answer"
@keshavsaharia
keshavsaharia / javagamedev.java
Last active August 29, 2015 13:58
Java Game Development
import Zen.*;
public class MyGame extends ZenGame {
// What code should happen when you click run?
public static void main(String[] args) {
MyGame game = new MyGame();
game.setName("My first game!");
game.setSize(800, 600);
game.run();
boolean view[7][7];
void setup() {
for (int i = 0 ; i < 14 ; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
for (int x = 0 ; x < 7 ; x++) {
for (int y = 0 ; y < 7 ; y++) {
package PhotoEditor;
import java.util.ArrayList;
public class Calculator {
public int calculate( String expression ) {
// Split it apart
String[] parts = splitApart(expression);
// Make two lists, one for numbers and another for operators
package PhotoEditor;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;
public class HashMapFun {
public static void main(String[] args) {
HashMap <String, Integer> wordFrequency = new HashMap <String, Integer> ();
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<style>
</style>
</head>
@keshavsaharia
keshavsaharia / Board.java
Last active August 29, 2015 14:08
TicTacToe board
public class Board {
private int[][] board;
private int current = 1;
private int empty = 9;
private int winner = 0;
/**
* Creates a new board.
*/
@keshavsaharia
keshavsaharia / Move.java
Created November 1, 2014 22:10
TicTacToe move class
public class Move {
private int x;
private int y;
public Move(int x, int y) {
this.x = x;
this.y = y;
}
@keshavsaharia
keshavsaharia / MarkTwainWroteIt.java
Created November 9, 2014 00:40
Mark Twain wrote it
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class MarkTwainWroteIt {
@keshavsaharia
keshavsaharia / conways
Created January 10, 2015 22:18
Conway's game of life utility functions
public static void step() {
boolean[][] newGrid = new boolean[50][50];
for (int x = 0 ; x < 50 ; x++) {
for (int y = 0 ; y < 50 ; y++) {
// Get how many neighbors this cell has.
int count = neighbors(x, y);
// 1. If the square is alive, but has less than two neighbors, it dies.
if (grid[x][y] == true && count < 2) {