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
help please....
thx so much....
Can anyone help me? [atomic-count list]
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.
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.
Re: Can anyone help me? [atomic-count list]
For example like this:
where flatten is http://rosettacode.org/wiki/Flatten_a_list#Common_Lisp.
Another solution is:
If it's really homework then I trust you that you exert some effort.
Code: Select all
(defun atomic-count (list)
(length (flatten list)))
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))))
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.
Re: Can anyone help me? [atomic-count list]
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?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
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p
Currently I'm planning a Scheme compiler :p