POV-Ray : Newsgroups : povray.off-topic : Reflections on employment : Re: Reflections on employment Server Time
28 Jul 2024 20:19:48 EDT (-0400)
  Re: Reflections on employment  
From: Warp
Date: 2 Dec 2012 11:11:16
Message: <50bb7da4@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> wrote:
> 1) You can figure out how to split a string and parse it into integers.

In this particular case I wouldn't split it at all, but parse the ints
directly from the string (which is quite easy to do since they are
whitespace-separated.)

Incidentally, there aren't any "string splitting" functions in C++ per se
(unless you count strtok() as being one.) If you literally need to create
a bunch of substrings from a given strings, there's no easier way than to
simply write the loop explicitly. (As much as it pains me to admit it,
parsing is not the forte of the C++ standard library, and it sometimes can
be a burden.)

In this case, however, it's just easier to parse the ints directly from the
input string, with no splitting or tokenization. (Basically there would be
two ways of doing that: Either use a stringstream, or use std::strtol() in
a loop. With a stringstream you could get fancy and use an input iterator
and call a standard algorithm to read the ints, thus eliding having to write
an explicit loop. If you want efficienty, though, std::strtol() is the
better choice, but it's more low-level.)

> 2) You can sort the result.

I can't imagine a programming language that doesn't offer sorting directly.
Even standard C offers such a function, and that's saying quite a lot.
In most languages it should be a one-liner (except in C, of course.)

If using the standard sorting function is disallowed for the purpose of
the exercise, then it becomes quite an academic question in itself. It
becomes a question of whether it needs to be efficient or short. A simple
insertion sort is a four-liner (I count each main element of the algorithm
as one line of code), but it's slow with large amounts of data. Faster
algorithms are harder to implement.

> > I assume there's an at least as easy way of doing it in C#, but since
> > I don't know the language I would fail the test.

> At this point, we're not even asking for correct class or method names. 
> Just something that looks like vaguely valid C# syntax and has logic 
> which isn't obviously gibberish.

I don't know enough C# to make it even look like it were. Unless C#
resembles a lot C++ (which it probably does.) :)

-- 
                                                          - Warp


Post a reply to this message

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