Skip to content

Instantly share code, notes, and snippets.

View chmllr's full-sized avatar

Christian Müller chmllr

View GitHub Profile
@chmllr
chmllr / gist:1005060
Created June 2, 2011 19:06
JS Hash Function
function hashIt(str)
{
// just a cyclic rotation
var rotateBy = function(s,N) { for (var i = 0; i < N; i++) s.unshift(s.pop()); }
// take a random string and convert it to char array
var alphabet = "1L,$G=JD'W)7QYC02M#</@B3-AUF*!VT8H(RO;:45&NXZ+PKES>.?I6%9".split("");
// set the initial value of the hash to the first 16 chars of the alphabet
var hash = alphabet.slice(0,16);
// we go through the string
for (var i = 0; i < str.length; i++)
var numbers = readLine.split(" ").map(_.toInt).toList.sorted
numbers = numbers.distinct ++ (numbers diff numbers.distinct)
def solve(acc: Int, list: List[Int]):Int = list match{
case (h::Nil) => acc
case (h::t) => if (h+1 == t.head) solve(acc,t) else solve(acc+1,h+1::t.slice(0,t.size-1))
}
println(solve(0,numbers))
; for i > 2
(defn prime? [i]
(not (some
#(= 0 (mod i %))
(cons 2 (range 3 (inc (Math/sqrt i)) 2)))))
<html>
<body>
<div id="box1">1</div>
<div id="box2">2</div>
<div id="box3">3</div>
<div id="box4">4</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
type="text/javascript"></script>
<script>
for (var i = 1; i < 5; i++) {
@chmllr
chmllr / Haiku.clj
Last active December 15, 2015 04:19
(defn wlk
[nodelist [tag attrs & nodes]]
(if (= (:class attrs) "r")
(conj nodelist (:href (second (first nodes))))
(reduce wlk nodelist (filter coll? nodes))))
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String... args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(; t > 0; --t) {
System.out.println(solve(s.next(), s.next()));
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int k = s.nextInt(), n;
String[] a;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Mmass {
static Map<Character, Integer> m = new HashMap<Character, Integer>();
public static void main(String[] args) {
m.put('H', 1);
m.put('C', 12);
m.put('O', 16);
import java.util.Scanner;
import java.util.Arrays;
public class Bsearch1 {
public static void main(String... args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt(), Q = s.nextInt(), n = N, ln = N-1;
int[] numbers = new int[N];
while (n --> 0) numbers[ln-n] = s.nextInt();
import java.util.Scanner;
import java.util.Arrays;
public class Bsearch1 {
public static void main(String... args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt(), Q = s.nextInt(), n = N, ln = N-1;
int[] numbers = new int[N];
while (n --> 0) numbers[ln-n] = s.nextInt();