## Can anyone help me? [atomic-count list]

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

### Can anyone help me? [atomic-count list]

Count atomic number program for example

(atomic-count '(c h 2 o 2))
return 5

(atomic-count '((c h 2) 3 o 2)
return 11

(atomic-count '(c 2 h 2 (o 2) 2))
return 8

T^T
thx so much....
geassking

Posts: 1
Joined: Tue Jul 03, 2012 12:22 pm

### Re: Can anyone help me? [atomic-count list]

For example like this:
Code: Select all
`(defun atomic-count (list)  (length (flatten list)))`

where flatten is http://rosettacode.org/wiki/Flatten_a_list#Common_Lisp.
Another solution is:
Code: Select all
`(defun atomic-count (list)  (loop for item in list sum       (cond ((and (listp item) (not (null item))) (atomic-count item))        (t 1))))`

If it's really homework then I trust you that you exert some effort.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.

Goheeca

Posts: 271
Joined: Thu May 10, 2012 12:54 pm

### Re: Can anyone help me? [atomic-count list]

geassking wrote:Count atomic number program for example

(atomic-count '(c h 2 o 2))
return 5

(atomic-count '((c h 2) 3 o 2)
return 11

(atomic-count '(c 2 h 2 (o 2) 2))
return 8

As far as I ca tell you really need magic because I cannot see the relationship between the arguments supplied and the returned number. Sometimes the number is added as number instead of counted as an atom but when?? Are you sure your examples are accurate?
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
sylwester

Posts: 130
Joined: Mon Jul 11, 2011 2:53 pm

### Who is online

Users browsing this forum: No registered users and 2 guests