Skip to content

Instantly share code, notes, and snippets.

View sidharthkuruvila's full-sized avatar

Sidharth Kuruvila sidharthkuruvila

View GitHub Profile
let move_bits dest_num dest_bits src_num src_bits =
let movable_bits = min dest_bits src_bits in
let bits_to_move = src_num lsr (src_bits - movable_bits) in
let dest_num = (dest_num lsl movable_bits) lor bits_to_move in
let src_num = src_num land ((1 lsl (src_bits - movable_bits)) - 1) in
(dest_num, dest_bits - movable_bits, src_num, src_bits - movable_bits)
@sidharthkuruvila
sidharthkuruvila / day_8.ml
Created December 9, 2020 23:50
Advent of code
open Core;;
let s = {|nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
import csv
import itertools
l = list(csv.DictReader(open('Mailchimp_GeoTwitter.csv')))
col_email = 'Email Address'
col_address = 'Your Mailing Address (where you receive your rock)'
col_shipping = 'Are you willing to ship internationally?'
col_first_name = 'First Name'
col_last_name = 'Last Name'
let string_of_chars chars =
let buf = Buffer.create 16 in
List.iter (Buffer.add_char buf) chars;
Buffer.contents buf
module type Integer = sig
type t
val of_string : string -> t
val to_string : t -> string
val subtract : t -> t -> t
@sidharthkuruvila
sidharthkuruvila / ServerApplication.kt
Created April 20, 2018 12:45
Simple client server application using AsynchronousSocketChannel
package server
import java.io.ObjectInputStream
import java.net.SocketAddress
import java.nio.ByteBuffer
import java.nio.channels.AsynchronousServerSocketChannel
import java.nio.channels.AsynchronousSocketChannel
import java.nio.channels.CompletionHandler
import java.nio.charset.Charset
import java.util.concurrent.locks.Lock
class Solution {
public:
double findMedianSortedArrays(vector<int> &nums1, vector<int> &nums2);
int find_at_index(size_t index, vector<int> &nums1, vector<int> &nums2);
};
using namespace std;
void print_range(std::vector<int>::iterator begin, std::vector<int>::iterator end){
for(; begin < end; begin++){
std::cout << *begin << ",";
@sidharthkuruvila
sidharthkuruvila / render_digraph.py
Created December 14, 2017 08:27
Generate a graphviz dot file for a digraph represented as an adjacency list
G = [("A", "B"), ("B", "C"), ("C", "D")]
def render_digraph(G):
def g():
for p, c in G:
yield '"{}" -> "{}"'.format(p, c)
lines = "\n".join(g())
return """
digraph {{
@sidharthkuruvila
sidharthkuruvila / problem_10_20_a.py
Created December 14, 2017 04:42
Use a greedy strategy to create a schedule
import itertools
s = """18:01 ! 6:042
18:01 ! 18:03
8:01 ! 8:02
6:042 ! 6:046
6:001; 6:002 ! 6:003
6:004 ! 6:033
18:01 ! 18:02
6:046 ! 6:840
@sidharthkuruvila
sidharthkuruvila / sudoku.py
Created December 7, 2017 12:13
A simple sudoku solver
"""
A simple sudoku puzzle solver. It uses the observation that an empty position
can only contain labels that are not in any other position on the same row, column or
square.
The solver uses a depth first strategy. When a candidate position is filled, that value is
removed from the list of possible value for all positions on the same row, column or squeare.
This reduces the search space considerably.
@sidharthkuruvila
sidharthkuruvila / AggregatAccounts.vba
Created July 29, 2017 18:38
vba excel macro script that aggregates data from multiple xlsx files
'vba excel macro script that aggregates data from multiple xlsx files.
'The path to the directory containing the files should be in a sheet called
'Control. And should be in Applescripts colon (:) separated format.
Option Explicit
Const max_rows As Integer = 200
Sub ListFiles()