How would you solve this 'interview' question in D?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Jun 27 10:15:08 PDT 2013
On Thu, 27 Jun 2013 04:09:39 -0400, monarch_dodra <monarchdodra at gmail.com>
wrote:
> On Wednesday, 26 June 2013 at 21:00:42 UTC, Adam D. Ruppe wrote:
>> On Wednesday, 26 June 2013 at 20:51:35 UTC, Gary Willoughby wrote:
>>> Just for a bit of fun, I saw this question posted on reddit the other
>>> day and wondered how *you* would solve this in D?
>>
>> Since they didn't say *pure* function, I'd cheat:
>>
>> int f(int n) {
>> static bool isOddCall;
>> isOddCall = !isOddCall;
>> if(!isOddCall)
>> return -n;
>> return n;
>> }
>>
>> :P
>
> Well if you solved it *that* way, *I* wouldn't hire you :p
TBH, if working there required writing such functions, I wouldn't want to
:)
-Steve
More information about the Digitalmars-d-learn
mailing list