This file contains 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
(defn euler-8 | |
"Problem 8" | |
([numstr] | |
(euler-8 (map #(Character/getNumericValue %) numstr) 0)) | |
([numseq prod] | |
(let [temp-prod (reduce * (take 5 numseq)) | |
next-list (rest numseq)] | |
(if (< (count next-list) 5) prod | |
(recur next-list | |
(if (> temp-prod prod) temp-prod prod)))))) |
This file contains 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
(defn sieve-of-era | |
"Generate the primes upto N based on sieve of erastothenes" | |
([num] (sieve-of-era [] num (range 2 num))) | |
([primes num sieve] | |
(let [x (first sieve)] | |
(def divisible? (fn [divisor num] (zero? (rem num divisor)))) | |
(def remaining (fn [coll x] (remove (partial divisible? x) coll))) | |
;optimisation - enough to remove until current prime ^ 2 < limit | |
(if (>= (* x x) num) (concat primes sieve) | |
(recur (conj primes x) num (remaining (rest sieve) x)))))) |
This file contains 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
;Project Euler problem 11 - find the greatest product of 4 elements in the 20*20 | |
;grid either vertically, horizontally or diagonally | |
(def grid | |
[[8 2 22 97 38 15 0 40 0 75 4 5 7 78 52 12 50 77 91 8] | |
[49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 4 56 62 0] | |
[81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 3 49 13 36 65] | |
[52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 2 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 3 45 2 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] |
This file contains 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
public void redirect(final HttpServletResponse response) throws IOException{ | |
String url = "http://abcde.com"; | |
String out = "<script type=\"text/javascript\">window.top.location=\"" + url+ "\"</script>"; | |
response.getWriter().print(out); | |
response.flushBuffer(); | |
} |
This file contains 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
public synchronized int hashCode() { | |
if (hashCode != -1) | |
return hashCode; | |
hashCode = handler.hashCode(this); | |
return hashCode; | |
} |
This file contains 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
protected synchronized InetAddress getHostAddress(URL u) { | |
if (u.hostAddress != null) | |
return u.hostAddress; | |
String host = u.getHost(); | |
if (host == null || host.equals("")) { | |
return null; | |
} else { | |
try { | |
u.hostAddress = InetAddress.getByName(host); |
This file contains 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
private static InetAddress[] checkLookupTable(String host) { | |
synchronized (lookupTable) { | |
// If the host isn't in the lookupTable, add it in the | |
// lookuptable and return null. The caller should do | |
// the lookup. | |
if (lookupTable.containsKey(host) == false) { | |
lookupTable.put(host, null); | |
return null; | |
} | |
This file contains 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 test_crawler.test; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* 1. Create a 2D array of characters | |
* 2. Gather the lower edge indexes first e.g. in a 3 x 3 array gather all y positions alone | |
* y x x |
This file contains 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.ArrayList; | |
import java.util.List; | |
public class ObjectSizeCalcTest { | |
static class Employee { | |
public int age; | |
public int id; | |
public String name; | |
public Employee(int age, int id, String name) { |
This file contains 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.File; | |
import java.io.FilenameFilter; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
public class FileUtil { | |
private static String getSimpleFileName(final String fileName){ | |
if(fileName == null || fileName.length() == 0) |
OlderNewer