Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am danvonk on github.
* I am dvonk (https://keybase.io/dvonk) on keybase.
* I have a public key whose fingerprint is C786 E49F EB06 153F 7302 069E 0436 C83D 0276 F160
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am danvonk on github.
* I am dvonk (https://keybase.io/dvonk) on keybase.
* I have a public key ASAcbi_LCpnk6Br_izsuJ5wcjmA2YQKW6oMZpeXBgvOLcgo
To claim this, I am signing this object:
#include <boost/hana.hpp>
#include <iostream>
template <typename T>
struct basic_type {
using type = T;
};
namespace hana = boost::hana;
using namespace hana::literals;
@danvonk
danvonk / cts.rb
Created March 7, 2015 11:55
Capture the sarram programming task in ruby
#!/usr/bin/ruby
class SparseArray
attr_reader :hash
def initialize
@hash = {}
end
def [](key)
/*
* Compile: gcc -Wall -o rf rf.c -lwiringPi
* Usage: sudo ./rf [binary] [delay in microseconds] [inverting bits]
* Example.. turning on Silvercrest outlet A
* sudo ./rf 11111111111111001001011001011011011011001011011011011011001001011001011011011011011011000000 500 1
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
### Keybase proof
I hereby claim:
* I am danvonk on github.
* I am danvonk (https://keybase.io/danvonk) on keybase.
* I have a public key whose fingerprint is 9790 6DF8 F237 CF4B 665D BD66 8CD6 8D5B 9903 00B6
To claim this, I am signing this object:
#!/usr/bin/env ruby
require 'benchmark'
def collatzSequence(x) # e.g. 916
n = x
chain = 0
loop do
if n % 2 == 0
n = n/2
chain = chain + 1
#!/usr/bin/env ruby
def numDivisors(x)
factors = 0
(2..x).take(Math.sqrt(x).to_i + 1).each do |u|
if x % u == 0
factors += 2
end
end
factors += 2
@danvonk
danvonk / gist:0d3fca788b0bcc755d31
Last active August 29, 2015 14:07
base no. algo
#!/usr/bin/env ruby
#Convert a binary value to decimal...
x = 1011
n = Math.log10(x).to_i + 1
b = 2 #binary
s = 0
x.to_s.chars.map(&:to_i).each do |u|
n = n - 1
#!/usr/bin/env ruby
def getBinary(dec)
quot = 0
binaryrep = []
#do the first one manually to populate q
quotmod = dec.divmod(2) # [69,0]
q = quotmod[0]
binaryrep.push(quotmod[1])