diff --git a/README.md b/README.md index 526e9b1..11cc11e 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ -# Java \ No newline at end of file +# Java +Useful library for usaco and other purposes. +. Use releases when possible otherwise download usacotools.java. +# Release dates and more +Find release dates at https://javaarchive.github.io/Java/. Moved to https://github.com/javaarchive/Java/wiki diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..c419263 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file diff --git a/compilestandard.java b/compilestandard.java new file mode 100644 index 0000000..1b31cf1 --- /dev/null +++ b/compilestandard.java @@ -0,0 +1,57 @@ +import java.io.*; +import java.security.MessageDigest; +import java.security.*; +public class compilestandard extends usacotools { + public static String sha256(String input) throws NoSuchAlgorithmException { + MessageDigest mDigest = MessageDigest.getInstance("SHA-256"); + byte[] result = mDigest.digest(input.getBytes()); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < result.length; i++) { + sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); + } + + return sb.toString(); + } + public static void main(String[] args) throws IOException{ + // TODO Auto-generated method stub + BufferedReader f; + if(args.length==1) { + if(args[0].equals("eclipse")) { + f=mreader("src/usacotools.java"); + }else { + f=mreader("usacotools.java"); + } + + }else { + f=mreader("usacotools.java"); + } + + print("build"); + + String st; + String full=""; + + while ((st = f.readLine()) != null) { + full=full+st+"\n"; + } + String text=full.replace("if(!(lock)) {return null;}", ""); + text=text.replace("public abstract class usacotools","public abstract class utools"); + print(text); + PrintWriter pw=mwriter("utools.java"); + if(args[0].equals("eclipse")) { + pw=mwriter("src/utools.java"); + }else { + + } + pw.println(text); + pw.close(); + print("utools.java is the one you should copy into your code but usacotools is the one you should extend"); + try{ + print("utools.java SHA256: "+sha256(text)); + print("usacotools.java SHA256: "+sha256(full)); + }catch(Exception e) { + e.printStackTrace(); + } + + } +} diff --git a/debuggableapp.java b/debuggableapp.java new file mode 100644 index 0000000..1431b80 --- /dev/null +++ b/debuggableapp.java @@ -0,0 +1,70 @@ +import java.io.*; +import java.util.*; +class Var { + private Object object; + public Var() { + this.object=null; + } + public Var(Object o) { + this.object=o; + } + public void set(Object object) { this.object = object; } + public Object get() { return object; } +} +public class debuggableapp { + public static PrintWriter debug; + public static HashMap db=new HashMap(); + public static void setup() { + try { + debug=new PrintWriter(new BufferedWriter(new FileWriter("programdebug.info"))); + }catch(Exception e) { + e.printStackTrace(); + System.out.println("WARNING:Log file cannot be initliazed, redirecting to stdout! This may be a restrcited system!"); + debug=new PrintWriter(System.out); + + } + debug.println("Setup completed"); + } + public static void session() { + debug.println("Session started"); + System.out.println("Debug 1.0 Session\nPress enter to stop\nWarning timing this program will be messed up!"); + String text=">"; + Scanner sc=new Scanner(System.in); + while(!(text.equals(""))) { + System.out.print(">"); + text=sc.nextLine(); + if(db.containsKey(text)) { + show(db.get(text)); + } + } + } + public static void show(Var x) { + debug.println(x.getClass()); + if(x.getClass().getName().contains((CharSequence) "List")) { + System.out.println("WARNING this is a list"); + debug.println("WARNING this is a list"); + } + System.out.println(x.get()); + } + public static void add(Var x,String friendlyname) { + db.put(friendlyname, x); + } + public static void set(Var x,String friendlyname) { + db.put(friendlyname, x); + + + + } + public static void main(String[] args) { + setup(); + String x="test"; + Var a=new Var("Testing"); + add(a,x); + session(); + a.set("sync test"); + Var a2=new Var(new ArrayList()); + add(a2,"arr"); + session(); + } + +} diff --git a/index.htm b/index.htm new file mode 100644 index 0000000..393a061 --- /dev/null +++ b/index.htm @@ -0,0 +1,27 @@ + + + + + + + + + + +Code Speed + + + + + + + +

Which runs faster on java

+ + + + + + diff --git a/usacotools.java b/usacotools.java index 2edc111..f7ed572 100644 --- a/usacotools.java +++ b/usacotools.java @@ -1,6 +1,24 @@ - +/* + * USACOTOOLS-Official version + * This is the official version. + * + */ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Queue; +import java.util.Scanner; +import java.util.Set; import java.util.*; -import java.io.*; +import java.util.regex.*; public abstract class usacotools { public static final String ANSI_RESET = "\u001B[0m"; public static final String ANSI_BLACK = "\u001B[30m"; @@ -15,6 +33,12 @@ public abstract class usacotools { public static ArrayList console=new ArrayList(); public static String error="Error"; public static int debugcode=-1; + public static boolean DEBUG=false; + public static boolean lock; + public static boolean IO=true; + public static void blockio() { + IO=false; + } public static boolean isrect(int[][] map,int x,int y) { int cachedsize=-1; int cachey=-1; @@ -34,6 +58,38 @@ public static boolean isrect(int[][] map,int x,int y) { } return true; } + public static Set sclones(Set k) { + return (new HashSet(k)); + } + public static Set sclone(Set k) { + + return (new HashSet(k)); + } + public static Set sclonel(Set k) { + return (new HashSet(k)); + } + public static boolean smartequals(int[] a,int[] b) { + if(a.length!=b.length) { + return false; + } + for(int i=0;i arr) { + if(!(lock)) {return null;} int[] stuff=new int[arr.size()]; for(int i=0;i arr) { } public static String[] toArrays(ArrayList arr) { + if(!(lock)) {return null;} String[] stuff=new String[arr.size()]; for(int i=0;i fibmem=new ArrayList(); + public static long ffib(long n){ + /* + * Fibonnaci implemented with DP + */ + if(n<=1) { + return n; + } + + if(fibmem.size()>n) { + return fibmem.get((int) n-1)+fibmem.get((int) n-2); + }else { + fibmem.add(ffib(n-1)+ffib(n-2)); + return fibmem.get((int) n); + } + } + public static void print() { + System.out.println(); + } + public static void setupfib() { + fibmem.add((long) 0);fibmem.add((long)1);fibmem.add((long)1);fibmem.add((long)2); + } + public static void show2Darr(int[][] a) { + //Print out a 2D array for you + for(int[] b:a) { + for(int c:b) { + print(c+" ",""); + } + print(); + + } + } + public static void showarr(int[] a) { + //Print out a array for you + for(int x:a) {print(x+" ");} + } + public static int[][] dpcache; + public static int ks(int W,int[] wt,int[] val,int n) { + int result; + if(dpcache[n][W]!=0) {return dpcache[n][W];} + if(n==0||W==0) { + result=0; + }else if(wt[n-1]>W) { + result=ks(W,wt,val,n-1); + + + + }else { + result=Math.max(val[n-1]+ks(W-wt[n-1],wt,val,n-1),ks(W,wt,val,n-1)); + } + dpcache[n][W]=result; + return result; + } + public static void kssetup(int n,int W) { + dpcache=new int[n+1][W+1]; + } + public static int count(int[] arr) { /* - * Short demo of stuff - * Making an error would also demo error reporting - * + * Number of groups of 1s + * Modify for other purposes if needed + * Example + * 1111000111 + * Returns 2 * */ - System.out.println("Running demo"); - Scanner sc=getsysscan(); - print("Welcome to the demo\nYou have many choices \n1} Run help \n2} Check for a update \n3}Run demo to see features"); - print(">",""); - int val; - try { - val=sc.nextInt(); - }catch(Exception e) { - print("Oops that did not go well please rerun and choose a INTEGER"); - val=-1; - report(e); - print("How about we test erro reporting"); - console(); + boolean b=false;int c=0;int temp; + for(int i=0;i speedqueue=new LinkedList(); + public static long prevtime=0; + public static void $1() { + long time=System.currentTimeMillis(); + if(prevtime==0) { + prevtime=time; + }else { + speedqueue.add((long) abs(time-prevtime)); + prevtime=0; } } + public static long $r() { + return speedqueue.poll().longValue(); + } + public static boolean $r$smatch(String a,String b) { + return Pattern.matches(a, b); + } + public static boolean $r$match(String a,String b) throws Exception{ + //WIP + throw new Exception("Not implemented"); + } } diff --git a/utools.java b/utools.java new file mode 100644 index 0000000..83bfe5f --- /dev/null +++ b/utools.java @@ -0,0 +1,494 @@ +/* + * USACOTOOLS-Official version + * This is the official version. + * + */ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Queue; +import java.util.Scanner; +import java.util.Set; +import java.util.*; +import java.util.regex.*; +public abstract class utools { + public static final String ANSI_RESET = "\u001B[0m"; + public static final String ANSI_BLACK = "\u001B[30m"; + public static final String ANSI_RED = "\u001B[31m"; + public static final String ANSI_GREEN = "\u001B[32m"; + public static final String ANSI_YELLOW = "\u001B[33m"; + public static final String ANSI_BLUE = "\u001B[34m"; + public static final String ANSI_PURPLE = "\u001B[35m"; + public static final String ANSI_CYAN = "\u001B[36m"; + public static final String ANSI_WHITE = "\u001B[37m"; + public static int ERRORS=0; + public static ArrayList console=new ArrayList(); + public static String error="Error"; + public static int debugcode=-1; + public static boolean DEBUG=false; + public static boolean lock; + public static boolean IO=true; + public static void blockio() { + IO=false; + } + public static boolean isrect(int[][] map,int x,int y) { + int cachedsize=-1; + int cachey=-1; + for(int i=x;icachedsize) { + return false; + } + for(int j=y;jcachey) { + return false; + } + } + } + return true; + } + public static Set sclones(Set k) { + return (new HashSet(k)); + } + public static Set sclone(Set k) { + + return (new HashSet(k)); + } + public static Set sclonel(Set k) { + return (new HashSet(k)); + } + public static boolean smartequals(int[] a,int[] b) { + if(a.length!=b.length) { + return false; + } + for(int i=0;i touching(int[][] map,int x,int y){ + ArrayList out=new ArrayList(); + try { + out.add(map[x-1][y]); + }catch(Exception e) { + + } + try { + out.add(map[x+1][y]); + }catch(Exception e) { + + } + try { + out.add(map[x][y-1]); + }catch(Exception e) { + + } + try { + out.add(map[x][y+1]); + }catch(Exception e) { + + } + return out; + + } + public static String repeat(int count, String with) { + return new String(new char[count]).replace("\0", with); + } + public static String changen(int position, char ch, String str){ + char[] charArray = str.toCharArray(); + charArray[position] = ch; + return new String(charArray); + } + public static BufferedReader mreader(String filen) throws IOException { + //Make a reader + return new BufferedReader(new FileReader(filen)); + } + public static PrintWriter mwriter(String filen) throws IOException { + return new PrintWriter(new BufferedWriter(new FileWriter(filen))); + } + public static Scanner getsysscan() { + return new Scanner(System.in); + } + public static int binarySearch(int arr[], int l, int r, int x) + { + /* + * Binary Search + * + */ + if (r>=l) + { + int mid = l + (r - l)/2; + + + if (arr[mid] == x) + return mid; + + if (arr[mid] > x) + return binarySearch(arr, l, mid-1, x); + + return binarySearch(arr, mid+1, r, x); + } + + + return -1; + } + public static int[][] copy2D(int[][] a){ + + int[][] b=new int[a.length][]; + for(int i=0;i arr) { + + int[] stuff=new int[arr.size()]; + for(int i=0;i arr) { + + String[] stuff=new String[arr.size()]; + for(int i=0;i fibmem=new ArrayList(); + public static long ffib(long n){ + /* + * Fibonnaci implemented with DP + */ + if(n<=1) { + return n; + } + + if(fibmem.size()>n) { + return fibmem.get((int) n-1)+fibmem.get((int) n-2); + }else { + fibmem.add(ffib(n-1)+ffib(n-2)); + return fibmem.get((int) n); + } + } + public static void print() { + System.out.println(); + } + public static void setupfib() { + fibmem.add((long) 0);fibmem.add((long)1);fibmem.add((long)1);fibmem.add((long)2); + } + public static void show2Darr(int[][] a) { + //Print out a 2D array for you + for(int[] b:a) { + for(int c:b) { + print(c+" ",""); + } + print(); + + } + } + public static void showarr(int[] a) { + //Print out a array for you + for(int x:a) {print(x+" ");} + } + public static int[][] dpcache; + public static int ks(int W,int[] wt,int[] val,int n) { + int result; + if(dpcache[n][W]!=0) {return dpcache[n][W];} + if(n==0||W==0) { + result=0; + }else if(wt[n-1]>W) { + result=ks(W,wt,val,n-1); + + + + }else { + result=Math.max(val[n-1]+ks(W-wt[n-1],wt,val,n-1),ks(W,wt,val,n-1)); + } + dpcache[n][W]=result; + return result; + } + public static void kssetup(int n,int W) { + dpcache=new int[n+1][W+1]; + } + public static int count(int[] arr) { + /* + * Number of groups of 1s + * Modify for other purposes if needed + * Example + * 1111000111 + * Returns 2 + * + */ + boolean b=false;int c=0;int temp; + for(int i=0;i speedqueue=new LinkedList(); + public static long prevtime=0; + public static void $1() { + long time=System.currentTimeMillis(); + if(prevtime==0) { + prevtime=time; + }else { + speedqueue.add((long) abs(time-prevtime)); + prevtime=0; + } + } + public static long $r() { + return speedqueue.poll().longValue(); + } + public static boolean $r$smatch(String a,String b) { + return Pattern.matches(a, b); + } + public static boolean $r$match(String a,String b) throws Exception{ + //WIP + throw new Exception("Not implemented"); + } +} +