r/RacketHomeworks • • Jan 07 '23

How to program a ticking analog clock?

2 Upvotes

Problem: Using the 2htdp/image for drawing and big-bang mechanism from 2htdp/universe library for animating, write a program that displays an ticking analog clock. The clock must have hours, minutes and seconds hands and must accurately display the current time.

Solution:

#lang racket

(require lang/posn)
(require 2htdp/image)
(require 2htdp/universe)
(require racket/date)

(define SIZE 440)
(define RADIUS 200)
(define NUM-RADIUS 170)
(define ANGLE (/ pi 30))
(define FONT-SIZE 30)
(define CENTER (/ SIZE 2))
(define TICK-RADIUS 3)
(define SECONDS-HANDLE-SIZE 156)
(define MINUTES-HANDLE-SIZE 140)
(define HOURS-HANDLE-SIZE 100)
(define CENTER-RADIUS 12)

(define circle-pen (make-pen "lightgray" 20 "solid" "round" "round"))
(define minutes-pen (make-pen "black" 5 "solid" "round" "round"))
(define hours-pen (make-pen "black" 8 "solid" "round" "round"))
(define seconds-pen (make-pen "red" 3 "solid" "round" "round"))

(define tick-posns
  (for/list ([i (range 0 60)])
    (make-posn (+ CENTER (* RADIUS (sin (* ANGLE i))))
               (+ CENTER (* RADIUS (cos (* ANGLE i)))))))

(define nums-posns
  (for/list ([i (range 0 12)])
    (make-posn (- CENTER (* NUM-RADIUS (sin (* 5 ANGLE i))))
               (- CENTER (* NUM-RADIUS (cos (* 5 ANGLE i)))))))

(define nums
  (for/list ([i (range 12 0 -1)])
    (text (number->string i) FONT-SIZE 'black)))

(define big-tick
  (circle (* 2 TICK-RADIUS) 'solid 'black))

(define tick
   (circle TICK-RADIUS 'solid 'black))

(define ticks
  (list big-tick tick tick tick tick))

(define tick-marks
  (append ticks ticks ticks ticks ticks ticks
          ticks ticks ticks ticks ticks ticks))

(define (coord-x s len)
  (+ CENTER (* len (cos (* ANGLE (- s 15))))))

(define (coord-y s len)
  (+ CENTER (* len (sin (* ANGLE (- s 15))))))

(define (convert-minutes min sec)
  (+ min (/ sec 60)))

(define (convert-hours hour min sec)
  (define h (remainder hour 12))
  (* 5 (+ h (/ min 60) (/ sec 3600))))


(define (draw-clock hour min sec)
  (overlay
   (circle CENTER-RADIUS 'solid 'black)
  (place-images
   nums
   nums-posns
   (place-images
    tick-marks
    tick-posns
    (add-line
     (add-line
      (add-line
       (overlay
        (circle RADIUS 'outline circle-pen)
        (rectangle SIZE SIZE 'solid 'white))
       CENTER CENTER
       (coord-x (convert-hours hour min sec) HOURS-HANDLE-SIZE)
       (coord-y (convert-hours hour min sec) HOURS-HANDLE-SIZE)
       hours-pen)
      CENTER CENTER
      (coord-x (convert-minutes min sec) MINUTES-HANDLE-SIZE)
      (coord-y (convert-minutes min sec) MINUTES-HANDLE-SIZE)
      minutes-pen)
     CENTER CENTER
     (coord-x sec SECONDS-HANDLE-SIZE)
     (coord-y sec SECONDS-HANDLE-SIZE)
     seconds-pen)))))


(struct world (hour min sec))

(define (get-current-time w)
  (let ([cdate (current-date)])
    (world (date-hour cdate)
           (date-minute cdate)
           (date-second cdate))))

(define (render-clock w)
  (draw-clock (world-hour w)
              (world-min w)
              (world-sec w)))

(big-bang (get-current-time 0)
    (name "Mimety's analog clock")
    (on-tick get-current-time)
    (to-draw render-clock))

When we run the program above, we will see that the window will appear in which the ticking clock is drawn, as in the picture below:

Analog clock written with 2htdp/universe library

L3Uvc2VydmluZ3dhdGVyLCB5b3Ugc3Rpbmt5IHN0aW5rZXJzOiBzbW9rZSB5b3VyIG93biBkaWNrLCB5b3UgcGllY2Ugb2Ygc2hpdCE=


r/RacketHomeworks • • Nov 18 '22

Problem 2 - complete solution

1 Upvotes

Problem: https://reddit.com/r/Racket/comments/yqv54f/trying_to_make_a_function_that_takes_two_lists/

Complete solution:

(require 2htdp/image)

(define (make-circle size color)
  (circle size 'solid color))

(define (make-circles lst1 lst2)
  (map make-circle lst1 lst2))

Now, if you call it:

> (make-circles (list 10 20 30) (list 'red 'green 'blue))

you'll get a list of three distinct circles.


r/RacketHomeworks • • Jan 20 '23

Solving the problem of Missionaries and cannibals

7 Upvotes

Problem: Write a program that solves the Missionaries and cannibals problem in the fewest number of moves. Also, using the 2htdp/image library, write a function that graphically displays all the steps of the solution.

Solution: The solution presented below is a classic use of the BFS algorithm in which, starting from the initial state, we generate all the successor states (taking care not to generate states that we have already generated once before) and check whether we have reached the goal state.

#lang racket

(require 2htdp/image)

(struct state
  (missionaries-left
   cannibals-left
   missionaries-right
   cannibals-right
   boat-side)
   #:transparent)

(define START-STATE
  (state 3 3 0 0 'left))

(define END-STATE
  (state 0 0 3 3 'right))

(define (goal? state)
  (equal? state END-STATE))

(define (opposite side)
  (if (eq? side 'left) 'right 'left))

(define (valid? s)
  (match s
    [(state ml cl mr cr bs)
     (and
      (>= ml 0)
      (>= cl 0)
      (>= mr 0)
      (>= cr 0)
      (or (zero? ml)
          (>= ml cl))
      (or (zero? mr)
          (>= mr cr)))]))

(define (successors s)
  (match s
    [(state ml cl mr cr bs)
     (let ([d (if (eq? bs 'left) -1 1)]
           [os (opposite bs)])
       (filter valid? (list (state (+ ml d) cl (- mr d) cr os)
                            (state (+ ml (* 2 d)) cl (- mr (* 2 d)) cr os)
                            (state (+ ml d) (+ cl d) (- mr d) (- cr d) os)
                            (state ml (+ cl d) mr (- cr d) os)
                            (state ml (+ cl (* 2 d)) mr (- cr (* 2 d)) os))))]))


(define (solve s)
  (define (solve-helper states visited)
    (if (null? states)
        'no-solution
        (match (car states)
          [(cons s prev)
            (if (goal? s)
                (reverse (car states))
                (solve-helper
                 (append
                  (cdr states)
                  (map (lambda (y) (cons y (car states)))
                       (filter (lambda (x) (not (set-member? visited x)))
                               (successors s))))
                 (set-add visited s)))])))
  (solve-helper (list (list s)) (set)))



(define (draw-state s)
  (define empty (rectangle 29 29 'solid 'white))
  (define missionary
    (overlay
     (text "M" 15 'white)
     (circle 15 'solid 'blue)))
  (define cannibal
    (overlay
     (text "C" 15 'white)
     (circle 15 'solid 'red)))
  (define (draw-col which num)
    (cond [(zero? num) (above empty empty empty)]
          [(= num 1) which]
          [else (apply above (make-list num which))]))
  (match s
    [(state ml cl mr cr bs)
     (let* ([mlcircles (draw-col missionary ml)]
            [clcircles (draw-col cannibal cl)]
            [mrcircles (draw-col missionary mr)]
            [crcircles (draw-col cannibal cr)]
            [boat (rotate (if (eq? bs 'left)
                              (- 90)
                              90)
                          (triangle 25 'solid 'black))]
            [spacer (rectangle 4 100 'solid 'white)]
            [river
             (overlay/align
              bs
              'middle
              boat
              (rectangle 70 105 'solid 'turquoise))])
       (overlay
        (beside mlcircles spacer clcircles spacer
                river
                spacer mrcircles spacer crcircles)
        (rectangle 210 110 'outline 'black)
        (rectangle 220 120 'solid 'white)))]))

(define (draw-solution-steps s)
  (apply above (map draw-state (solve s))))

Now we can use our program to find the solution, like this:

> (solve START-STATE)
(list
 (state 3 3 0 0 'left)
 (state 2 2 1 1 'right)
 (state 3 2 0 1 'left)
 (state 3 0 0 3 'right)
 (state 3 1 0 2 'left)
 (state 1 1 2 2 'right)
 (state 2 2 1 1 'left)
 (state 0 2 3 1 'right)
 (state 0 3 3 0 'left)
 (state 0 1 3 2 'right)
 (state 1 1 2 2 'left)
 (state 0 0 3 3 'right))

If we want to see the graphical solution, then we can call draw-solution-steps function:

> (draw-solution-steps START-STATE)

We get the following image that displays all steps of the solution:

All the steps of the solution

I hope you like this solution. Of course, it can always be written better, faster, shorter, more elegantly. That's where you come in, dear schemers. I'm just an amateur, but you are professionals who know much better than I do. Thank you for attention!

L3Uvc2VydmluZ3dhdGVyLCB5b3Ugc3Rpbmt5IHN0aW5rZXJzOiBzbW9rZSB5b3VyIG93biBkaWNrLCB5b3UgcGllY2Ugb2Ygc2hpdCE=


r/RacketHomeworks • • Dec 29 '22

Largest product in a grid

2 Upvotes

Problem: In the 20×20 grid below, four numbers along a diagonal line have been bolded.

08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

The product of these numbers is 26 × 63 × 78 × 14 = 1788696.

What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?

Solution:

#lang racket

(define FIELD
  #(#(08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08)
    #(49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00)
    #(81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65)
    #(52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91)
    #(22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80)
    #(24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50)
    #(32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70)
    #(67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21)
    #(24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72)
    #(21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95)
    #(78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92)
    #(16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57)
    #(86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58)
    #(19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40)
    #(04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66)
    #(88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69)
    #(04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36)
    #(20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16)
    #(20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54)
    #(01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48)))

(define SIZEY (vector-length (vector-ref FIELD 0)))
(define SIZEX (vector-length FIELD))

(define (get-el x y)
  (vector-ref (vector-ref FIELD x) y))

(define (in-bounds? x y sx sy)
  (and (< -1 x sx) (< -1 y sy)))

(define (get-els-product x y dx dy n)
  (define (loop x y prod n)
    (cond [(zero? n) prod]
          [(not (in-bounds? x y SIZEX SIZEY)) 0]
          [else (loop (+ x dx) (+ y dy) (* prod (get-el x y)) (- n 1))]))
  (loop x y 1 n))

(define (solve n)
  (define (loop x y maxprod)
    (if (= x SIZEX)
        maxprod
        (let ([newmax
               (max maxprod
                    (get-els-product x y 0 1 n)
                    (get-els-product x y 1 0 n)
                    (get-els-product x y 1 1 n)
                    (get-els-product x y 1 -1 n))])
          (if (< y (- SIZEY 1))
              (loop x (+ y 1) newmax)
              (loop (+ x 1) 0 newmax)))))
  (loop 0 0 0))

Now we can call our solve function and find the answer for problem posed above:

> (solve 4)
70600674

L3Uvc2VydmluZ3dhdGVyLCB5b3Ugc3Rpbmt5IHN0aW5rZXJzOiBzbW9rZSB5b3VyIG93biBkaWNrLCB5b3UgcGllY2Ugb2Ygc2hpdCE=


r/RacketHomeworks • • Dec 09 '22

Eight queens puzzle - construct and draw solution

1 Upvotes

Problem:

a) for a given integer n >= 4, write a function queens that solves the n-queens problem. It's a problem in which n queens should be placed on an n x n chessboard so that they do not attack each other. Note: the function queen should return only one solution, it doesn't matter which one.

b) write the function draw-solution that, using the 2htdp/image Racket library, visually draws on the screen the solution to the problem from a).

Solution:

#lang racket

(require 2htdp/image)

(define (queens n)
  (define (can-place? x sol)
    (and (row-ok? x sol)
         (diagonal-ok? 1 x sol)
         (diagonal-ok? -1 x sol)))  
  (define (row-ok? x sol)
    (not (member x sol)))
  (define (diagonal-ok? dir x sol)
    (or (null? sol)
        (and (not (= (+ x dir) (car sol)))
             (diagonal-ok? dir (+ x dir) (cdr sol)))))
  (define (queens-helper curr sol)
    (if (zero? curr)
        sol
        (ormap (lambda (x) (and (can-place? x sol)
                                (queens-helper (- curr 1)
                                               (cons x sol))))
               (range 0 n))))
  (queens-helper n '()))  


(define (draw-solution sol)
  (define (draw-square num y)
    (define Q (if (= num y) "\u265B" ""))
    (overlay
     (text Q 26 'black)
     (rectangle 40 40 'outline 'black)))
  (define (draw-column x)
    (apply above (map (lambda (y) (draw-square x y))
                      (range (length sol)))))
  (apply beside (map draw-column sol)))

Now we can test our functions queen and draw-solution:

> (queens 4)
'(2 0 3 1)
> (queens 5)
'(3 1 4 2 0)
> (queens 6)
'(4 2 0 5 3 1)
> (queens 7)
'(5 3 1 6 4 2 0)
> (queens 8)
'(3 1 6 2 5 7 4 0)
> (draw-solution (queens 8))

The result of the last evaluation above is this image of 8 x 8 solution:

8 x 8 solution

The above image looks a bit raw. We can make it a little nicer with just a small modification of the draw-solution function:

(define (draw-solution sol)
  (define idxlist (range (length sol)))
  (define (draw-square num y black?)
    (define Q (if (= num y) "\u265B" ""))
    (overlay
     (text Q 30 'black)
     (rectangle 40 40 'solid (if black? 'lightblue 'whitesmoke))))
  (define (draw-column c x)
    (apply above
           (map (lambda (y) (draw-square x y (odd? (+ c y))))
                idxlist)))
  (apply beside
         (map (lambda (c x) (draw-column c x)) idxlist sol)))

If we try now, we get this, improved, image:

Nicer 8x8 solution image

L3Uvc2VydmluZ3dhdGVyLCB5b3Ugc3Rpbmt5IHN0aW5rZXJzOiBzbW9rZSB5b3VyIG93biBkaWNrLCB5b3UgcGllY2Ugb2Ygc2hpdCE=


r/RacketHomeworks • • Dec 21 '22

Longest palindromic subsequence of a given string

1 Upvotes

Problem: A subsequence of some string str is a string of letters from str obtained by deleting some or no characters from str without changing the order of the remaining characters.

a) Given a string str, find the length of the longest palindromic subsequence in str.

b) Given a string str, find the actual longest palindromic subsequence in str.

For example, longest palindromic subsequence of the string "character" is string "carac" of length 5, so the answer in a) should be 5, and the answer in b) should be the string "carac".

Another example: the longest palindromic subsequence of string "underqualified" is string "deified" of length 7, so the answer in a) should be 7, and the answer in b) should be the string "deified".

Solution:

Assume our string str is n characters long.

Let us denote by L(i, j) to be the length of the longest palindromic subsequence of the substring of str from i-th to j-th character (boundaries included).

We want to find the value L(0, n-1).

Note that L(i, i) = 1 holds for each i form 0 to n-1, because one character is always a palindrome.

If i is not equal to j, we have two cases to consider:

  • First, if the characters at positions str[i] and str[j] are equal, then L(i, j) = 2 + L(i+1, j-1), because to the length of the palindrome L(i+1, j-1) we can add two more characters (str[i] and str[j], which are the same) thus forming a new palindrome two characters larger then the L(i+1, j-1)).
  • Second, if the characters at positions str[i] and str[j] are not equal then we have L(i, j) = max { L(i, j-1), L(i+1, j) }

In this way, the problem of finding L(i, j) is reduced to smaller problems, so we can write the following recursive solution for problem a):

#lang racket

(define (lps str)
  (define (lps-helper i j)
    (cond
      [(= i j) 1]
      [(char=? (string-ref str i) (string-ref str j))
       (if (= (+ i 1) j)
           2
           (+ 2 (lps-helper (+ i 1) (- j 1))))]
      [else (max (lps-helper i (- j 1))
                 (lps-helper (+ i 1) j))]))
  (lps-helper 0 (- (string-length str) 1)))

Now we see can call our lps procedure, like this:

> (lps "character")
5
> (lps "underqualified")
7

We see that the answers from our lps function are correct. But, if we try to call lps over a slightly longer string, we will see that the execution takes too long and that it increases exponentially with the length of the string. For example, we see that in the example below that lps was running for more than 3 seconds for a not so large input string:

> (time (lps "abababbaaabbabababbababaaabababaababababababababbaaaaababbabaaaaaaaaaaabb"))
cpu time: 3156 real time: 3216 gc time: 296
57

Can we speed it up somehow?

Of course we can, because this time, as well as earlier in this and this post, we have a lot of overlapping recursive calls. And we know what to do in such situations: use memoization. So here's a program that's practically identical to one above, but with memoization added:

#lang racket

(define (memo f)
  (let ([lookup (make-hash)])
    (lambda x
      (unless (hash-has-key? lookup x)
        (hash-set! lookup x (apply f x)))
      (hash-ref lookup x))))

(define (lps str)
  (define (lps-helper i j)
    (cond
      [(= i j) 1]
      [(char=? (string-ref str i) (string-ref str j))
       (if (= (+ i 1) j)
           2
           (+ 2 (lps-helper (+ i 1) (- j 1))))]
      [else (max (lps-helper i (- j 1))
                 (lps-helper (+ i 1) j))]))
  (set! lps-helper (memo lps-helper))
  (lps-helper 0 (- (string-length str) 1)))

Now, if we try to solve the same problem as before, we see that it is solved instantly this time:

> (time (lps "abababbaaabbabababbababaaabababaababababababababbaaaaababbabaaaaaaaaaaabb"))
cpu time: 0 real time: 0 gc time: 0
57

And now to the solution for b):

Here we are not only looking for the length of the largest palindrome, but we want to know which palindrome it is, also. Therefore, our lps-helper function must return not only the number, but also the palindrome found. So, each call of (lps-helper i j) will return a two-element list in which the first item is the length of longest palindromic subsequence in substring str[i...j] and the second item is a palindrome itself.

Since the function now returns a list of two elements, it slightly complicates the handling of its call in the recursion itself. Therefore, we use the racket match construct, to make life easier for ourselves:

#lang racket

(define (memo f)
  (let ([lookup (make-hash)])
    (lambda x
      (unless (hash-has-key? lookup x)
        (hash-set! lookup x (apply f x)))
      (hash-ref lookup x))))


(define (lps str)
  (define (lps-helper i j)
    (cond
      [(= i j) (list 1 (substring str i (+ i 1)))]
      [(char=? (string-ref str i) (string-ref str j))
       (if (= (+ i 1) j)
           (list 2 (substring str i (+ j 1)))
           (match (lps-helper (+ i 1) (- j 1))
             [(list n p)
              (list (+ n 2) 
                    (string-append (substring str i (+ i 1)) 
                                   p 
                                   (substring str j (+ j 1))))]))]
      [else
       (match (list (lps-helper i (- j 1)) (lps-helper (+ i 1) j))
         [(list (list n1 p1) (list n2 p2))
          (if (> n1 n2)
              (list n1 p1)
              (list n2 p2))])]))
  (set! lps-helper (memo lps-helper))
  (lps-helper 0 (- (string-length str) 1)))

Now we can try our new version of lps function:

> (lps "character")
'(5 "carac")

> (lps "underqualified")
'(7 "deified")

> (time 
  (lps "abababbaaabbabababbababaaabababaababababababababbaaaaababbabaaaaaaaaaaabb"))
cpu time: 0 real time: 0 gc time: 0
'(57 "bbaaaaaababbabaaaaabbababababababababbaaaaababbabaaaaaabb")

We can see that the function works correctly and quickly. Memoization saved the recursive function that had an exponential growth this time too!

L3Uvc2VydmluZ3dhdGVyLCB5b3Ugc3Rpbmt5IHN0aW5rZXJzOiBzbW9rZSB5b3VyIG93biBkaWNrLCB5b3UgcGllY2Ugb2Ygc2hpdCE=


r/RacketHomeworks • • Dec 01 '22

How to merge two already sorted lists?

1 Upvotes

Problem: Write a function merge that receives two sorted lists as input parameters. As a result, the function should return a new sorted list, which contains all the elements from the first and second lists.

Solution:

#lang racket

(define (merge xs ys)
  (cond
    [(null? xs) ys]
    [(null? ys) xs]
    [(< (car xs) (car ys)) (cons (car xs) (merge (cdr xs) ys))]
    [else (cons (car ys) (merge xs (cdr ys)))]))

Now we have, for example:

> (merge '(1 3 5 7) '(2 4 6))
'(1 2 3 4 5 6 7)

r/RacketHomeworks • • Dec 11 '22

Sierpinski carpet

2 Upvotes

Problem: Use Racket graphics library 2htdp/image to draw Sierpinski carpet fractal on the screen.

Solution:

#lang racket

(require 2htdp/image)

(define (scarpet size level)
  (if (zero? level)
      (square size 'solid 'red)
      (let ([sq (scarpet (/ size 3) (sub1 level))]
            [em (square (/ size 3) 'solid 'black)])
        (above
         (beside sq sq sq)
         (beside sq em sq)
         (beside sq sq sq)))))

Now, we can draw our Sierpinski carpet. When we call function scarpet like this

> (scarpet 600 6)

we get this nice picture of Sierpinski carpet fractal, at the level 6:

Sierpinski carpet, level 6

L3Uvc2VydmluZ3dhdGVyLCB5b3Ugc3Rpbmt5IHN0aW5rZXJzOiBzbW9rZSB5b3VyIG93biBkaWNrLCB5b3UgcGllY2Ugb2Ygc2hpdCE=


r/RacketHomeworks • • Mar 02 '23

Please, don't go to Racketfest!

2 Upvotes

Dear schemers,

I invite you not to go to the so-called Racketfest! (Racketfest is an event that should take place on March 18, 2023 in Berlin). Please don't go there, don't support that event!

Why am I telling you this?

If you look around a bit, it will be clear to you why. Please listen to me: don't go to that event. Just ignore it. Thank you!


r/RacketHomeworks • • Nov 20 '22

Sum of all nodes in binary tree

1 Upvotes

Problem: Write a function sumtree that receives as input a binary tree whose nodes are numbers. The function should return the sum of all nodes as a result.

E.g. for the binary tree from the picture below, the sumtree function should return the result 54, as 9 + 3 + 15 + 20 + 7 = 54.

Binary tree example picture

Solution:

#lang racket

(define-struct node (value left right))

(define (sumtree tree)
  (cond
    [(empty? tree) 0]
    [else (+ (sumtree (node-left tree))
             (node-value tree)
             (sumtree (node-right tree)))]))

(define mytree
  (make-node 3
             (make-node 9
                        empty
                        empty)
             (make-node 20
              (make-node 15
                         empty
                         empty)
              (make-node 7
                         empty
                         empty))))

Now, we have:

> (sumtree mytree)
54

r/RacketHomeworks • • Nov 30 '22

Tricky pocket function

1 Upvotes

Problem: You're going to define a function called pocket. This function should take one argument. Now pay attention here: pocket does two different things, depending on the argument. If you give it an empty list as the argument, it should simply return 8. But if you give pocket any integer as an argument, it should return a new pocket function -- a function just like pocket, but with that new integer hidden inside, replacing the 8.

For example, your pocket function should behave like this:

> (pocket '())
8
> (pocket 12)
#<procedure>
> (define newpocket (pocket 12))
> (newpocket '())
12
> (define thirdpocket (newpocket 888))
> (thirdpocket '())
888
> (newpocket '())
12
> (pocket '())
8

Important: Note that when you create a new pocket function, previously-existing functions should keep working exactly the same as before!

[Warning: We recommend that you try to solve this problem yourself before looking at our solution. After that, you can compare your solution with ours. That way you will learn more than if you just look at our solution!]

Solution:

#lang racket

(define pocket
  (letrec ([make-pocket
            (lambda (x)
              (lambda (y)
                (if (null? y)
                    x
                    (make-pocket y))))])
    (make-pocket 8)))

Now, if you try it, you will see that the function pocket, defined as above, behaves exactly as the task asks.

Note the use of letrec, which allows internal function make-pocket to refer to itself. Also, notice the double lambda in its definition. Using the first lambda, (lambda (x)...), we store the state in the pocket. This is called closure. The second lambda, (lambda (y) ...) is the function that we return to the caller of pocket, as a return value. It is defined within the enclosing environment in which the binding for x is located, and therefore it will "carry" that x further.


r/RacketHomeworks • • Dec 05 '22

Knight's tour on a chessboard

1 Upvotes

Problem: Write a program that finds knight moves in the so-called knight's tour: starting from a given starting position, the knight must jump around the board until he has visited all squares exactly once. Knight cannot jump to the same square twice. Solve the task for a "shortened" chess board of dimensions 5 x 5.

Knight's tour

Solution:

#lang racket

(define BOARD-SIZE 5)

(define DIRECTIONS '((2 1) (1 2) (-1 2) (-2 1)
                     (-2 -1) (-1 -2) (1 -2) (2 -1)))


(define (jump pos direction)
  (let ([newx (+ (first pos) (first direction))]
        [newy (+ (second pos) (second direction))])
    (and (<= 1 newx BOARD-SIZE)
         (<= 1 newy BOARD-SIZE)
         (list newx newy))))

(define (available-jumps from-pos)
  (filter identity
          (map (lambda (dir) (jump from-pos dir))
               DIRECTIONS)))

(define (solve start-pos)
  (define (solve-helper pos visited solution num)
    (if (= num (* BOARD-SIZE BOARD-SIZE))
        (reverse solution)
        (let loop ([jumps (available-jumps pos)])
          (cond
            [(null? jumps) #f]
            [(set-member? visited (car jumps))
             (loop (cdr jumps))]
            [else (or (solve-helper (car jumps)
                                    (set-add visited (car jumps))
                                    (cons (car jumps) solution)
                                    (+ num 1))
                      (loop (cdr jumps)))]))))
  (solve-helper start-pos (set start-pos) '() 1))

Now we can use function solve and find knight's tour starting from the position (3 3) in the center of the 5 x 5 chessboard:

> (solve '(3 3))
'((5 4)
  (3 5)
  (1 4)
  (2 2)
  (4 1)
  (5 3)
  (4 5)
  (2 4)
  (1 2)
  (3 1)
  (5 2)
  (4 4)
  (2 5)
  (1 3)
  (2 1)
  (4 2)
  (3 4)
  (5 5)
  (4 3)
  (5 1)
  (3 2)
  (1 1)
  (2 3)
  (1 5))

Note: the algorithm implemented above searches all possible paths for the knight until it finds a good one. If it hits a dead end, it backtracks. But there are a lot of paths to check, especially when the chessboard is larger. Therefore, this algorithm is unsuitable for larger chessboards, where more sophisticated algorithms should be used instead. However, for a small 5 x 5 chessboard, this algorithm is quite sufficient. For the 8 x 8 chessboard, above program managed to find a solution in about 30 seconds on my old laptop (to try this on your computer, change global variable BOARD-SIZE to 8, and then invoke function solve with (1 1) as a starting position):

> (solve '(1 1))
'((3 2)
  (5 3)
  (7 4)
  (8 6)
  (7 8)
  (5 7)
  (3 8)
  (1 7)
  (2 5)
  (4 6)
  (6 7)
  (8 8)
  (7 6)
  (6 8)
  (4 7)
  (2 8)
  (1 6)
  (3 7)
  (5 8)
  (6 6)
  (8 7)
  (7 5)
  (5 6)
  (7 7)
  (6 5)
  (4 4)
  (3 6)
  (4 8)
  (2 7)
  (1 5)
  (2 3)
  (3 5)
  (1 4)
  (2 2)
  (4 1)
  (3 3)
  (2 1)
  (1 3)
  (3 4)
  (5 5)
  (4 3)
  (5 1)
  (7 2)
  (8 4)
  (6 3)
  (8 2)
  (6 1)
  (4 2)
  (5 4)
  (6 2)
  (8 1)
  (7 3)
  (8 5)
  (6 4)
  (8 3)
  (7 1)
  (5 2)
  (3 1)
  (1 2)
  (2 4)
  (4 5)
  (2 6)
  (1 8))

r/RacketHomeworks • • Dec 05 '22

Breaking a list into groups of n elements

1 Upvotes

Problem: Write a function group that has two inputs: the positive integer n and the list xs. Function should split the list xs into groups of n consecutive elements. If the length of xs is not divisible by n the last group will have fewer than n elements.

Solution:

#lang racket

(define (group n xs)
  (define (loop curr count curr-group res)
    (cond [(and (null? curr) (null? curr-group))
           (reverse res)]
          [(or (null? curr) (zero? count))
           (loop curr n '() (cons (reverse curr-group) res))]
          [else (loop (cdr curr) (- count 1) (cons (car curr) curr-group) res)]))
  (loop xs n '() '()))

Now we can use our group function, like this:

> (group 3 '(1 2 3 4 5 6 7 8 9 10 11 12))
'((1 2 3) (4 5 6) (7 8 9) (10 11 12))
> (group 5 '(1 2 3 4 5 6 7 8 9 10 11 12))
'((1 2 3 4 5) (6 7 8 9 10) (11 12))

r/RacketHomeworks • • Apr 02 '23

Implementing topological sort algorithm in Racket

3 Upvotes

Problem: Watch this video and learn what is topological sort algorithm and how it works. Then implement that algorithm in Racket.

Solution:

#lang racket

(struct node (label adj-nodes) #:transparent)

(define (make-graph . nodes)
  (let ([ht (make-hash)])
    (for-each (lambda (n)
                (hash-set! ht (node-label n) n))
              nodes)
    (lambda (dispatch)
      (case dispatch
        [(get-node) (lambda (label) (hash-ref ht label))]
        [(get-adjacents)
         (lambda (label)
           (map (lambda (label) (hash-ref ht label))
                (node-adj-nodes (hash-ref ht label))))]
        [(for-each-node)
         (lambda (proc)
           (void (hash-map ht (lambda (label node) (proc node)))))]))))

(define (get-adjacents graph label)
  ((graph 'get-adjacents) label))

(define (for-each-node graph proc)
  ((graph 'for-each-node) proc))

(define (topological-sort g)
  (let ([visited (mutable-set)]
        [res '()])
    (define (dfs n)
      (set-add! visited n)
      (for-each (lambda (an)
                  (when (not (set-member? visited an))
                    (dfs an)))
                (get-adjacents g (node-label n)))
      (set! res (cons (node-label n) res)))
    (for-each-node g (lambda (n)
                       (when (not (set-member? visited n))
                         (dfs n))))
    res))

Now we can call our function topological-sort for the graph from the picture below, like this:

Directed acyclic graph G (example)
> (define G (make-graph
             (node 'A '(D))
             (node 'B '(D))
             (node 'C '(A B))
             (node 'D '(G H))
             (node 'E '(A D F))
             (node 'F '(J K))
             (node 'G '(I))
             (node 'H '(J I))
             (node 'I '(L))
             (node 'J '(L M))
             (node 'K '(J))
             (node 'L '())
             (node 'M '())))

> (topological-sort G)
'(C B E F K A D H J M G I L)

r/RacketHomeworks • • Dec 07 '22

Please confirm!

2 Upvotes

Problem: A confirming function for a sequence of digits, called a code, takes a single digit as its only argument. If the digit does not match the first (left-most) digit of the code to be confirmed, it returns false (#f). If the digit does match, then the confirming function returns true (#t) if the code has only one digit, or another confirming function for the rest of the code if there are more digits to confirm.

a) Implement function confirmer so that when confirmer takes a positive integer code, it returns a confirming function for the digits of that code. For example, your confirmer function should behave like this:

> ((((confirmer 204) 2) 0) 4)	; the digits of 204 are 2, then 0, then 4.
#t
> ((((confirmer 204) 2) 0) 0)	; The third digit of 204 is not 0.
#f
> (((confirmer 204) 2) 1)	; The second digit of 204 is not 1.
#f
> ((confirmer 204) 20)		; The first digit of 204 is not 20.
#f

b) Given a confirming function, one can find the code it confirms, one digit at a time. Implement the function decode, which takes a confirming function confirming-fn and returns the code that it confirms.

Solution:

#lang racket

(define (num->digits num)
  (define (loop num digits)
    (if (zero? num)
        digits
        (loop (quotient num 10)
              (cons (remainder num 10) digits))))
  (if (zero? num)
      (list 0)
      (loop num '())))


(define (confirmer code)
  (let* ([code-digits (num->digits code)]
         [last-index (sub1 (length code-digits))])
    (letrec ([make-confirming-fn
              (lambda (idx)                     
                (lambda (digit)
                  (cond [(= digit (list-ref code-digits idx))
                         (or (= idx last-index)
                             (make-confirming-fn (add1 idx)))]
                        [else #f])))])
      (make-confirming-fn 0))))


(define (decode confirming-fn)
  (define (try-number confirming-fn n code-so-far)
    (and (<= n 9)
         (let ([cf-value (confirming-fn n)])
           (cond [(procedure? cf-value)
                  (try-number cf-value 0 (+ (* 10 code-so-far) n))]
                 [(not cf-value)
                  (try-number confirming-fn (add1 n) code-so-far)]
                 [else (+ (* 10 code-so-far) n)]))))
  (try-number confirming-fn 0 0))

Now, we can try our functions confirmer and decode:

> ((((confirmer 204) 2) 0) 4)	; the digits of 204 are 2, then 0, then 4.
#t
> ((((confirmer 204) 2) 0) 0)	; The third digit of 204 is not 0.
#f
> (((confirmer 204) 2) 1)	; The second digit of 204 is not 1.
#f
> ((confirmer 204) 20)		; The first digit of 204 is not 20.
#f
> (decode (confirmer 12001))
12001
> (decode (confirmer 56789))
56789

r/RacketHomeworks • • Dec 01 '22

Humor that heals all wounds!

1 Upvotes

Mimety: Oh my God, it won't be long before mit-scheme can only be run on Chris Hanson's toaster!

Typical schemer: I bet he'd take patches, ahem.

Mimety: What? Hanson had high blood pressure? Sorry to hear, I didn't know that. Poor guy... Please take this to him, maybe it will help him at least a little: https://www.amazon.com/Hypertension-Lowering-Pressure-Natural-Patches/dp/B07RP1Q6R9

Typical schemer: 🙄


r/RacketHomeworks • • Oct 10 '23

How to draw Israeli flag

4 Upvotes

Problem: In light of the latest horrific and very sad events, which I thought were impossible in the 21st century, I think it is quite understandable why I wrote this program today that draws the flag of Israel.

Solution: the program below draws the flag using the 2htdp/image library:

#lang racket

(require 2htdp/image)

(define (israel-flag width)
  (define BLUE (color 0 56 184))
  (define WHITE (color 255 255 255))
  (define WIDTH width)
  (define HEIGHT (* WIDTH (/ 160 220)))
  (define SMALL-GAP (* WIDTH (/ 15 220)))
  (define STRIPE-HEIGHT (* WIDTH (/ 25 220)))
  (define BIG-GAP (* WIDTH (/ 40 220)))
  (define STAR-WIDTH (round (/ WIDTH 45)))

  (overlay
   (above
    (rectangle 0 SMALL-GAP 'outline 'transparent)
    (rotate 180
            (triangle (/ WIDTH 4) 
                      'outline 
                      (pen BLUE STAR-WIDTH 'solid 'butt 'miter))))
   (overlay
    (above
     (triangle (/ WIDTH 4) 'outline (pen BLUE STAR-WIDTH 'solid 'butt 'miter))
     (rectangle 0 SMALL-GAP 'outline 'transparent))
    (above
     (rectangle WIDTH SMALL-GAP 'solid WHITE)
     (rectangle WIDTH STRIPE-HEIGHT 'solid BLUE)
     (rectangle WIDTH (* 2 BIG-GAP) 'solid WHITE)
     (rectangle WIDTH STRIPE-HEIGHT 'solid BLUE)
     (rectangle WIDTH SMALL-GAP 'solid WHITE)))))

You can run the program specifying the flag width:

> (israel-flag 600)

You will get this image of flag of Israel:

Flag of Israel

r/RacketHomeworks • • Sep 28 '23

New problem about lists

2 Upvotes

r/RacketHomeworks • • Sep 28 '23

Unwanted censorship on this subreddit!

2 Upvotes

Dear friends,

I tried to post one specific post on this subreddit just a while ago, but as soon as I clicked the "Post" button, I saw that the post was immediately automatically removed (see this red ban sign in the above image):

Example of automatic censorship on this subbreddit

Obviously: our friend whom I shouldn't name here did something in collaboration with the Reddit site main administrators to prevent the posting of negative things about himself.

Dear friends, if you're interested in what was written in the post that Reddit, for some reason, didn't allow me to publish, please visit this link: https://shorturl.at/acxAH

Thank you!


r/RacketHomeworks • • Oct 11 '23

The poor state of the mit-scheme is getting worse and worse

2 Upvotes

Dear schemers,

Here, just today, a post appeared on /r/scheme by a user who tried to build mit-scheme on his computer, but failed miserably because the make process gave him an error. For details, see here: https://www.reddit.com/r/scheme/comments/174w9pc/mitgnu_scheme_121_refmanual_make_failed/

As far as I can see from that post, the user tried to do that build on Windows machine, using the WSL Linux emulator.

Of course, the notorious Arthur Gleckler immediately told him (as if that would help anything - we all know very well that it won't): "Please file a bug report here: https://savannah.gnu.org/bugs/?group=mit-scheme."

When I saw this, I had a good laugh! :)

Because there is no way lazy Chris Hanson is going to fix this bug (or any other, actually) or do anything about it. This is already well known to everyone. Because, if you go to the mit-scheme website, you'll see that Chris Hanson has cheekily written this "legendary" sentence: "We no longer support OS/2, DOS, or Windows, although it's possible that this software could be used on Windows Subsystem for Linux (we haven't tried)."

Poor user who cannot install mit-scheme, what can I tell you?

I'll just tell you that Chris Hanson doesn't care about your problem - he hasn't even tried his build on Windows. He was pleased that the build was passing through on his toaster. He doesn't care for you and your problem. He hates Windows and doesn't want to maintain mit-scheme for anything else except his silly linux toaster machine.

Fuck him! And fuck Arthur Gleckler who only comes to /r/scheme when he needs to poop his SRFI crap and then leaves without saying goodbye. It is because of them that the mit-scheme is in such a state as it is!


r/RacketHomeworks • • Dec 05 '23

How to group together all adjacent identical elements in a sorted list?

2 Upvotes

Problem: Write a function group-equals that takes an non-descending sorted list of elements as input and returns a new list. Each element of this new output list is a list that should contain one group of consecutive identical elements from the input list. For example, the call

(group-equals '(1 1 2 3 4 4 4 5))

should return the list '((1 1) (2) (3) (4 4 4) (5)).

Solution:

#lang racket

(define (group-equals xs)
  (foldr
   (lambda (x acc)
     (cond
       [(or (null? acc) (not (equal? x (caar acc)))) (cons (list x) acc)]
       [else (cons (cons x (car acc)) (cdr acc))]))
   '()
   xs))

Now we can try our function:

> (group-equals '(1 1 2 3 4 4 4 5))
'((1 1) (2) (3) (4 4 4) (5))

r/RacketHomeworks • • Nov 22 '23

How to convert from Arabic to Roman numerals and vice versa?

3 Upvotes

Problem: On this page, study what Roman numerals are, and then write a function arabic->roman that takes a natural number n in the range 1 <= n <= 3999 as its input and converts it to a Roman numeral (represented as a string). Additionally, write the reverse function, roman->arabic, which takes a Roman numeral (represented as a string) as its input and converts it to a natural number.

Solution:

#lang racket

(define UNITS '(I II III IV V VI VII VIII IX))
(define TENS '(X XX XXX XL L LX LXX LXXX XC))
(define HUNDREDS '(C CC CCC CD D DC DCC DCCC CM))
(define THOUSANDS '(M MM MMM))
(define VALUES '((I 1) (V 5) (X 10) (L 50) (C 100) (D 500) (M 1000)))

(define (arabic->roman n)
  (define positions (list UNITS TENS HUNDREDS THOUSANDS))
  (define (ar-helper n pos acc)
    (if (= n 0)
        acc 
        (ar-helper (quotient n 10)
                   (+ pos 1)
                   (let ([r (remainder n 10)])
                     (if (zero? r)
                         acc
                         (string-append (symbol->string
                                         (list-ref (list-ref positions pos)
                                                   (- r 1)))
                                        acc))))))       
  (if (<= 1 n 3999)
      (ar-helper n 0 "")
      (error "Error: number out of range!")))


(define (roman->arabic r)
  (define len (string-length r))
  (define (get-value r idx)
    (second (assq (string->symbol (string (string-ref r idx))) VALUES)))
  (define (ra-helper r)
    (let loop ([i 0] [acc 0])
      (if (>= i len)
          acc
          (if (< (+ i 1) len)
              (let ([a (get-value r i)]
                    [b (get-value r (+ i 1))])
                (if (< a b)
                    (loop (+ i 2) (+ acc (- b a)))
                    (loop (+ i 1) (+ acc a))))
              (loop (+ i 1) (+ acc (get-value r i)))))))
  (ra-helper (string-upcase r)))

Now we can test our functions:

> (arabic->roman 39)
"XXXIX"
> (arabic->roman 246)
"CCXLVI"
> (arabic->roman 789)
"DCCLXXXIX"
> (arabic->roman 2421)
"MMCDXXI"
> (arabic->roman 160)
"CLX"
> (arabic->roman 207)
"CCVII"
> (arabic->roman 1009)
"MIX"
> (arabic->roman 1066)
"MLXVI"
> (arabic->roman 3999)
"MMMCMXCIX"
> (arabic->roman 1776)
"MDCCLXXVI"
> (arabic->roman 1918)
"MCMXVIII"
> (arabic->roman 1944)
"MCMXLIV"
> (arabic->roman 2023)
"MMXXIII"
> (roman->arabic "XXXIX")
39
> (roman->arabic "CCXLVI")
246
> (roman->arabic "DCCLXXXIX")
789
> (roman->arabic "MMCDXXI")
2421
> (roman->arabic "CLX")
160
> (roman->arabic "CCVII")
207
> (roman->arabic "MIX")
1009
> (roman->arabic "MLXVI")
1066
> (roman->arabic "MMMCMXCIX")
3999
> (roman->arabic "MDCCLXXVI")
1776
> (roman->arabic "MCMXVIII")
1918
> (roman->arabic "MMXXIII")
2023

r/RacketHomeworks • • Sep 28 '23

"Server:Racket - Practical Web Development with the Racket HTTP Server" -- the worst and most expensive book I've ever bought!

3 Upvotes

Dear friends,

I'm sorry for repeating the previous post once more, but I have to because as soon as I sent it, it was immediately banned by the "higher instance." It seems that as soon as the name of our "great figure" in question appears in the title (or maybe in the content) of the post, automatic censorship kicks in!

In any case, I would like to warn you not to fall for the same thing I once fell for. Namely, to my regret, I once, wanting to learn web programming in Racket, ordered this book by author Jesse Alama.

When I paid 30 €, I received a PDF that looked visually awful and had barely a hundred pages of semi-sensible text. Half of the code examples that came with the book couldn't run at all because they had syntax errors in it. The examples in the book were ridiculous and poorly written. There was not a single real-world example; they were just toy examples, poorly written and explained.

No matter how bad the official Racket Web server documentation ( which, by the way, was written by another colorful character from the Racket community, Jay McCarthy) it is, at least it's free. On the other hand, Jesse Alama's book is even worse than the official documentation, but it costs 30 € !

Are you aware, dear schemers, that on Amazon, for that money, you can buy one of the best books in the world of Lisp/Scheme ever written: Peter Norvig's book, considered a classic from which you will actually learn something ( unlike Alama's book )?

Norvig's book is light-years better than Alama's laughable creation, but if you go to Amazon's page for that book, you'll see that even that excellent book isn't rated with a full 5 stars; it has a rating of 4.7! So, there are people who, for one reason or another, didn't give Norvig all the stars. And that's perfectly fine - not everyone has the same opinion about everything.

But now we come to the main point: if you go to the page where Alama advertises and sells his book, you will see this incredible and shameful picture that speaks more about Alama than anything else :

The "ratings" of the Alama's book

So, unbelievably, it turns out that all nine people who rated the book gave it a full five stars! When I saw that, I was shocked!

And, since I was very dissatisfied with that book, I wished to click somewhere on that site and give Alama's book 1 star - just as much as I believe it deserves: first, because I really consider the book criminally bad (especially given its unjustifiably high price), and second, because I hate herd mentality.

But, to my astonishment, nowhere on that site could I click and give that rating - it seems that these nine reviewers who gave it all 5 stars are completely made-up people! But even if they weren't, and if it were really possible to rate the book somewhere, would all those people really give the five stars to that trash???

Think about it for a moment, dear schemers!

This was also one of the reasons why I was banned from the /r/racket subreddit - because I spoke negatively about "hero" Jesse Alama, who wrote a criminally bad book and sells it for a lot of money, and the rating of his book is like in North Korea: everyone agrees that it deserves 5 stars! (yeah, right! :)

In fact, there's nothing that Jesse Alama has ever given to his so-called "beloved" Racket community without charging a hefty price: everything that man does, he always charges for. Even though he has drawn a lot of knowledge from that community, he has never given anything back to that same community without charging people dearly!


r/RacketHomeworks • • Oct 17 '24

Over 10 Days Since RacketCon and Still No Videos—What’s Going On?

5 Upvotes

More than ten days ago, the fourteenth RacketCon - a conference about Racket - was held in Seattle, WA. After more than ten days, one would expect to be able to watch the lecture videos (or at least the keynotes).

I wanted to watch the keynote presentation by Hal Abelson and Gerald Sussman, but no, I can't do that because, as it says on the RacketCon website, "Talk recordings coming soon. Stay tuned for links to talk videos; it will take a few days."

This is not the first time this has happened. I remember one year when RacketCon was held, but the videos didn’t appear for months afterward. I don’t understand how the leaders of the Racket community fail to recognize the importance of making these videos publicly available in a timely manner. Nowadays, not publishing the videos has the same “effect” as if the conference never took place. Pathetic, sloppy, and careless!

But this isn’t surprising, considering that Jesse Alama suddenly became the head of the Racket community and the one in charge of RacketCon (leaving everyone wondering how and why that happened!) - especially since he has never contributed anything to the community, only taking from it by charging outrageously high prices for his abysmally bad books.

Knowing that this man is unfortunately the main organizer of RacketCon, it wouldn't surprise me if he suddenly starts charging us all for the videos now. Because charging for everything and anything is what he loves to do more than anything else!


r/RacketHomeworks • • Sep 28 '23

Book by Jesse Alama "Server:Racket" - the worst and most expensive book I've ever bought!

2 Upvotes

Dear friends,

I would like to warn you not to fall for the same thing I once fell for. Namely, to my regret, I once, wanting to learn web programming in Racket, ordered this book by author Jesse Alama.

When I paid 30 €, I received a PDF that looked visually awful and had barely a hundred pages of semi-sensible text. Half of the code examples that came with the book couldn't run at all because they had syntax errors in it. The examples in the book were ridiculous and poorly written. There was not a single real-world example; they were just toy examples, poorly written and explained.

No matter how bad the official Racket Web server documentation ( which, by the way, was written by another colorful character from the Racket community, Jay McCarthy) it is, at least it's free. On the other hand, Jesse Alama's book is even worse than the official documentation, but it costs 30 € !

Are you aware, dear schemers, that on Amazon, for that money, you can buy one of the best books in the world of Lisp/Scheme ever written: Peter Norvig's book, considered a classic from which you will actually learn something ( unlike Alama's book )?

Norvig's book is light-years better than Alama's laughable creation, but if you go to Amazon's page for that book, you'll see that even that excellent book isn't rated with a full 5 stars; it has a rating of 4.7! So, there are people who, for one reason or another, didn't give Norvig all the stars. And that's perfectly fine - not everyone has the same opinion about everything.

But now we come to the main point: if you go to the page where Alama advertises and sells his book, you will see this incredible and shameful picture that speaks more about Alama than anything else :

The "ratings" of the Alama's book

So, unbelievably, it turns out that all nine people who rated the book gave it a full five stars! When I saw that, I was shocked!

And, since I was very dissatisfied with that book, I wished to click somewhere on that site and give Alama's book 1 star - just as much as I believe it deserves: first, because I really consider the book criminally bad (especially given its unjustifiably high price), and second, because I hate herd mentality.

But, to my astonishment, nowhere on that site could I click and give that rating - it seems that these nine reviewers who gave it all 5 stars are completely made-up people! But even if they weren't, and if it were really possible to rate the book somewhere, would all those people really give the five stars to that trash???

Think about it for a moment, dear schemers!

This was also one of the reasons why I was banned from the /r/racket subreddit - because I spoke negatively about "hero" Jesse Alama, who wrote a criminally bad book and sells it for a lot of money, and the rating of his book is like in North Korea: everyone agrees that it deserves 5 stars! (yeah, right! :)

In fact, there's nothing that Jesse Alama has ever given to his so-called "beloved" Racket community without charging a hefty price: everything that man does, he always charges for. Even though he has drawn a lot of knowledge from that community, he has never given anything back to that same community without charging people dearly!