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> ();
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
<!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 / rainbowsort.java
Created October 18, 2014 22:11
Rainbow Sort
import zen.core.Zen;
public class RainbowSort {
// Just some utility stuff, leave these variables alone.
private static boolean visualized = false;
private static int size = 500, step = 1;
private static int min = 0, max = 0;
private static int[] cache;
// Creates an array and visualizes the sorting of it.
@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;
}