POV-Ray : Newsgroups : povray.off-topic : Unexpected Server Time
28 Jul 2024 20:31:58 EDT (-0400)
  Unexpected (Message 21 to 30 of 30)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Orchid Win7 v1
Subject: Re: Unexpected
Date: 18 Aug 2013 10:44:35
Message: <5210ddd3$1@news.povray.org>
>>>> But you can phrase that as
>>>
>>>>      return x ? x : -x;
>>>
>>> No, you can't.
>>>
>>> Don't blame others for doing mistakes if you are doing them yourself. ;)
>
>> The guy took about 6 minutes to come up with the answer illustrated. My
>> problem was in only spending 6 seconds. :-/
>
> The problem is that the answer above doesn't work.

Yes, because I typed it too fast. What I meant to say was

   return (x >= 0) ? x : -x;

which works as expected.


Post a reply to this message

From: Samuel Benge
Subject: Re: Unexpected
Date: 18 Aug 2013 15:25:00
Message: <web.52111f00825e3e9f51343230@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> wrote:
> On 17/08/2013 08:15 PM, Samuel Benge wrote:
> > return x*(1-2*(x<0));
>
> Well, I mean, the "obvious" way is
>
>    if (x<0) return -x; else return x;

Obviously.

The method I posted isn't the "scariest" or "craziest," I'll admit. It would be
hard to beat the job applicants' answers, what with their hapless ingenuity and
all.

> > Thanks for the laughs, btw :) When Haskell isn't the main subject, you're
> > actually pretty funny ;)
>
> If you wanted to find crazy ways to do this in Haskell, you would have
> some pretty scary options available... ;-)

If you're trying to convince me Haskell is somehow worth my time, you're not
succeeding :-P


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Unexpected
Date: 18 Aug 2013 17:26:24
Message: <52113c00$1@news.povray.org>
>> If you wanted to find crazy ways to do this in Haskell, you would have
>> some pretty scary options available... ;-)
>
> If you're trying to convince me Haskell is somehow worth my time, you're not
> succeeding :-P

Nah, I've pretty much given up on anybody ever believing that one.


Post a reply to this message

From: scott
Subject: Re: Unexpected
Date: 19 Aug 2013 05:10:23
Message: <5211e0ff$1@news.povray.org>
> On this day, the applicant came up with this:
>
>    int abs(int input)
>    {
>      int value = 0;
>      for (int n = input; n != 0; n++)
>      {
>        value++;
>      }
>      return value;
>    }

That's a pretty epic fail. The rest of the interview must have been fun :-)


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Unexpected
Date: 19 Aug 2013 13:50:21
Message: <52125add$1@news.povray.org>
On 19/08/2013 10:10 AM, scott wrote:
>> On this day, the applicant came up with this:
>>
>> int abs(int input)
>> {
>> int value = 0;
>> for (int n = input; n != 0; n++)
>> {
>> value++;
>> }
>> return value;
>> }
>
> That's a pretty epic fail.

As I say, the impressive thing is that it's a correct (yet inefficient) 
implementation of negate().

> The rest of the interview must have been fun :-)

My boss was particularly amused by the time the guy said he read 
something about design patterns, and when we asked which book, he 
couldn't remember, but he said it was "the one with the Singleton 
pattern in it".

When asked for an example of a design pattern, he fumblingly described 
something which sounded exactly like a switch block.


Post a reply to this message

From: Warp
Subject: Re: Unexpected
Date: 19 Aug 2013 15:01:16
Message: <52126b7c@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> wrote:
> > That's a pretty epic fail.

> As I say, the impressive thing is that it's a correct (yet inefficient) 
> implementation of negate().

Out of curiosity, I wanted to see what gcc would produce from that code
(when written in C++). In other words this:

//-----------------------------------------
int a(int input)
{
    int value = 0;
    for(int n = input; n != 0; ++n)
        ++value;
    return value;
}
//-----------------------------------------

It produces this, in asm:

//-----------------------------------------
.LFB0:
        .cfi_startproc
        movl    %edi, %edx
        xorl    %eax, %eax
        negl    %edx
        testl   %edi, %edi
        cmovne  %edx, %eax
        ret
        .cfi_endproc
//-----------------------------------------

If we "disassemble" that back to C++, it's basically equivalent to:

//-----------------------------------------
int a(int input)
{
    return input == 0 ? 0 : -input;
}
//-----------------------------------------

For some reason gcc produces a needless test against zero, but
otherwise it's rather impressive that it got rid of the loop completely.

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Unexpected
Date: 19 Aug 2013 15:33:57
Message: <52127325@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> If we "disassemble" that back to C++, it's basically equivalent to:

> //-----------------------------------------
> int a(int input)
> {
>     return input == 0 ? 0 : -input;
> }
> //-----------------------------------------

Btw, clang is able to optimize it to an outright "return -input;"

-- 
                                                          - Warp


Post a reply to this message

From: Orchid Win7 v1
Subject: Re: Unexpected
Date: 19 Aug 2013 17:05:03
Message: <5212887f$1@news.povray.org>
On 19/08/2013 08:01 PM, Warp wrote:
> If we "disassemble" that back to C++, it's basically equivalent to:
>
> //-----------------------------------------
> int a(int input)
> {
>      return input == 0 ? 0 : -input;
> }
> //-----------------------------------------
>
> For some reason gcc produces a needless test against zero, but
> otherwise it's rather impressive that it got rid of the loop completely.

That *is* pretty impressive, actually... I wonder how on Earth it 
figures that out. I doubt anybody would have put a special case into the 
compiler just for this, so I wonder how it figures it out...


Post a reply to this message

From: scott
Subject: Re: Unexpected
Date: 20 Aug 2013 10:33:16
Message: <52137e2c$1@news.povray.org>
>> int abs(int input)
>>> {
>>> int value = 0;
>>> for (int n = input; n != 0; n++)
>>> {
>>> value++;
>>> }
>>> return value;
>>> }
>>
>> That's a pretty epic fail.
>
> As I say, the impressive thing is that it's a correct (yet inefficient)
> implementation of negate().

Yes, there must be a prize for that somewhere, but presumably not one 
that involves working at your company :-) I wonder what would have 
happened if you'd asked him to implement an "add" function...?


Post a reply to this message

From: clipka
Subject: Re: Unexpected
Date: 20 Aug 2013 11:30:46
Message: <52138ba6@news.povray.org>
Am 20.08.2013 16:33, schrieb scott:
>>> int abs(int input)
>>>> {
>>>> int value = 0;
>>>> for (int n = input; n != 0; n++)
>>>> {
>>>> value++;
>>>> }
>>>> return value;
>>>> }
>>>
>>> That's a pretty epic fail.
>>
>> As I say, the impressive thing is that it's a correct (yet inefficient)
>> implementation of negate().
>
> Yes, there must be a prize for that somewhere,

http://www.ioccc.org/

(Okay, this is for C code, not C#, but it should be easy enough to port 
the function)


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.