Skip to content

Instantly share code, notes, and snippets.

@jacks205
jacks205 / FileBrowser.java
Last active December 17, 2015 07:38
This is a File Browser program that can be used to locate, append, and display files, also has an option of creating a log file that updates and prints everything that is shown to the user. Option (4) is the one thing I can't get working at the moment but it doesn't crash the program.
View FileBrowser.java
import java.util.Scanner;
import java.io.*;
public class FileBrowser{
private static String logName;
public FileBrowser(){
logFile();
run();
@jacks205
jacks205 / Card.java
Last active December 17, 2015 07:38
A simulation of the card game "War." You enter the amount of games you want to simulate and it will give you: Average Wars, Average Double Wars, Average Battles, Max/Min Battles per game, Max/Min Wars per game, Max/Min Double Wars per game Uses LinkedLists to keep track of decks and exchanges of cards.
View Card.java
public class Card {
private int value; //didnt include suit because it messed with calculations (not important for the War game, but in the future I will try to include things like that for reuse-ability)
public Card(int i){
value = i;
}
public int getCardValue(){
return value;
@jacks205
jacks205 / Hangman.py
Created May 14, 2013 05:35
Hangman Simulation. Takes words out of a words.txt file.
View Hangman.py
import random;
# Repeatedly play the game of Hangman:
def play():
maxAllowedAttempts = 8;
print rulesDisplay(maxAllowedAttempts);
listOfWords = inputListOfWords('words.txt');
while (True):
playOneGame(maxAllowedAttempts, listOfWords);
ans = inputYesNo('\nPlay more? [Yes/No]: ');
@jacks205
jacks205 / StockTracker.py
Created May 14, 2013 05:38
Stock tracker that takes information from Yahoo Stocks and prints it to the screen, and then updates it continuously.
View StockTracker.py
import urllib;
# Stock checkup - Download and display a stock quote:
def checkup(symbol):
keywords = ['Symbol', 'Price', 'Open', 'Date', 'Time', 'Volume'];
stock = getStock(symbol, keywords);
display(stock);
# Display stock quote from a dictionary:
def display(stock):
@jacks205
jacks205 / ScoreFiler.py
Created May 14, 2013 05:39
Score Filer takes the scores of a test and returns the Average, Lowest, and Highest score(s) of the test.
View ScoreFiler.py
# Input student records from a file and return a list of records:
def read(fileName):
listOfStudents = [];
inFile = open(fileName, 'rU'); # read in "universal end-of-line" mode
for line in inFile:
# Strip unnecessary '\n' from right end:
line = line.rstrip('\n');
student = line.split(',');
# student = ['last-name', 'first-name', 'score']
listOfStudents.append(student);
@jacks205
jacks205 / StringFunctions.py
Created May 14, 2013 05:40
String Functions contains a group of random string methods.
View StringFunctions.py
# Generate a string with all letters from the English alphabet. :
def alphabet():
result = 'abcdefghijklmnopqrstuvwxyz';
return result + result.upper();
# Generate a randomly scrambled version of a string:
import random;
def scramble(string):
characterList = list(string);
random.shuffle(characterList);
@jacks205
jacks205 / Quiz1.py
Last active December 17, 2015 07:39
Quiz Handler gives out a quiz to the users, and then calculates the score and other information.
View Quiz1.py
[
{ #question 1
'type' : 'multiple-choice',
'text' :
'Who was the first U.S. President?\n' +
'(1) Abraham Lincoln\n' +
'(2) George Washington\n' +
'(3) John Lennon\n' +
'(4) Franklin Roosevelt',
@jacks205
jacks205 / SumOfPrimes.java
Created May 22, 2013 06:14
Project Euler #10 I made this method off the idea off of Project Euler's #10 of finding the sum of all primes up to two million, and made the method compatible with any limit you enter in the parameters. I started out doing the obvious thing and going through each number and finding if it was divisible by anything other than itself and 1, but ra…
View SumOfPrimes.java
public class SumOfPrimes {
public SumOfPrimes(){
System.out.println(sum(2000000)); //running the sum of primes limit to 2,000,000 [For Project Euler's answer]
}
public long sum(int limit){ //Project Euler wanted it for 2,000,000 but this method can do it for any limit given
boolean[] boolPrimes = new boolean[limit]; //initializing an array of booleans to the limit
boolPrimes[0] = false; //I know 0 isn't a prime
boolPrimes[1] = false;// I know 1 isn't a prime
@jacks205
jacks205 / GridProduct.java
Created May 23, 2013 07:44
Project Euler #11. What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20x20 grid? I made the program so any grid X by X (must be equal dimensions) could be used. I originally thought of using normal arrays, but it would just require more code, and someone could make a method …
View GridProduct.java
public class GridProduct {
private int[][] grid = new int[][]{
{8, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 8},
{49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00},
{81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65},
{52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91},
{22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80},
{24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50},
{32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70},
{67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21},
@jacks205
jacks205 / TriangleNumber.java
Created May 24, 2013 05:04
Project Euler #12. What is the value of the first triangle number to have over five hundred divisors? I felt that this problem was easier than the last two, but I got stuck on line 29 and had to look up online for help. I want to come back to this problem and make it smoother. It is about 1.1 seconds, but it should be able to run at like 50ms wi…
View TriangleNumber.java
public class TriangleNumber {
private int numDivisors;
public TriangleNumber(int numDivisors){ //takes in how many divisors
this.numDivisors = numDivisors;
}
public int firstOccurance(){ //returns the first occurance of the number of divisors you want the triangle number to have
int i = 1;