From: Spehro Pefhany on
On Mon, 5 May 2008 23:55:57 +0200, the renowned "Ulf Samuelsson"
<ulf(a)a-t-m-e-l.com> wrote:

>
>"nospam" <nospam(a)please.invalid> skrev i meddelandet
>news:t07n14h0inv7d48quvn4ffnu120mtdlusq(a)4ax.com...
>> andrew.nesterov(a)softhome.net wrote:
>>
>>>Implement a block that inputs either 1 or 2 and outputs the opposite:
>>>1 -> 2, 2 -> 1
>>>The author continue with three hypotetical solutions:
>>>1. A programming class instructor:
>>> if ( x == 1) x = 2;
>>> if ( x == 2) x = 1;
>>>2. A programmer:
>>> if ( x == 1) x = 2;
>>> else if ( x == 2) x = 1;
>>>3. A mathematitian:
>>> x = 3 - x;
>>
>>
>> So who writes this one?
>>
>> x = x["0\02\01"];
>>
>> --
>
>You mean:
>
>x = "\00\02\01"[x];


This one is perhaps mathematically attractive, but maybe less so for
programming:

x = (3 - cos(pi*x))/2;

- gives results of 1 or 2 for all integer inputs
- is continuous
- is differentiable
- is infinitely differentiable (smooth)





Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
speff(a)interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
From: tims next home on

"David M. Palmer" <dmpalmer(a)email.com> wrote in message
news:050520082215555636%dmpalmer(a)email.com...
> In article <fvnvpj$k6d$1(a)aioe.org>, Ulf Samuelsson <ulf(a)a-t-m-e-l.com>
> wrote:
>
>> "nospam" <nospam(a)please.invalid> skrev i meddelandet
>> news:t07n14h0inv7d48quvn4ffnu120mtdlusq(a)4ax.com...
>> > andrew.nesterov(a)softhome.net wrote:
>> >
>> >>Implement a block that inputs either 1 or 2 and outputs the opposite:
>> >>1 -> 2, 2 -> 1
>> >>The author continue with three hypotetical solutions:
>> >>1. A programming class instructor:
>> >> if ( x == 1) x = 2;
>> >> if ( x == 2) x = 1;
>> >>2. A programmer:
>> >> if ( x == 1) x = 2;
>> >> else if ( x == 2) x = 1;
>> >>3. A mathematitian:
>> >> x = 3 - x;
>> >
>> >
>> > So who writes this one?
>> >
>> > x = x["0\02\01"];
>> >
>> > --
>>
>> You mean:
>>
>> x = "\00\02\01"[x];
>
> You are insufficiently depraved.
> x = x["0\02\01"];
> works, and is perfectly valid C.

Not when working on my team, it isn't:-)

tim

>
> --
> David M. Palmer dmpalmer(a)email.com (formerly @clark.net, @ematic.com)

From: Stef on
In comp.arch.embedded,
Tom <tom(a)nospam.com> wrote:
>
> It's bad enough that network routers and cellphones have reset buttons, I just
> hope I never see the day when cars have reset buttons.

I think that hope is shared by car dealers. ;-)
Just think of the income they will loose when an owner can just press a
button to clear a erroneous warning light instead of going to the shop
and have them reset the light with a fancy 'analyzer'.

--
Stef (remove caps, dashes and .invalid from e-mail address to reply by mail)

From: CBFalconer on
Robert Adsett wrote:
>
.... snip ...
>
> Well, we really had moved away from interview questions. Even
> then though it would be instructive to see which candidates noted
> the range limitations of their approach. I was more struck not
> that some disn't note the limitation but so few did and no-one
> actually checked the input for validity or added a comment that
> the output was only valid over a certain input range.

Wrong. My suggestions ensured correct output for any input.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


** Posted from http://www.teranews.com **
From: Robert Adsett on
In article <4820FBF6.1D03B3C7(a)yahoo.com>, CBFalconer says...
> Robert Adsett wrote:
> >
> ... snip ...
> >
> > Well, we really had moved away from interview questions. Even
> > then though it would be instructive to see which candidates noted
> > the range limitations of their approach. I was more struck not
> > that some disn't note the limitation but so few did and no-one
> > actually checked the input for validity or added a comment that
> > the output was only valid over a certain input range.
>
> Wrong. My suggestions ensured correct output for any input.

It ensures a particular output. Whether it is correct or not is another
question. My reading of the problem would preclude a correct output for
any input other than 1 or 2.

Robert
** Posted from http://www.teranews.com **