Skip to content

Instantly share code, notes, and snippets.

View arknave's full-sized avatar

Arnav Sastry arknave

View GitHub Profile
@arknave
arknave / bulba.hs
Last active January 2, 2016 11:09
Finding Bulbasaur in Pokemon Red, using Haskell!
import qualified Data.ByteString.Char8 as BS
import Data.Char
oneString :: String -> Int -> String
oneString s n = map (\x -> chr $ (ord x) + n) s
allStrings :: String -> [BS.ByteString]
allStrings s = map (BS.pack . oneString s) [-65..165]
showByteString :: Char -> Char

Keybase proof

I hereby claim:

  • I am arknave on github.
  • I am arknave (https://keybase.io/arknave) on keybase.
  • I have a public key whose fingerprint is 86D1 F11A 1C62 FD23 EAFD E7E2 A108 24C9 4330 0001

To claim this, I am signing this object:

// Assume N is the number of vertices
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dist[i][j] = min(dist[i][j],
dist[i][k] + dist[k][j]);
}
}
}
for (int i = 0; i < N; i++) {
dist[i] = INFINITY;
}
dist[start] = 0;
for (int k = 0; k < N - 1; k++) {
for (int i = 0; i < N; i++) {
for (int e = 0; e < adj[i].size(); e++) {
int j = adj[i][e].vertex;
@arknave
arknave / perms.cpp
Last active November 13, 2015 19:53
N = length(perm);
do {
print(perm);
} while (next_permutation(perm, perm + N));
#include <iostream>
#include <cstring>
#define MAX_LETTERS 600005
#define ALPHABET_SIZE 26
using namespace std;
// These two structures should be intiialized to all 0
// (0 is the root and should never be the child of another node)
int trie[MAX_LETTERS][ALPHABET_SIZE];
public class Trie {
final static int ALPHABET_SIZE = 26;
Trie[] children;
public Trie() {
this.children = new Trie[ALPHABET_SIZE];
}
// return true if the word added is new.
public boolean insert(String s) {
@arknave
arknave / CharCounter.hs
Created December 25, 2016 03:55
Counts characters in Golf.hs. Strips out imports, type definitions, and whitespace
import Data.List.Split
valid :: String -> Bool
valid "" = False
valid s = not $ foldr (\a b -> b || a `elem` ["::", "import", "->", "module" ]) False $ words s
count :: String -> Int
count s = if valid s then length . concat $ words s else 0
main = do
Hello Challenge!
// Say you have an integer array of length n. Then this monstrosity sorts it, slowly.
void cursed_sort(int* a, int n) {
int*q,i;
for(i=0;i<n;++i)
for(q=a;q+1<a+n;++q)
if(*q>*(q+1))
*q^=*(q+1)^=*q^=*(q+1);
}