Found this off slashdot. It's a mistake I see all too often in code.
http://blogs.csoonline.com/node/151
Found this off slashdot. It's a mistake I see all too often in code.
http://blogs.csoonline.com/node/151
My friend showed me what he submitted for his Intro to Programming lab in college, which is taught in scheme.
The assignment was:
A company maintains several pieces of information about its employees: their name, hourly salary, the names of projects they work on (could be several, like database, web, service), and which (other) employees they supervise. A person may work on different projects than his or her boss.
Develop a data definition and two examples of data for company employee hierarchies. The hierarchy should start with a single person (the boss). (The data for who each person supervises should be other employees, not just those employees' names.)
Provide the template for an employee hierarchy.
Write a function everyone-busy?
that consumes an
employee hierarchy and produces a boolean indicating whether every
person in the company is working on at least one project.
His solution:
;; Problem 1
;; an employee is a (make-employee string number list-of-string
;; list-of-employee)
(define-struct employee (name salary projects underlings))
;; a list-of-string is either;
;; empty, or
;; (cons string list-of-string)
;; a list-of-employee is either;
;; empty, or
;; (cons employee list-of-employee)
;; Examples
(define WebDeveloper (make-employee "Sam" 15.00 (list "web") empty))
(define WebLeadDeveloper (make-employee "Joe" 18.00 (list "web" "database") (list WebDeveloper)))
(define WebSupervisor (make-employee "John" 20.00 (list "web" "service") (list WebLeadDeveloper)))
(define WebVP (make-employee "Fred" 22.00 (list "database" "quality control") empty))
(define WebBoss (make-employee "Trogdor" 25.00 (list "management") (list WebVP WebSupervisor)))
(define WebGroup WebBoss)
(define VirtuJanitor (make-employee "The Janitor" 300.00 (list "cleaning") empty))
(define VirtuJunior (make-employee "Junior" 400.00 (list "sales" "morale officer" "security") (list VirtuJanitor)))
(define VirtuVP (make-employee "The VP of Nothing" 400.00 empty empty))
(define VirtuSavior (make-employee "The Savior" 500.00 (list "benefacting") (list VirtuVP VirtuJunior)))
(define VirtuCIO (make-employee "The CIO" 500.00 (list "magic") (list VirtuSavior)))
(define VirtuFounder (make-employee "The Founder" 750.00 (list "consulting") (list VirtuCIO RobGraves)))
(define RobGraves (make-employee "Rob Graves" 13.37 (list "design" "development" "implementation") empty))
(define Virtudyne VirtuFounder)
;; Problem 2
; ;; company-func/employee: employee -> ?
; ;; ?
; (define (dtree-func/employee anemp)
; (employee-name anemp)
; (employee-salary anemp)
; (projects-func/list (employee-projects anemp))
; (company-func/elist (employee-underlings anemp)))
;
; ;; company-func/elist: list-of-employee -> ?
; ;; ?
; (define (company-func/elist aloe)
; (cond [(empty? aloe) ]
; [(cons? aloe) (company-func/employee (first aloe))
; (company-func/elist (rest aloe))]))
;
; ;; projects-func/list: list-of-projects -> ?
; ;; ?
; (define (projects-func/list alop)
; (cond [(empty? alop) ]
; [(cons? alop) ( (first alop))
; (project-func/list (rest alop))]))
;
;; Problem 3
;; everyone-busy?: employee -> boolean
;; consumes an employee hierarchy and produces a boolean indicating
;; whether every person in the company is working on at least one project.
(define (everyone-busy? anemp)
(cond
[(empty? (employee-projects anemp)) false]
[(cons? (employee-projects anemp))
(anyone-busy? (employee-underlings anemp))]))
;; anyone-busy?: list-of-employee -> boolean
;; consumes a list-of-employee and produces a boolean indicating
;; whether every person in the company is working on at least one project.
(define (anyone-busy? aloe)
(cond [(empty? aloe) true ]
[(cons? aloe) (and (everyone-busy? (first aloe))
(anyone-busy? (rest aloe)))]))
;; Test Cases
(everyone-busy? WebGroup) "expects" true
(everyone-busy? Virtudyne) "expects" false
Will follow up with a grade in a few days. Wonder if the professor is familiar with Virtudyne?
Darwin, Newton, Faulkner.
I'm going to go against the grain here. I actually think it's a good question, especially for smaller companies. It gives you an idea of the candidates philosophies and veiws which are very important, especially if that candidate is going to be making decisions. Sure, maybe it's politically incorrect, and maybe it could lead to discrimination suits, but in a perfect world I'd ask everyone I could this question, but more importantly, I'd follow it up with "why?"
This discussion on the GameDev AI forums is so wtf that I wasn't quite sure what either participant was talking about - except that they seemed to be designing an AI based on events in an obscure comic book. It's a long discussion, but it's worth the read as it just gets crazier and crazier.
An excerpt:
"The design now will be based on a neural network, with threading. Only instead of a number being told to represent a neural path, an emotion will represent it."
The link: http://www.gamedev.net/community/forums/topic.asp?topic_id=430670