Skip to content

Instantly share code, notes, and snippets.

View trendsetter37's full-sized avatar

Javis Sullivan trendsetter37

View GitHub Profile
@trendsetter37
trendsetter37 / GoT.lisp
Last active August 29, 2015 14:08
Game of Thrones Warmup I on hackerRanck
(defparameter *letter-hash* (make-hash-table :size 100000))
(defvar even-length)
(defvar number-of-odds 0)
(defun string-to-list (&key word)
"Will set the even/odd param as well"
(setq even-length (evenp (length word)))
(loop for letter across word collect letter))
@trendsetter37
trendsetter37 / permute.lisp
Created October 28, 2014 14:33
Gives the permutations
;; Work in progress
(defun all-permutations (list &optional (a (length list)))
"Will give you all the permutations of the list specified"
;;(format t "The optional param is: ~d~%" a)
(cond ((null list) nil)
((null (cdr list)) (list list))
(t (loop for element in list
append (mapcar (lambda (x) (cons element x))
(all-permutations (remove element list) a))))))
@trendsetter37
trendsetter37 / factor.lisp
Last active August 29, 2015 14:08
Computes the factorial of an integer
(defun factorial! (number)
"returns the factorial of the number given"
(loop for x from 1 upto number
for y = 1 then (* x y)
finally (return y)))
@trendsetter37
trendsetter37 / series-expansion.lisp
Created October 28, 2014 19:59
Evaluate e^x HackerRank Common Lisp implementation
(read) ;; Throwing this away. Not needed
(defun read-list ()
"reading in list of number"
(let ((n (read *standard-input* nil)))
(if (null n)
nil
(cons n (read-list)))))
(defun factorial! (number)
@trendsetter37
trendsetter37 / first_nrc.cpp
Last active August 29, 2015 14:11
First Non-repeated Character (CodeEval)
/* First Non-repeated Character Moderate Challenge on CodeEval */
/* Comiple this with the -std=c++11 flag to prevent warnings */
#include <iostream>
#include <fstream>
#include <string>
#include <map>
struct Double
{
int val[2]; // { count, order }
@trendsetter37
trendsetter37 / space_split.lisp
Created December 12, 2014 22:18
Common Lisp string splitting
(defun space-split (string)
"Parses integer strings right now but can be easily altered for
other purposes "
(loop for start = 0 then (1+ finish)
for finish = (position #\Space string :start start)
collecting (parse-integer (subseq string start finish))
until (null finish)))
(defun fib (n)
(labels ((calc-fib (n a b)
(if (= n 0)
a
(calc-fib (- n 1) b (+ a b)))))
(calc-fib n 0 1)))
(time (print (fib 7000)))
@trendsetter37
trendsetter37 / reverse_and_add.php
Last active August 29, 2015 14:11
Kind of a hack for the CodeEval reverse and add problem in php
<?php
/** Recursive calls should be kept to under 100 per problem prompt.
* Or else this would not work in PHP */
function iter_palindrome($integer, $count = 0) {
$reverse_int = strrev($integer);
if (intval($reverse_int) == intval($integer)) {
echo $count . " ";
@trendsetter37
trendsetter37 / pass_triangle.cpp
Created January 2, 2015 19:28
Pass Triangle on Codeeval
//Help came from Steven A. Dunn's code
#include <fstream>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
@trendsetter37
trendsetter37 / team.py
Created April 24, 2015 14:43
ACM ICPC 2014 Team
def check_match2(person1, person2):
return bin(int('0b'+person1,2) | int('0b'+person2,2)).count('1')
def make_combos2(people):
plist = []; plist.append(input())
count = 0
maximum = 0
for i in range(people-1):
person = input()