cschlisner / Random-Tools

A bunch of things I wrote to help solve problems. These are by no means optimal solutions - just what I was able to come up with on my own at the time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Random-Tools

To use it just make sure the tools directory is in the same directory as your program and import tools.*;

Factors.java

getFactors(int n) returns vector of all factors (non proper) of n.

getFactors(int n, true) returns vector of all proper divisors of n.

getPrimes(int n) returns array of all prime numbers <= n.

isPrime(int n) returns true if n is prime, else false.

List.java

binaryCount(int n) returns array of every binary number <= n.

factorial(int n) returns n!

permutations(int[] arr, lim) returns two dimensional array of all (or s if s != -1) permutations of objects in arr.

Print.java

s(T s) literally System.out.print(s)

sln(T s) literally System.out.println(s)

array(int[][] arrarr) prints 2d int array

array(int[] arr) prints int array

array(T[][] arrarr) prints 2d T array

array(T[] arr) prints T array

triangle(int[][] t, int[] path) prints a triangle of numbers t, with an index path path highlighted

Sort.java

swap(T[],int i, int j) returns a T array with elements i and j switched

swap(int[],int i, int j) returns an int array with elements i and j switched

size(int[] arr) returns sorted (by size) copy of arr

size(int[] base, int[] secondary) returns sorted (by size of base) copy of secondary

reverse(int[] arr) returns reversed copy of arr

maxVal(int[][] arrarr) returns largest value in 2d array arrarr

maxVal(int[] arr) returns largest value in array arr

sum(int[] arr) returns sum of elements in arr

alphabetical(String[] sarr) returns sorted (alphabetically) copy of sarr

compareWords(String a, String b) returns true if a is before b in alphabet

Timer.java

Timer() creates new timer object

start() sets a start time

stop() sets an end time

getTime() returns current elapsed time of timer (nanoseconds).

printTime() prints the elapsed time in nanoseconds and seconds

About

A bunch of things I wrote to help solve problems. These are by no means optimal solutions - just what I was able to come up with on my own at the time.


Languages

Language:Java 100.0%