From: justinhj on
On Feb 28, 11:31 am, "justinhj" <justi...(a)gmail.com> wrote:
> On Feb 28, 10:51 am, "justinhj" <justi...(a)gmail.com> wrote:
>
>
>
> > On Feb 27, 11:31 pm, job-271842...(a)craigslist.org wrote:
>
> > > justinhj wrote:
> > > > (defun multiple(x n)
> > > > (= 0 (mod x n)))
>
> > > > (defun output-multiple(x n str)
> > > > (if (and (multiple x n) (princ str))
> > > > 1
> > > > 0))
>
> > > > (defun fizzbuzz(n)
> > > > (loop for x from 1 to n do
> > > > (if (> (+ (output-multiple x 3 "fizz") (output-multiple x 5
> > > > "buzz")) 0)
> > > > (format t "~%"))))
>
> > > Hmm.. this doesn't seem to work.
>
> > > [1]> (defun multiple(x n)
> > > (= 0 (mod x n)))
> > > MULTIPLE
> > > [2]>
> > > (defun output-multiple(x n str)
> > > (if (and (multiple x n) (princ str))
> > > 1
> > > 0))
> > > OUTPUT-MULTIPLE
> > > [3]>
> > > (defun fizzbuzz(n)
> > > (loop for x from 1 to n do
> > > (if (> (+ (output-multiple x 3 "fizz") (output-multiple x 5
> > > "buzz")) 0)
> > > (format t "~%"))))
> > > FIZZBUZZ
> > > [4]> (fizzbuzz 12)
> > > fizz
> > > buzz
> > > fizz
> > > fizz
> > > buzz
> > > fizz
> > > NIL
> > > [5]>
>
> > Unless I'm misunderstanding something what doesn't work? The output is
> > correct.
>
> > Justin
>
> I'm not having much luck trying to make it elegant and concise but I
> quite like this recursive version...
>
> (defun fizzbuzz2(n)
> (labels ((fizzbuzz-rec (current last fizz buzz)
> (let ((output nil))
> (if (= 0 fizz)
> (push "fizz" output))
> (if (= 0 buzz)
> (push "buzz" output))
> (if output
> (format t "~{~a~}~%" output))
> (unless (= current last)
> (fizzbuzz-rec (1+ current) last (mod (1-
> fizz) 3) (mod (1- buzz) 5))))))
> (fizzbuzz-rec 1 n (1- 3) (1- 5))))
>
> CL-USER> (fizzbuzz2 15)
> fizz
> buzz
> fizz
> fizz
> buzz
> fizz
> buzzfizz
>
> Justin

Note: just realised you have to swap the order of the buzz print with
the fizz print to get the correct output ;)

Justin

From: Tim Bradshaw on
On 2007-02-28 17:38:48 +0000, Richard M Kreuter <kreuter(a)progn.net> said:
>
> I think you mean "~&~[Fizz~:;~]~[Buzz~:;~D~]~%" right?

Probably, yes.

>
> (dotimes (i 100)
> (format t "~[~[~3@*~A~A~:;~3@*~A~]~:;~[~4@*~A~:;~D~]~]~%"
> (mod i 3) (mod i 5) i "Fizz" "Buzz"))
>

Really good, yes. Almost impossible to work out what it does. The
perfectionist in me would insist on

"~&~[~[~3@*~A~A~:;~3@*~A~]~:;~[~4@*~A~:;~D~]~]~%"

- you do actually want that so you know it always starts a line
properly, apart from being an extra bit of squigglines. But that's
trivial compared to the main drag of it.

I'm unhappy about the explicit looping however. I can see two
solutions to this:

* something really gratuitous involving GO
* something equally gratuitous involving a lot of LAMBDAs.

I think I may be too rusty to write this, but something like:

(defun fb (n)
((lambda (c p)
(funcall c c p 1)
(lambda (c p i)
(or (> i n)
(funcall p c p i)))
(lambda (c p i)
(format t "~[~[~3@*~A~A~:;~3@*~A~]~:;~[~4@*~A~:;~D~]~]~%"
(mod i 3) (mod i 5) i "Fizz" "Buzz")
(funcall c c p (1+ i))))))

(I should point out that I don't have a CL on the system I'm writing this.)

--tim

From: Tim Bradshaw on
On 2007-02-28 06:31:05 +0000, rpw3(a)rpw3.org (Rob Warnock) said:

> This one is both efficient -- *no* MOD calls at all! --
> *and* so ugly only a parent could love it: ;-} ;-}

I missed this. It's also really good. I think a combination of this
and (a working version of) the one I posted just now ought to be
something to be really proud of.

--tim

From: Ken Tilton on


Frank Buss wrote:
> Ken Tilton wrote:
>
>
>>You refer of course to the Cello code to create a 3-D oblong button of
>>variable thickness with rounded corners of variable radius:
>
>
> Yes, that's really ugly :-) Did you thought about using your dataflow
> paradigm to create graphics?

No. This will shock everyone and have Mastenbrook calling me a liar, but
my use of Cells does not violate Tilton's Law, viz., "Never use anything
for everything."

> Something similar would be to use higher order
> functions and combinators.

Look, I'm not smart like you guys, just a simple application programmer.
That is how I ended up working on paper and drawing pictures.

> The code below creates buttons like this:
>
> http://www.frank-buss.de/tmp/buttons.png

Wow, gorgeous. I let the graphicss card to the work, but your solution
is way cool.

kt

--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom
From: Ken Tilton on


Tim Bradshaw wrote:
> On 2007-02-28 06:31:05 +0000, rpw3(a)rpw3.org (Rob Warnock) said:
>
>> This one is both efficient -- *no* MOD calls at all! --
>> *and* so ugly only a parent could love it: ;-} ;-}
>
>
> I missed this. It's also really good. I think a combination of this
> and (a working version of) the one I posted just now ought to be
> something to be really proud of.

Ok, let's take another week on this, total up the cumulative man-months
and submit it for the 5-minute interview.

kt

ps. Me, I am not starting until we get the functional requirements
cleared up. k


--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom