(define (divisible n k) (= 0 (mod n k)))
(define (divisible-by-list n l) (fold (lambda (k o) (or o (divisible n k))) #f l))
Name:
Anonymous2007-08-12 17:47 ID:Mvf+qhCr
(define (divisible n l)
(if (pair? l) #f
(if (= (mod n (car l)) 0) #t
(divisible n (cdr l)))))
(divisible n '(3 5))
Name:
Anonymous2007-08-12 18:05 ID:RyfBwU/E
>>3
ok this is neat
I think I want to generalize though
divisible = (lambda (n d) (= 0 (mod n d))
f-by-list = (lambda (n l) (fold (lambda (k o) (or o (f n k))) #f 1))
divisble-by-list = (lambda (n l) (fold (lambda (k o) (or o ((lambda (n d) (= 0 (mod n d)) n k))) #f 1))
((lambda (n l) (fold (lambda (k o) (or o ((lambda (n d) (= 0 (mod n d)) n k))) #f 1)) n '(3 5))
hmm
Name:
Anonymous2007-08-12 18:08 ID:UuB0Fh1x
LOL Lisp.
int f(n){(!(n%3) || !(n%5))}
Name:
Anonymous2007-08-12 18:19 ID:+1As6lo3
LOL De Morgan.
int f(n){!(n%3 && n%5)}
Name:
Anonymous2007-08-12 18:23 ID:UuB0Fh1x
>>7
LOL some sort of newfag college undergrad who just finished discrete math. My version is clearly more readable, hence it is superior to yours in every way possible.
Name:
Anonymous2007-08-12 18:38 ID:+1As6lo3
LOL hurt pride
Really, just use haskell for euler, you'll finish the first 50 or so in no time.
(defun any (&rest predicates)
(lambda (x)
(some (function identity)
(mapcar (function (lambda (p) (funcall p x))) predicates))))
did that so (any (% 3) (% 5)) makes just the function I needed,
can anyone beat that? I don't think so :p
Name:
Anonymous2007-08-13 3:12 ID:UK+mlIcu
>>15
This is what I love about you smug LISP weenies. Always making excuses for your failure of a language. Go count some parenthesis, I'm done talking with your stupid ass.
yeah i dont know lisp or anything but this thread is hilarious i mean what the fuck is >>21 even supposed to mean and how does it relate to finding if numbers are evenly divisible by 3 or 5
there are some functions explained in the book On Lisp exactly like the "all" and "any" you proposed. They're called fun (function union) and fint (function intersection).
Name:
Anonymous2007-08-13 7:30 ID:3J35KuIg
>>24
lmao, that wasn't actually the program but hehe
>>25
of course you don't understand it if you don't know lisp... duh..