This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import sys | |
def sort_perm(perm_list): | |
''' This will sort the list of permutations in | |
your into a list of tuples/list''' | |
teh_list = sorted(perm_list) | |
for item in teh_list: | |
if (item == teh_list[len(teh_list) - 1]): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun space-split (string) | |
"works for integers only at this point" | |
(loop for start = 0 then (1+ finish) ;; increments start by the value of finish | |
for finish = (position #\Space string :start start) ;; gives position of the next space begins at start | |
collecting (parse-integer (subseq string start finish)) ;; gathers integers from string list | |
until (null finish))) ;; continue until finish is nil (runs off the end of the string) | |
(defun cut-sticks (sticks) | |
(do ((rest (sort sticks #'<) | |
(remove (car rest) rest))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; This is to read files into repl for dev work | |
; You would replace println with your function | |
; That you would like to test on each line of | |
; the text file. | |
(defn do-stuff [file] ; file should be a string surrounded by double quotes | |
(with-open [rdr (clojure.java.io/reader file)] | |
(doseq [line (remove empty? (line-seq rdr))] | |
(println line)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* https://www.codeeval.com/open_challenges/166/ */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAX 1024 | |
int time_difference(char* time1, char* time2); | |
void seconds_to_time(int seconds); | |
int main(int argc, char** argv) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Enter your code here. Read input from STDIN. Print output to STDOUT | |
(defun space-split (string) | |
(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 min-from-list (list &optional (default 1000)) | |
(reduce #'min list :initial-value default)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;https://www.hackerrank.com/challenges/halloween-party | |
(defn determine_pieces [number] | |
(if (= (mod number 2) 0) | |
(* (/ number 2) (/ number 2)) | |
(* (quot number 2) (+ (quot number 2) 1)))) ;quot is clojure's version of non-float division | |
(dotimes [i (Integer/parseInt (read-line))] | |
(let [input (Integer/parseInt (read-line))] | |
(println (determine_pieces input)))) |