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
| #!/usr/bin/sbcl --script | |
| (load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))) | |
| (require 'cl-ppcre) | |
| (with-open-file (in (car (last *posix-argv*))) | |
| (let* ((l (read in)) | |
| (d (read in)) | |
| (n (read in)) | |
| (words (loop repeat d |
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
| #!/usr/bin/sbcl --script | |
| (defun count-unique (alist) | |
| (let ((hash (make-hash-table :test #'equal))) | |
| (map 'nil | |
| (lambda (i) | |
| (setf (gethash i hash) 1)) | |
| alist) | |
| (hash-table-count hash))) |
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
| #!/usr/bin/sbcl --script | |
| (with-open-file (in (car (last *posix-argv*))) | |
| (let ((total-cases (read in))) | |
| (with-open-file (out "A.out" :direction :output :if-exists :supersede) | |
| (loop for i from 1 to total-cases do | |
| (let* ((n (read in)) | |
| (v1 (loop for j from 0 below n collect (read in))) | |
| (v2 (loop for j from 0 below n collect (read in)))) | |
| (format out "Case #~D: ~D~%" i |
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
| (let ((counter 0)) | |
| (defun increment-counter () | |
| (incf counter)) | |
| (defun reset-counter () | |
| (setf counter 0)) | |
| (defun get-counter () | |
| counter)) |
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
| #!/usr/bin/sbcl --script | |
| (loop for n = (read t) | |
| for stack = (list n) then (cons n stack) | |
| until (member n '(exit quit)) | |
| do (unless (numberp n) | |
| (cond | |
| ((endp (nthcdr 2 stack)) | |
| (format t "Not enough numbers in stack~%") | |
| (pop stack)) |
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
| #include <stdio.h> | |
| #include <string.h> | |
| int main() { | |
| char a[] = "abcd"; | |
| memmove(a, a+1, 3); | |
| a[3] = 0; | |
| printf(a); | |
| return 0; | |
| } |
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
| #!/usr/bin/sbcl --script | |
| (defmacro time-methods (&body list) | |
| (let ((number (gensym))) | |
| `(progn | |
| ,@(loop for (key value) on list by #'cddr | |
| collect `(defun ,key (,number) | |
| (* ,number ,value)))))) | |
| (time-methods seconds 1 minutes 60 hours 3600 days 86400) |
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
| integral :: (Fractional a, Ord a) => (a -> a) -> Integer -> a -> a -> a | |
| integral f p a b | |
| | a==b = 0 | |
| | otherwise = total 0 a | |
| where dx = (b-a)/fromInteger p | |
| total t x | x2>b = t | |
| | otherwise = total (t+(dx*(f x+(4*f ((x+x2)/2))+f x2)/6)) x2 | |
| where x2 = x+dx |
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) | |
| (labels ((factorial-helper (x accumulator) | |
| (if (zerop x) | |
| accumulator | |
| (factorial-helper (- x 1) (* accumulator x))))) | |
| (factorial-helper number 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
| use std::vec::append_one; | |
| #[deriving(Clone)] | |
| struct Tree<T>(T, ~[Tree<T>]); | |
| impl<T: ToStr> ToStr for Tree<T> { | |
| fn to_str(&self) -> ~str { | |
| let &Tree(ref data, ref children) = self; | |
| data.to_str() + " -> " + children.to_str() | |
| } |