doing for loops assignment
1
Name:
Anonymous
2010-10-24 12:10
I'm in a programming class and we have an assignment about for loops where we gotta shuffle a deck of cards. Can someone show me how to do this please? in return, tits
2
Name:
Anonymous
2010-10-24 12:15
3
Name:
Anonymous
2010-10-24 12:15
4
Name:
Anonymous
2010-10-24 14:17
inb4 Paridæ
5
Name:
Anonymous
2010-10-24 18:34
6
Name:
Anonymous
2010-10-24 20:49
Accurate depiction of ``female programming'' .
7
Name:
Anonymous
2010-10-24 22:22
loled
8
Name:
Anonymous
2010-10-24 22:25
>>7
``lole'' is not a verb.
9
Name:
Anonymous
2010-10-25 4:42
>>8
Lazy organic light emitting diode.
10
Name:
Anonymous
2010-10-25 13:58
>>8
``Fucke'' isn't a verb either, but I still fucked your mother last night.
11
Name:
Anonymous
2010-10-25 17:11
(define shuffle-list
(lambda (l c)
(if (zero? c)
l
(let-values ([(a b)
(let ([half (floor (/ (length l) 2))])
(values
(let loop ([l l][n half])
(if (zero? n)
null
(cons (car l) (loop (cdr l) (sub1 n)))))
(list-tail l half)))])
(shuffle-list
(let loop ([a a][b b][l null])
(cond
[(null? a) (append (reverse b) l)]
[(null? b) (append (reverse a) l)]
[(zero? (random 2))
(loop (cdr a) b (cons (car a) l))]
[else
(loop a (cdr b) (cons (car b) l))]))
(sub1 c)))))))
12
Name:
Anonymous
2010-10-25 17:12
>>10
``Fuck'' isn't an abbreviation, ``lol'' is.
13
Name:
Anonymous
2010-10-25 17:59
Here's a quick-and-dirty CL solution:
(defun shuffle (sequence)
(sort (copy-seq sequence) #'> :key #'(lambda (_) (random 1.0))))
14
Name:
Anonymous
2010-10-25 18:00
>>12
Lol is an interjection, like "wow" or "huh"
15
Name:
Anonymous
2010-10-25 18:57
Assuming a vector,
(define (shuffle-vector! vector)
(loop ((for element i (in-vector vector)))
(let ((j (random-integer (+ i 1))))
(vector-set! vector i (vector-ref vector j))
(vector-set! vector j element))))
>>11
I don't like the way some Schemers (like the guy who does programming praxis) seem to thing that it's a good idea to use as many primitive abstractions as possible. I've rewritten your code to make it more palatable to me
(import (rnrs)
(srfi :27 random-bits)
(only (srfi :1 lists) split-at append-reverse)
(srfi :8 receive)
(wak foof-loop))
(define (half n)
(floor (/ n 2)))
(define (flip-coin)
(zero? (random-integer 2)))
(define (merge picker list1 list2)
(loop continue ((for car1 cons1 (in-list list1))
(for car2 cons2 (in-list list2))
(with result '()))
=> (append-reverse result (append cons1 cons2))
(if (picker car1 car2)
(continue (=> result (cons car1 result))
(=> cons2 cons2))
(continue (=> result (cons car2 result))
(=> cons1 cons1)))))
(define (shuffle l)
(receive (head tail) (split-at l (half (length l)))
(merge (lambda args (flip-coin)) head tail)))
(define (shuffle-many l c)
(loop ((for num-times (down-from c (to 0)))
(with l l (shuffle l)))
=> l))
16
Name:
Anonymous
2010-10-25 18:59
>>15
better yet, I could have used
vector-swap!
17
Name:
Anonymous
2010-10-25 22:56
when do I get tits?
18
Name:
Anonymous
2010-10-25 23:52
19
Name:
Anonymous
2010-10-26 0:43
20
Name:
Anonymous
2010-10-26 8:54
>>17
When you become attractive to the opposite sex.
21
Name:
Anonymous
2010-10-26 18:32
>>20
I don't think a man with tits would be very attractive to the opposite sex.
23
Name:
Anonymous
2011-02-04 14:51