This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is simply some pseudo code; applicable to any programming language that has support for | |
// basic data types and recursive functions | |
// Two questions: | |
// 1- Solve the "mystery": what does the function do? | |
// 2- Enhance the function to accommodate other integers. | |
function mystery(int a, int b) { | |
if (b == 1) { | |
return a | |
} | |
return mystery(a, b - 1) + a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A naive circular buffer ... | |
type CircularBuffer struct { | |
buf []int | |
cap, head, tail int | |
} | |
func (q *CircularBuffer) add(d int) error { | |
if q.tail-q.head > q.cap { | |
return errors.New("buffer full") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import sun.jvm.hotspot.memory.*; | |
import sun.jvm.hotspot.oops.*; | |
import sun.jvm.hotspot.debugger.*; | |
import sun.jvm.hotspot.runtime.*; | |
import sun.jvm.hotspot.tools.*; | |
import sun.jvm.hotspot.utilities.*; | |
public class DirectMemorySize extends Tool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fx.jvm.hotspot.tools; | |
import java.util.List; | |
import sun.jvm.hotspot.tools.Tool; | |
public class PrintThreadIds extends Tool { | |
public static void main(String[] args) { | |
PrintThreadIds tool = new PrintThreadIds(); | |
tool.start(args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ /tmp tree com | |
com | |
└── test | |
└── Test.java | |
1 directory, 2 files | |
➜ /tmp more com/test/Test.java | |
package com.test; | |
class Test { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tmp; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import java.net.URLConnection; | |
/** | |
* Created by kmhaswade on 3/31/16. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class SubsetSum { | |
public static void main(String[] args) { | |
subsetHasSum(new int[]{1, 2, 3, 4, 5, 6, 7}, 22); | |
} | |
static void subsetHasSum(int[] set, int sum) { | |
// basic validations | |
Arrays.sort(set); | |
System.out.println(Arrays.toString(set)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Trying out the solution to: | |
* http://stackoverflow.com/questions/5739024/finding-duplicates-in-on-time-and-o1-space | |
* Created by kmhaswade on 3/5/16. | |
* Have I translated @caf's pseudocode correctly? | |
*/ | |
public class DuplicateFinder { | |
public static void main(String[] args) throws IOException { | |
int[] a = new int[]{3, 0, 1, 3, 2}; | |
int n = a.length; | |
for (int i = 0; i <= n-1; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Library/Java/JavaVirtualMachines/8/Contents/Home/bin/java | |
-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:64661,suspend=y,server=n -ea -Didea.junit.sm_runner -Dfile.encoding=UTF-8 | |
-classpath "/Applications/IntelliJ IDEA 15.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA 15.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/jfxrt.jar: | |
/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/8/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Quicksort { | |
public static void qsort(int[] ints, int fi, int li) { | |
/* the recursive procedure */ | |
if (fi < li) { | |
//int p = partition(ints, fi, li); | |
int p = partition1(ints, fi, li); | |
qsort(ints, fi, p - 1); | |
qsort(ints, p + 1, li); | |
} |