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

Pages: 1-

Help?

Name: Anonymous 2012-10-14 0:12

Could someone please explain why these two codes give different results for the 'Grade' output. In the first code, it will give me all F's if i have an average of an F grade first. But the second code will return the correct Grade values if I use the same inputs.

The values I am using in both codes:
testOne: 50, 80, 70, 100
testTwo: 50, 80, 70, 100

Why is the code with specific array values {'A', 'B', 'C', 'F'} giving me the incorrect grade outputs?

Isn't saying average[i] = letterGrade[0], the same thing as assigning average[i] = 'A', if letterGrade[0] were to equal 'A'?

http://ideone.com/mSwRt

http://ideone.com/vI6ZU

Name: Anonymous 2012-10-14 0:19

Back to /g/ please

Name: Anonymous 2012-10-14 0:23

>>2
le HURRRRR

Name: Anonymous 2012-10-14 0:37

>>3
Back to Reddit please

Name: Anonymous 2012-10-14 0:41

>>1
Are you really this dumb? You're changing `letterGrade[i]' for i in [0..3] by reading back from `letterGrade[n]' to do so. What happens when your first average is in the F range? You essentially say letterGrade[0] = letterGrade[3]. Then on later iterations you're expecting letterGrade[0] to still somehow be 'A'...

Name: Anonymous 2012-10-14 1:58

>>5
It's a fallacy to associate programming ability with intelligence. Programming in the first place is an unintelligent, uncreative, and ultimately futile activity.

Name: >>6 2012-10-14 2:27

yet at the same time it is also an art.

Name: Anonymous 2012-10-14 3:47

Java has too much boilerplate. What do text formats and command-line arguments have to do with calculating grades?
Find average: N←(+/L)÷⍴L←∊⎕
Get letter grade: (<\N∘.≥90 80 70 0)/'ABCF'

Name: Anonymous 2012-10-14 5:32

>>6
You're lying out of your anus and you know it.

Name: Anonymous 2012-10-14 7:23

(DEFMACRO FOR-EACH-CONS (VAR LIST &REST BODY)
  (LET* ((LIST-NAME (GENSYM)))
    `(LET* ((,LIST-NAME ,LIST))
       (DO ((,VAR ,LIST-NAME))
           ((NULL ,VAR))
         ,@BODY
         (SETF ,VAR (CDR ,VAR))))))

(DEFCLASS THRESHOLD-DEF ()
  ((VALUE :INITARG VALUE :ACCESSOR VALUE)
   (UPPER-BOUND :INITARG UPPER-BOUND :ACCESSOR UPPER-BOUND)))

(DEFMETHOD DIVIDE-UPPER-BOUND ((SELF THRESHOLD-DEF) (DIVISOR NUMBER))
  (WITH-SLOTS (UPPER-BOUND) SELF
    (SETF UPPER-BOUND (/ UPPER-BOUND DIVISOR))))

(DEFMETHOD DIVIDED-UPPER-BOUND ((SELF THRESHOLD-DEF) (DIVISOR NUMBER))
  (WITH-SLOTS (VALUE UPPER-BOUND) SELF
    (MAKE-INSTANCE 'THRESHOLD-DEF
      :VALUE VALUE
      :UPPER-BOUND (/ UPPER-BOUND DIVISOR))))




(DEFCLASS THRESHOLD-LIST ()
  ((THRESHOLDS :INITARG THRESHOLDS :ACCESSOR THRESHOLDS)
   (SCALE :INITARG SCALE :ACCESSOR SCALE :INITFORM 1)))

(DEFMETHOD FACTOR ((SELF THRESHOLD-LIST))
  (WITH-SLOTS (THRESHOLDS) SELF
    (APPLY #'GCD (MAP 'LIST #'UPPER-BOUND THRESHOLDS))))

(DEFMETHOD DIVIDE-BOUNDS ((SELF THRESHOLD-LIST) (DIVISOR NUMBER))
  (WITH-SLOTS (THRESHOLDS SCALE) SELF
    (LOOP FOR THRESHOLD IN THRESHOLDS
       DO (DIVIDE-UPPER-BOUND THRESHOLD DIVISOR))
    (SETF SCALE (* SCALE DIVISOR))))

(DEFMETHOD DIVIDED-BOUNDS ((SELF THRESHOLD-LIST) (DIVISOR NUMBER))
  (WITH-SLOTS (THRESHOLDS SCALE) SELF
    (MAKE-INSTANCE 'THRESHOLD-LIST
      :THREASHOLDS (LOOP FOR THRESHOLD IN THRESHOLDS
                     COLLECT (DIVIDED-UPPER-BOUND THRESHOLD DIVISOR))
      :SCALE (* SCALE DIVISOR))))

(DEFMETHOD COMPACT-BOUNDS ((SELF THRESHOLD-LIST))
  (DIVIDE-BOUNDS SELF (FACTOR SELF)))

(DEFMETHOD COMPACTED-BOUNDS ((SELF THRESHOLD-LIST))
  (DIVIDED-BOUNDS SELF (FACTOR SELF)))

(DEFMETHOD CREATE-VALUES-ARRAY ((SELF THRESHOLD-LIST))
  (LET* ((THRESHOLDS (THRESHOLDS SELF))
         (TOP-THRESHOLD (CAR THRESHOLDS))
         (LARGEST-BOUND (UPPER-BOUND TOP-THRESHOLD))
         (VALUES-ARRAY (MAKE-ARRAY (+ LARGEST-BOUND 1))))
    (SETF (AREF VALUES-ARRAY LARGEST-BOUND) (VALUE TOP-THRESHOLD)) ;; So 100 is defined as an A
    (FOR-EACH-CONS CELL THRESHOLDS
      (LET* ((CURRENT-THRESHOLD (CAR CELL))
             (VALUE (VALUE CURRENT-THRESHOLD))
             (UPPER-BOUND (UPPER-BOUND CURRENT-THRESHOLD))
             (LOWER-BOUND (IF (NULL (CDR CELL))
                            0
                            (UPPER-BOUND (CADR CELL)))))
        (LOOP FOR I FROM LOWER-BOUND TO (- UPPER-BOUND 1)
          DO (SETF (AREF VALUES-ARRAY I) VALUE))))
    VALUES-ARRAY))

(DEFMETHOD CREATE-MAP ((SELF THRESHOLD-LIST))
  (LET* ((VALUES-ARRAY (CREATE-VALUES-ARRAY SELF))
         (SCALE (SCALE SELF)))
    (print `(grader scale is ,scale))
    (LAMBDA (KEY)
      (LET* ((DIVIDED-KEY (FLOOR (/ KEY SCALE))))
        (IF (OR (< DIVIDED-KEY 0) (>= DIVIDED-KEY (LENGTH VALUES-ARRAY)))
          NIL
          (AREF VALUES-ARRAY DIVIDED-KEY))))))



(DEFVAR *GRADE-THRESHOLD-DATA* '((A 100) (B 90) (C 80) (D 70) (F 60)))

(DEFVAR *GRADE-THRESHOLDS* (LOOP FOR DATA IN *GRADE-THRESHOLD-DATA*
                             COLLECT (MAKE-INSTANCE 'THRESHOLD-DEF 'VALUE (CAR DATA) 'UPPER-BOUND (CADR DATA))))

(DEFVAR *GRADE-THRESHOLDS-LIST* (MAKE-INSTANCE 'THRESHOLD-LIST 'THRESHOLDS *GRADE-THRESHOLDS*))

(COMPACT-BOUNDS *GRADE-THRESHOLDS-LIST*)

(DEFVAR *GRADER* (CREATE-MAP *GRADE-THRESHOLDS-LIST*))

(print `(PLEASE ENTER A SEXP LIST OF ALL PERCENTAGE SCORES FROM 0 TO 100))

(DEFVAR *SCORES* (read))

(DEFVAR *GRADES* (MAP 'LIST *GRADER* *SCORES*))

(print `(THE GRADES ARE AS FOLLOWS ,*GRADES*))

Name: Anonymous 2012-10-14 7:28

>>10

OH NO I FORGOT TO CAPITALIZE PRINT AND READ!

*COMMITS SEPUKU*

Name: Anonymous 2012-10-14 7:31

>>9

It depends on the context, but in almost every shape and form programming it redundant. In any case, it fails to be a measure of intelligence for the same reason that juggling burning coals is not a measure of intelligence.

Name: Anonymous 2012-10-14 7:45

>>12
Programming as implementation of a predefined system or monkey work in general, sure.
But programming as problem-solving, I would disagree. Although there seems to be fewer and fewer programming problems that have not already been solved thrice over.

I like to make the distiction by referring to the former definition as ``coding'' rather than ``programming''.

Name: Anonymous 2012-10-14 8:37

>>1
You've just violated the Honor Code. Congrats.

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