Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 293 294 [295] 296 297 ... 796

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

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4410 on: May 16, 2013, 08:03:42 am »

Doing a Fibonacci problem.

I think it needs to be a little more efficient >.>
I've been waiting for a few minutes now and I only have 5 minutes to upload the answer ;_;

edit: negative rabbits DDDD:
« Last Edit: May 16, 2013, 08:06:57 am by Dutchling »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4411 on: May 16, 2013, 08:11:18 am »

Poor negative rabbits...  :-[
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4412 on: May 16, 2013, 08:11:34 am »

Dutchling: A big hint is that you should store Fibonacci numbers you've already found in some sort of dictionary. It make it much much faster at the cost of memory.
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

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4413 on: May 16, 2013, 08:15:57 am »

I'll do that once i get rid of the negative rabbits :D
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4414 on: May 16, 2013, 11:17:07 am »

Dutchling: A big hint is that you should store Fibonacci numbers you've already found in some sort of dictionary. It make it much much faster at the cost of memory.
Hooray for Dynamic Programming!
(Which you should never use for the first 20 or so problems at Project Euler unless you want to really over do them.)
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4415 on: May 17, 2013, 12:40:45 am »

ϕx-1/√5 maps really closely to the fibonacci sequence, btw.

Could be useful for something or other :P

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4416 on: May 17, 2013, 12:58:02 am »

Dutchling: A big hint is that you should store Fibonacci numbers you've already found in some sort of dictionary. It make it much much faster at the cost of memory.
Hooray for Dynamic Programming!
(Which you should never use for the first 20 or so problems at Project Euler unless you want to really over do them.)
I don'tthink it's called dynamic programming.... Isn't it called optimization? Mapping Fibonacci numbers have little to do with solving a problem, just making it faster.

Also, I suspect Dutchling isn't doing Euler.. O_o

Putnam: what's ϕ?
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

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4417 on: May 17, 2013, 02:45:35 am »

ϕx/√5 maps really closely to the fibonacci sequence, btw.
Fix'd the exponent (because F0=0 and F1=1)
Skyrunner, ϕ = (1+√5)/2, and if you want a totally exact formula (that also works for negative indices), use Fn = (ϕn-(-ϕ)-n)/√5.
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4418 on: May 17, 2013, 07:47:51 am »

I don'tthink it's called dynamic programming.... Isn't it called optimization? Mapping Fibonacci numbers have little to do with solving a problem, just making it faster.
http://en.wikipedia.org/wiki/Dynamic_programming

Dynamic Programming is an algorithm design paradigm for problems with overlapping subproblems and optimal substructure (that is, combining optimal solutions to subprobems creates the optimal solution for the overall problem.)
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #4419 on: May 17, 2013, 09:23:47 am »

I don'tthink it's called dynamic programming.... Isn't it called optimization? Mapping Fibonacci numbers have little to do with solving a problem, just making it faster.
http://en.wikipedia.org/wiki/Dynamic_programming

Dynamic Programming is an algorithm design paradigm for problems with overlapping subproblems and optimal substructure (that is, combining optimal solutions to subprobems creates the optimal solution for the overall problem.)
:c
That article makes me sad because I have to compete in the Seoul Informatics Olympiad and I have no idea how that works and how to solve common informatics puzzles.

Sky = doomed
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

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4420 on: May 17, 2013, 10:42:26 am »

Dutchling: A big hint is that you should store Fibonacci numbers you've already found in some sort of dictionary. It make it much much faster at the cost of memory.
Well, if understand why this works with Fibonacci numbers and can generalize it to other similar problems, you should be fine.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4421 on: May 18, 2013, 05:52:11 pm »

I was diagnosing why something wasn't working:

Code: [Select]
const char* shaderSourceVertex = &shaderSourceVertex[0];
What. How did that even...
Logged

Puzzlemaker

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4422 on: May 21, 2013, 06:37:21 am »

I was diagnosing why something wasn't working:

Code: [Select]
const char* shaderSourceVertex = &shaderSourceVertex[0];
What. How did that even...

Looking at that line is like bad code inception.  There are so many levels, each more WTF then the last.  The const is what gets me, though.
Logged
The mark of the immature man is that he wants to die nobly for a cause, while the mark of the mature man is that he wants to live humbly for one.

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4423 on: May 21, 2013, 06:48:45 am »

[Python]

I have a problem with making a function inside a class make another instance (not sure what they are called again) of a another class.

It doesn't work if I just copy my normal code for making another class-thing with some 'self.' in front of it :v
Logged

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4424 on: May 21, 2013, 07:20:21 am »

A simple example with both classes defined in the same file.

This is Python 2, so you may need to update it for 3 if that's what you use.

Code: [Select]
class Foo:
    def __init__(self, x, y):
        self.x, self.y = x, y

    def __str__(self):
        return 'Foo instance: x=%s, y=%s' % (self.x, self.y)

class Bar:
    def __init__(self):
        self.foo = Foo(1, 2)

if __name__ == '__main__':
    b = Bar()
    print b.foo
    print b.foo.x
    print b.foo.y

Re-reading your post leads me to believe the problem may be something else. Do you have a snippet of what you did?
Logged
Pages: 1 ... 293 294 [295] 296 297 ... 796