Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

LISP/Scheme/DrRacket

Name: Anonymous 2013-02-06 1:53

How the fuck do you do this?

The common card game Go Fish has an adapted childrens version known as Go-Fish-for-Fun. In this game each player tries to have as many cards in a set as possible (up to 4). When one player reaches four cards of the same number the game ends. However, the winner is the player that gets the highest score. Scores are calculated as follows: Cards which occur at least three or four times in a hand count towards the score. Cards which appear zero, once or twice in a hand do not count towards the score. Card values begin at 2 and end at 14. Each card is given its value multiplied by the number of occurrences of the card in the player’s hand. For example a player with the cards (2 2 2 5 8 8 10 10 10 10 14) receives 46 points.
This is because 2 occurs 3 times, and 10 occurs 4 times, so the total is 2*3+4*10=46. A player with the cards (2 3 5 7 7 7 9 11 12 12 12 13) receives 57 points.

Use accumulative recursion to complete the scheme function go-fishff-points, that consumes a list of numbers between 2 and 14 inclusive (called card-list), and produces a natural number that is the total points for card-list. You may assume the card-list will always be in ascending order.

For example,
(go-fishff-points empty) => 0
(go-fishff-points (list 3 3 4 7 7 8 8 12 13)) => 0
(go-fishff-points (list 4 6 6 7 7 9 9 9 9 12 14)) => 36

Name: Anonymous 2013-02-06 2:11

Snapuuu.

Name: Anonymous 2013-02-06 2:25

Bump.

Name: Anonymous 2013-02-06 4:38

Lisp/Scheme/DrRacket ... is that language like C/C++?

Name: Anonymous 2013-02-06 4:54

You still haven't failed that class yet?

Name: Xarney The Dinosaur 2013-02-06 5:11

(define (count-list lst)
 (fold
  (lambda (elem accum)
   (define (pred x) (= (car x) elem))
   ((lambda (x)
     (if (not x)
      (cons (cons elem 1) accum)
      (cons (cons elem (+ (cdr x) 1))
       (remove pred accum))))
    (find pred accum)))
  '() lst))

(define (go-fish lst)
 (fold
  (lambda (elem accum)
   (+ accum
    (if (<= (cdr elem) 2) 0
     (* (car elem) (cdr elem)))))
   0 (count-list lst)))

Name: Anonymous 2013-02-06 5:26

Just start with apply sum and go from there.

Name: Anonymous 2013-02-06 12:36

>>4
No. C++ is for weak willed people who can't open their minds to a new paradigm.

Racket is the only language that includes both batteries! So get started!

Name: Anonymous 2013-02-06 14:54

>>8
You need an open mind to learn C++, otherwise you'll just crash and burn.

Name: Anonymous 2013-02-07 3:30

>>8
You need an open anus to learn C++, otherwise you'll just pinch and rip.

Don't change these.
Name: Email:
Entire Thread Thread List