Skip to content

Instantly share code, notes, and snippets.

View xmonkee's full-sized avatar

Mayank Mandava xmonkee

View GitHub Profile
(def winnersall (set (clojure.string/split
"washington adams jefferson jefferson madison madison monroe
monroe adams jackson jackson vanburen harrison polk taylor pierce buchanan
lincoln lincoln grant grant hayes garfield cleveland harrison cleveland mckinley
mckinley roosevelt taft wilson wilson harding coolidge hoover roosevelt
roosevelt roosevelt roosevelt truman eisenhower eisenhower kennedy johnson nixon
nixon carter reagan reagan bush clinton clinton bush bush obama obama" #" ")))
(def losersall (set (clojure.string/split
"clinton jefferson adams pinckney pinckney clinton king adams
@xmonkee
xmonkee / evenFib.go
Created January 26, 2014 02:17 — forked from anonymous/evenFib
package main
import "fmt"
func isEven(n int, c chan<- int) {
if n%2 == 0{
c <- n
}
}
;This week's challenge—not directly related to BFS—is to implement a queue using two stacks.
;Queues are a first-in-first-out data structure that we just saw used as a "next to visit" data store in breadth-first search.
;Stacks are a last-in-first-out data structure used in depth-first search, and can often be used to implement recursive algorithms iteratively (because the call stack is, itself, a stack).
;For this problem, you are to create a queue using two stacks. So your Queue will support the operations:
;enqueue(item), which inserts an item into the queue
;dequeue(), which removes and returns the oldest item in the queue
@xmonkee
xmonkee / Untrusted level 13
Last active July 19, 2016 10:36
My solution
/*
* robotMaze.js
*
* The blue key is inside a labyrinth, and extracting
* it will not be easy.
*
* It's a good thing that you're a AI expert, or
* we would have to leave empty-handed.
*/
;"Find number of disjoint islands in a square matrix of 0's and 1's"
(defn rand-mat [size]
"Make a random matrix of 1's and 0's"
(vec (for [i (range size)]
(vec (for [j (range size)]
[(-> 2 rand int) [i j]])))))
(defn print-mat [mat]
"Print the matrix"
@xmonkee
xmonkee / 0_reuse_code.js
Created April 28, 2014 14:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@xmonkee
xmonkee / Concordance.py
Created January 22, 2015 08:02
Concordance generator
try:
from xml.etree.cElementTree import XML
except ImportError:
from xml.etree.ElementTree import XML
import zipfile
"""
Module that extract text from MS XML Word document (.docx).
(Inspired by python-docx <https://github.com/mikemaccana/python-docx>)
@xmonkee
xmonkee / fib.clj
Last active August 29, 2015 14:17
;Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
;1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
;By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
;Extra: Give a solution in two different languages.
(def fib (cons 0 (cons 1 (lazy-seq (map + fib (rest fib))))))
(def answer (->> fib
(take-while #(<= % 4000000))
(filter even?)
(reduce +)))
@xmonkee
xmonkee / Convert between time zones .java
Last active August 29, 2015 14:23
Convert between time zones
/* http://www.java2s.com/Code/Java/Development-Class/Converttimebetweentimezone.htm */
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
public class Main {
public static void main(String[] args) {
Calendar localTime = Calendar.getInstance();
localTime.set(Calendar.HOUR, 17);

Keybase proof

I hereby claim:

To claim this, I am signing this object: