Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 274 275 [276] 277 278 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883022 times)

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4125 on: March 06, 2013, 05:50:50 pm »

Programmers, always trying to find solutions, never trying to solve problems...
If it says anywhere on the marking criteria 'Must solve for n integers withing x time' I would be very surprised.
If you have two variations of a routine that are writable in the same time, but the first is objectively better than the second, why pick the second?
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4126 on: March 06, 2013, 05:53:04 pm »

Couldn't you do this in O(log(n)) time, instead of O(n)?


Code: (pseudocode, my C++ is nonexistant) [Select]
max(number a, number b)
    if a> b
        return a
    else
        return b
    end if
end max


max(array numbers)
    int n = length(numbers)
    case
        n == 0 -> error
        n == 1 -> return numbers(0)
        n == 2 -> return max(numbers(0), numbers(1))
        n => 3 -> return max( max(numbers(0:n/2)), numbers(array(n/2:n))))
    end case
end max
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4127 on: March 06, 2013, 05:55:40 pm »

If you have two variations of a routine that are writable in the same time, but the first is objectively better than the second, why pick the second?
Well one reason is to keep your code coherent and compliment with an open and close principle. Sometimes for good design, you have to compromise on speed a little.

Apart from that, so that you can learn how the second works.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4128 on: March 06, 2013, 05:56:30 pm »

Couldn't you do this in O(log(n)) time, instead of O(n)?


Code: (snopped) [Select]
Since every single array element is compared to, the runtime of your code is necessarily O(n). Only your recursion depth is O(log(n)), the amount of calls to max() is still O(n).
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4129 on: March 06, 2013, 05:58:31 pm »

Whelp you're right.


Edit: Screw me, of course you can't find the maximum of an array in log(n) time, since if no assumptions can be made about the array, every element needs to be checked.
Logged

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4130 on: March 06, 2013, 06:17:41 pm »

If you have two variations of a routine that are writable in the same time, but the first is objectively better than the second, why pick the second?

To maintain my artistic vision.
Some people say that it is bad form to use a GOTO to jump from inside one endless loop to inside another endless loop. I say to hell with those people! My algorithm doesn't actually do anything, okay? It represents the idea of a working algorithm, and if you small-minded traditionalist sticks-in-the-mud can't let go of your ridiculous preconceived notions of "good" and "bad" ways of doing things, you don't deserve to understand my work!
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4131 on: March 06, 2013, 06:20:31 pm »

You say that as a joke, but Perl Poetry is a real thing...

kaenneth

  • Bay Watcher
  • Catching fish
    • View Profile
    • Terrible Web Site
Re: if self.isCoder(): post() #Programming Thread
« Reply #4132 on: March 06, 2013, 07:16:28 pm »


Out of the list of numbers {0,1,1} which one is the largest? (pun slightly intended)

If you are only returning the value of the the largest integer in a set, it's easy to say the result is 1; which is fine for this basic programming exercise. But if the numbers are attributes of objects (like item prices) you're going to have to decide which one, or many to return.

This may seem excessively pedantic; but asking these kinds of questions during programming interviews is how I get employed.
Logged
Quote from: Karnewarrior
Jeeze. Any time I want to be sigged I may as well just post in this thread.
Quote from: Darvi
That is an application of trigonometry that never occurred to me.
Quote from: PTTG??
I'm getting cake.
Don't tell anyone that you can see their shadows. If they hear you telling anyone, if you let them know that you know of them, they will get you.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4133 on: March 06, 2013, 08:28:47 pm »

Isn't the textbook answer "refer to the specifications, and if not known consult a supervisor/whoeve wrote it"? XD
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4134 on: March 06, 2013, 10:11:23 pm »

If on a time limit and no answer can be found through either of the other sources, and there is not additional time for the discovery phase, establish a standard (the first input, barring information that multiple items is a valid return) and make note of it, along with filing a ticket to confirm this standard later and change this code if it no longer meets the standard.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4135 on: March 06, 2013, 10:51:04 pm »

Help ;_;
We're learning C! With Visual C++ 6.0! And the file extenctions are .cpp! I can't stand anymore ;_;

Also, USBs are blocked, files wiped daily.

I guess I could do a daily Codeblocks+gcc(?) installation. <.< But stiiill.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4137 on: March 06, 2013, 10:54:51 pm »

Highschool.
What stumps me is that my school bought thirty copies of VS 6.0 over the past three years instead of 2010, or even codeblocks.

... How? O_o
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Sirus

  • Bay Watcher
  • Resident trucker/goddess/ex-president.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4138 on: March 06, 2013, 10:56:33 pm »

Well, if it's anything like Visual Studio, you should be able to make it work by naming each file <name>.c

Spoiler: Like so (click to show/hide)
Logged
Quote from: Max White
And lo! Sirus did drive his mighty party truck unto Vegas, and it was good.

Star Wars: Age of Rebellion OOC Thread

Shadow of the Demon Lord - OOC Thread - IC Thread

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4139 on: March 06, 2013, 11:00:38 pm »

My main problem is that the UI is rather bad, and that I don't have any STL containers to play with D: Also some non-standards gotchas.
The speed of the class is so very slow...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 274 275 [276] 277 278 ... 796