;;;; generate.scm

;;;; This file, part of project 3, just contains things like the
;;;; list of words in various files.  Don't waste your time looking at
;;;; it.

(define (2sym x)
  (cond ((symbol? x) x)
        ((string? x) (string->symbol x))
        ((number? x) (string->symbol (number->string x)))
        (else (error x))))

(define the-web
  (make-graph (list
    (make-graph-element 
     'http://sicp.csail.mit.edu/
     '(http://sicp.csail.mit.edu/SchemeImplementations
       http://sicp.csail.mit.edu/psets)
     (map 2sym '(18:30:02 2004 6001-WEBMASTER@CSAIL.MIT.EDU 8 
                          ABOUT ALL AM AND ANNOUNCEMENTS ANSWERS ARE ASSIGNMENT 
                          ASSIGNMENTS BY CALENDAR CAN CHANGE COLLABORATIVE 
                          COMMENTS COMPUTER COPYRIGHT CURRENT DO DOCUMENTATION 
                          EDT FALL FIND FOR GENERAL GET GETTING GUIDELINES HELP
                          HOW I IN INDIVIDUAL INFORMATION INSTITUTE INTERPRETATION 
                          IS LAST LECTURE MASSACHUSETTS ME MICROQUIZZES MODIFIED 
                          MY NEW NOTES OCT OF ON ON-LINE ORAL OWN PAST POLICY 
                          POSTED PRESENTATIONS PREVIOUS PROBLEM PROGRAMS 
                          RECITATION RECITATIONS RECORDS RESERVED RIGHTS SCHEME 
                          SECTION SECTIONS SEND SET SETS SITE SOFTWARE STAFF
                          STRUCTURE SUBJECT TECHNOLOGY TELL TERMS THE THIS THU TO
                          UP USE WEEK WHAT WHERE WHICH WORK WRITING)))
    (make-graph-element
     'http://sicp.csail.mit.edu/SchemeImplementations
     '(http://sicp.csail.mit.edu/getting-help.html
       http://sicp.csail.mit.edu/lab-use.html
       *the-goal*)
     (map 2sym '(11:09 2004 3.1 34-501 4.0 6.001 6001-WEBMASTER@CSAIL.MIT.EDU 
            7 7.5A 95 98 A ABOUT ACCESS ADDITION ALL ALSO AN AND ANY 
            ARE ASSIGNMENTS ASSISTANTS AT ATHENA AVAILABLE BASED BE 
            BEAR BEAUTY BECAUSE BEEN BEFORE BETWEEN BUT BY CAN 
            CAPABLE CERTAIN COME COMFORT COMMENTS CONVENIENT COPY 
            COPYRIGHT COURSE CROWDED DEBUGGER DISK DISTRIBUTIONS
            DO DOCUMENTATION DONE DRSCHEME DUE EDITOR EDSCHEME EITHER
            ENJOY ETC EXTENSIONS FEBRUARY FEE FEEL FELLOW FILES FIND 
            FLOPPY FOLLOWING FOR FREE FROM GET GNU GRANT HAS HAVE HELP
            HERE HOME IDENTICAL IF IMPLEMENTATIONS IN INC INCLUDED 
            INCLUDING INSTALL INSTITUTE IS IT JUST LAB LAST LIKE LINUX 
            LOCKER LOT MAC MACHINE MASSACHUSETTS MAY MIND MODIFIED MUST 
            NEED NEWER NOT NOTE NT OBTAINED OF OFTEN OLDER ON OPTIONS 
            OR OTHER OUT OWN PAGE PARTIALLY PC PERHAPS PLATFORMS PLEASE 
            PM PREPARED PREVIOUS PREVIOUSLY PROBLEM PROGRESS REALIZE 
            REPRODUCE REQUIRES RESERVED RETURN RICE RIGHTS ROOM ROOT 
            RUN RUNNING SAVE SCENIC SCHEME SCHEMERS SEE SEMESTERS SEND 
            SETS SEVERAL SHOULD SINCE SITE SMALL SOMEONE SPRING STAFF 
            STUDENTS SUGGEST SUPPORTED SYSTEM SYSTEMS TECHNOLOGY TESTED 
            THAN THAT THE THEM THERE THESE THIS TIME TO TOOK TRANSFERRING
            TRY UNIVERSITY UNIX UNSUPPORTED UPDATE USE USED USING VERSION
            VERSIONS VERSON VERY VIRTUALLY WAIVERS WANT WARNED WE WEB 
            WHERE WHO WILL WINDOWS WITH WORK WORKSTATIONS WOULD YOU YOUR)))
    (make-graph-element
     'http://sicp.csail.mit.edu/psets
     '()
     (map 2sym '(0 1 15 2004 2 20 23:32:29 28 3 4 5 6.001
        6001-WEBMASTER@CSAIL.MIT.EDU 98 A ABOUT ALL ALSO AND ARE AS 
        ASSIGNMENTS ATHENA AVAILABLE BETWEEN BOTH BY CAN COLLABORATIVE 
        COMMENTS COPYRIGHT DISTRIBUTED EDT FALL FILES FOR FORMAT GET 
        GHOSTVIEW HELP HERE HOME HOW HTML I IN INSTITUTE IS LAB LAST 
        LECTURE LOCKER MASSACHUSETTS MODIFIED MY OCT OF ON PAGE POLICY 
        POSTED POSTSCRIPT PRINTING PROBLEM REQUIRES RESERVED RETURN 
        RIGHTS SCREEN SEND SEPT SET SETS SHOULD SITE SOLUTIONS SUCH 
        TECHNOLOGY THE THEY THIS THU TO TRANSFER TUESDAYS UP VIEWER
        VIEWING WEB WHAT WHERE WHICH WITH WORK WRITE)))
    (make-graph-element
     'http://sicp.csail.mit.edu/getting-help.html
     '(http://sicp.csail.mit.edu/
       http://sicp.csail.mit.edu/SchemeImplementations)
     (map 2sym '(09:38:18 1 10 2004 2 23 24 339-0052 4 5 6 6.001 6001-HELP@MIT.EDU
               6001-WEBMASTER@CSAIL.MIT.EDU 8 947-2394 98 A ABLE ABOUT 
               ADJUSTING ADMINISTRATIVE ADVANTAGE ALL ALSO AM AN AND 
               ANY ARE AS ASSISTANTS AT ATTENTION BE BEEPER BEING BROUGHT
               BY CAN CANNOT CELL COMMENTS COMPUTER COPYRIGHT COURSE 
               CURRENTLY DAY DEMAND DISCUSSION DOES DONE DURING DUTY
               EARLY EDT EDUCATION EMAIL FALL FEEL FOLLOWS FOR FORUM 
               FRIDAY GET GETTING GRIPE HAS HAVE HELP HERE HOME HOMEWORK
               HOURS HOW IF IN INFORMATION INSTALL INSTITUTE INSTRUCTOR 
               IS IT LAB LAST LECTURERS LINE LOST MASSACHUSETTS MIDNIGHT
               MIDNITE MIGHT MINORITY MODIFIED MONDAY NATURE NEED NIGHT
               NOT OF OFFICE ON OPEN OPERATES OR OTHER PAGE PERSONAL 
               PHONE PHONING PLEASE PM PROBLEM PROBLEMS PROGRAM REACH
               RECITATION REQUEST RESERVED RESPONSE REST RETURN RIGHTS 
               SATURDAY SCHEME SCREAMS SECRETARY SEE SEMESTER SEND SEP
               SET SETUP SHOULD SITE SOME SPECIFIC STAFFED STAFFING 
               START STATEMENT STUDENT SUNDAY TECHNOLOGY THAT THE THESE
               THINGS THIS THURSDAY TO TOUCH TRY TUESDAY TUTOR TUTORING
               UNDERSTAND UNTIL WAIT WAY WE WED WEDNESDAY WHICH WILL
               WITH YOU YOUR)))
    (make-graph-element
     'http://sicp.csail.mit.edu/lab-use.html
     '()
     (map 2sym '(1 2004 2 24 34-501 4:33 6.001 6001-WEBMASTER@CSAIL.MIT.EDU 7 8 A
        ABLE ABOUT ACCESSIBLE ADDITIONAL AFTER ALL ALLOWING ALSO AM AN 
        AND ANY APPRECIATED ARE ARRANGED AS ASSISTANT AT BE BETWEEN 
        BOSTON BROUGHT BY CAB CAMPUS CAREFUL CAUTION CLASSES CLEAN CODE
        COMMENTS COMMON COMPONENTS CONSIDER CONSIDERATION CONTACT 
        COOPERATION COPYRIGHT CORRIDOR DAY DAYS DETAILS DO DOING
        DOORS DRINK DURING EDWIN ESCORT ESPECIALLY EXERCISE EXPERIMENT 
        EXTEND FEBRUARY FOLLOWING FOOD FOR FRATS FUTURE GETTING GO 
        GREATLY HAVE HERE HOME HOURS HOWEVER IF IN INFORMATION INNER 
        INSTITUTE INSTRUMENT INTO IS ISSUES KEYBOARDS LAB LABORATORY 
        LAST LATE LEADING LIVE LOOK MACHINES MANUAL MASSACHUSETTS
        MIDNIGHT MODIFIED MUST NEAR NEED NIGHT NOT NOTE OF OFF ON ONE 
        OPEN OPERATION OTHER OUT OUTER PAGE PANIC PAST PATROL PERSONAL
        PLEASE PM POLICY PROBLEM PROVIDED REMEMBER RESERVED
        RESPONSIBILITY RETURN RETURNING RIDE RIGHTS RIVER ROOM SAFE
        SAFETY SCHEME SECOND SEE SEND SENSE SET SHOW SIDE SITE SMOOTHLY
        SO SPELLED STAFFED STARTED SUCH TAKING TECHNOLOGY TERM THAT 
        THE THEM THINGS THIS TIME TO UP USE USING WE WEEK WILL WITH 
        WORKING YOU YOUR YOURSELF ))))))

(define *all-words*
  (list->vector 
   (map 2sym 
        '(0 09:38:18 1 10 11:09 15 18:30:02 2004 2 20 23 23:32:29
       24 28 3 3.1 339-0052 34-501 4 4.0 4:33 5 6 6.001
       6001-HELP@MIT.EDU 6001-WEBMASTER@CSAIL.MIT.EDU 7 7.5A 8 947-2394
       95 98 A ABLE ABOUT ACCESS ACCESSIBLE ADDITION ADDITIONAL
       ADJUSTING ADMINISTRATIVE ADVANTAGE AFTER ALL ALLOWING ALSO AM
       AN AND ANNOUNCEMENTS ANSWERS ANY APPRECIATED ARE ARRANGED AS
       ASSIGNMENT ASSIGNMENTS ASSISTANT ASSISTANTS AT ATHENA
       ATTENTION AVAILABLE BASED BE BEAR BEAUTY BECAUSE BEEN BEEPER
       BEFORE BEING BETWEEN BOSTON BOTH BROUGHT BUT BY CAB CALENDAR
       CAMPUS CAN CANNOT CAPABLE CAREFUL CAUTION CELL CERTAIN
       CHANGE CLASSES CLEAN CODE COLLABORATIVE COME COMFORT COMMENTS
       COMMON COMPONENTS COMPUTER CONSIDER CONSIDERATION CONTACT
       CONVENIENT COOPERATION COPY COPYRIGHT CORRIDOR COURSE CROWDED
       CURRENT CURRENTLY DAY DAYS DEBUGGER DEMAND DETAILS DISCUSSION
       DISK DISTRIBUTED DISTRIBUTIONS DO DOCUMENTATION DOES DOING
       DONE DOORS DRINK DRSCHEME DUE DURING DUTY EARLY EDITOR
       EDSCHEME EDT EDUCATION EDWIN EITHER EMAIL ENJOY ESCORT
       ESPECIALLY ETC EXERCISE EXPERIMENT EXTEND EXTENSIONS FALL
       FEBRUARY FEE FEEL FELLOW FILES FIND FLOPPY FOLLOWING FOLLOWS
       FOOD FOR FORMAT FORUM FRATS FREE FRIDAY FROM FUTURE GENERAL
       GET GETTING GHOSTVIEW GNU GO GRANT GREATLY GRIPE GUIDELINES
       HAS HAVE HELP HERE HOME HOMEWORK HOURS HOW HOWEVER HTML I
       IDENTICAL IF IMPLEMENTATIONS IN INC INCLUDED INCLUDING
       INDIVIDUAL INFORMATION INNER INSTALL INSTITUTE INSTRUCTOR
       INSTRUMENT INTERPRETATION INTO IS ISSUES IT JUST KEYBOARDS
       LAB LABORATORY LAST LATE LEADING LECTURE LECTURERS LIKE LINE
       LINUX LIVE LOCKER LOOK LOST LOT MAC MACHINE MACHINES MANUAL
       MASSACHUSETTS MAY ME MICROQUIZZES MIDNIGHT MIDNITE MIGHT MIND
       MINORITY MODIFIED MONDAY MUST MY NATURE NEAR NEED NEW NEWER
       NIGHT NOT NOTE NOTES NT OBTAINED OCT OF OFF OFFICE OFTEN
       OLDER ON ON-LINE ONE OPEN OPERATES OPERATION OPTIONS OR ORAL
       OTHER OUT OUTER OWN PAGE PANIC PARTIALLY PAST PATROL PC
       PERHAPS PERSONAL PHONE PHONING PLATFORMS PLEASE PM POLICY
       POSTED POSTSCRIPT PREPARED PRESENTATIONS PREVIOUS PREVIOUSLY
       PRINTING PROBLEM PROBLEMS PROGRAM PROGRAMS PROGRESS PROVIDED
       REACH REALIZE RECITATION RECITATIONS RECORDS REMEMBER
       REPRODUCE REQUEST REQUIRES RESERVED RESPONSE RESPONSIBILITY
       REST RETURN RETURNING RICE RIDE RIGHTS RIVER ROOM ROOT RUN
       RUNNING SAFE SAFETY SATURDAY SAVE SCENIC SCHEME SCHEMERS
       SCREAMS SCREEN SECOND SECRETARY SECTION SECTIONS SEE SEMESTER
       SEMESTERS SEND SENSE SEP SEPT SET SETS SETUP SEVERAL SHOULD
       SHOW SIDE SINCE SITE SMALL SMOOTHLY SO SOFTWARE SOLUTIONS
       SOME SOMEONE SPECIFIC SPELLED SPRING STAFF STAFFED STAFFING
       START STARTED STATEMENT STRUCTURE STUDENT STUDENTS SUBJECT
       SUCH SUGGEST SUNDAY SUPPORTED SYSTEM SYSTEMS TAKING
       TECHNOLOGY TELL TERM TERMS TESTED THAN THAT THE THEM THERE
       THESE THEY THINGS THIS THU THURSDAY TIME TO TOOK TOUCH
       TRANSFER TRANSFERRING TRY TUESDAY TUESDAYS TUTOR TUTORING
       UNDERSTAND UNIVERSITY UNIX UNSUPPORTED UNTIL UP UPDATE USE
       USED USING VERSION VERSIONS VERSON VERY VIEWER VIEWING
       VIRTUALLY WAIT WAIVERS WANT WARNED WAY WE WEB WED WEDNESDAY
       WEEK WHAT WHERE WHICH WHO WILL WINDOWS WITH WORK
       WORKING WORKSTATIONS WOULD WRITE WRITING YOU YOUR YOURSELF))))

(define *random-web-debugging* #f)
(define (make-random-web size guarantee-path-to-all-nodes?)
  (define (->string obj)
    (if (symbol? obj)
        (symbol->string obj)
        (number->string obj)))
  (define (choose n out-of)
    (let loop ((numbers '())
               (to-go n))
      (if (zero? to-go)
          numbers
          (let ((choice (random out-of)))
            (if (memv choice numbers)
                (loop numbers to-go)
                (loop (cons choice numbers)
                      (- to-go 1)))))))
  (if (> size 200)
      (error "200 nodes is the maximum..."))
  (let ((n-total-names (vector-length *all-words*)))
    (if *random-web-debugging* (write-line "Choosing node names..."))
    (let ((node-names
           (map (lambda (n)
                  (string->symbol
                   (string-append
                    "http://sicp.csail.mit.edu/"
                    (->string
                     (vector-ref *all-words* n)))))
                (choose (- size 1) n-total-names)))
          (*nodes* '())
          (size (- size 1)))
      (define (adjoin entry list)
        (if (memq entry list)
            list
            (cons entry list)))
      (define (make-node name)
        (let ((exits (choose (min 10 (random size)) size))
              (words (choose (+ 50 (random 200)) n-total-names)))
          (if *random-web-debugging*
              (write-line (list name (length exits) (length words))))
          (list name
                (let ((random-exits
                       (map (lambda (n) (list-ref node-names n))
                            exits)))
                  (if (and (not (null? *nodes*))
                           guarantee-path-to-all-nodes?)
                      (adjoin (car
                               (list-ref *nodes* (random (length *nodes*))))
                              random-exits)
                      random-exits))
                (sort
                 (map (lambda (n) (vector-ref *all-words* n))
                      words)
                 (lambda (a b)
                   (string<? (->string a)
                             (->string b)))))))
      (define (make-node! name)
        (let ((node (make-node name)))
          (set! *nodes* (cons node *nodes*))))
      (if *random-web-debugging* (write-line "creating nodes..."))
      (for-each make-node! node-names)
      (make-node! '*start*)
      (make-graph (map (lambda (node)
                         (make-graph-element (car node)
                                           (cadr node)
                                           (caddr node)))
                       *nodes*)))))

(define (generate-random-web size)
  (make-random-web size #T))

; (generate-random-web 3)


