Skip to content

Instantly share code, notes, and snippets.

View wildermuthn's full-sized avatar

Nate Wildermuth wildermuthn

View GitHub Profile
;; ProjectEuler.net
;;
;; Multiples of 3 and 5
;; Problem 1
;; If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
;;
;; Find the sum of all the multiples of 3 or 5 below 1000.
(defun multiple-of-p (y x)
(let ((r (mod x y)))
; ProjectEuler.net
;; Even Fibonacci numbers
;; Problem 2
;; Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
;;
;; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
;;
;; By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
(defun fsequence (limit)
;;; Largest prime factor
;;; Problem 3
;;; The prime factors of 13195 are 5, 7, 13 and 29.
;;;
;;; What is the largest prime factor of the number 600851475143 ?
;;;
;;;
(defun prime-p (x)
(cond ((eq 1 x) 1)
;;Largest palindrome product
;;Problem 4
;;A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
;;
;;Find the largest palindrome made from the product of two 3-digit numbers.
;;
(defun number-palindrome-p (x)
(string-palindrome-p (write-to-string x)))
(make-table user
((id serial)
(first-name string)
(last-name string)
(email string)
(phone string)
(image-id integer)
(creation-date integer (timestamp-to-unix (now))))
(projects tasks)
(id project-id))
@wildermuthn
wildermuthn / test.lisp
Last active August 29, 2015 13:56
Testing in LISP is amazing
(defun make-edge (from ids &key end)
(progn
(setf ids (mklist ids)))
(dolist (to ids)
(let ((lst (gethash from *edges*)))
(cond ((not lst)
(setf (gethash from *edges*) (list to)))
(t (if (not (member to lst))
(setf (gethash from *edges*) (append lst (list to)))))))
(unless end (make-edge to from :end t)))))
@wildermuthn
wildermuthn / formItem.js
Last active August 29, 2015 13:57
An Angular directive for form fields
angular.module('crossroadsDonateApp')
.directive('formItem', ['$compile', '$http', '$templateCache', function($compile, $http, $templateCache, $rootScope) {
var rootScope = $rootScope;
var getTemplate = function(contentType) {
var templateLoader,
baseUrl = 'views/',
templateMap = {
text: 'form-item-text.html',
radios: 'form-item-radios.html',
select: 'form-item-select.html',
(defun check-permission (user verb noun params)
(let ((verb (intern (string-upcase verb)))
(noun (intern (string-upcase noun))))
(if (equal verb 'remove) (setf verb 'delete))
(let ((perm (member noun (getf (gethash user *user-permissions*) verb) :test #'equal)))
(or (member (getf params :type) (getf perm noun) :test #'equal) (equal '(all) (getf perm noun))))))
(defun insert-op (op)
(setf *operations* (append *operations* op)))
; (insert-op (create-op "mail" "mail"))
(defmacro create-op (noun &body body)
`(insert-op '((if (equal noun ,noun)
,@body))))
; (create-op "mail" "sending mail")
(defparameter echo '(lambda (x) (print x)))
(defun test ()
(funcall echo "me"))
; (test)
;The value (LAMBDA (X) (PRINT X))
;is not of type ;
;(OR FUNCTION SYMBOL).