Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 378 379 [380] 381 382 ... 796

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

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5685 on: April 15, 2014, 08:44:48 am »

As long as you stick to the stuff you perfectly understand, you should be perfectly fine.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5686 on: April 15, 2014, 10:55:09 pm »

So, log(9999999!) takes more than 1 hour in Python (it's still working the CPU at 100%), but log1+log2+...+log9999999 takes 1.177 seconds. O.o

I guess the latter is how Wolfram Alpha calculates log (9999999!)? :P
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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5687 on: April 15, 2014, 11:05:35 pm »

9999999! would be very time-consuming to compute, which, due to order of operations, would be computed first. Computing logs of numbers is trivial.

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5688 on: April 16, 2014, 11:37:18 am »

And moreover, space. Your average value from that sequence of multiplies adds an additional 6 or so powers of 10; and you're doing 9999999 of them. Throwing out any question of computation or precision, your number's exponent value needs to store representations up to around 10^60000000. I've not used Python enough to know how it allocates its memory for numbers, but that's way more than enough to blow out the exponent on a float, a double, and even the IEEE spec for a 128 bit 'quad.' Which either means it's just plain causing errors when it tries to multiply it beyond a certain point, or it's using some horrifying software fallback involving converting numbers to and from its own special extreme exponent value. If it were just the assembly mult instruction, it would indeed be faster than taking the logs and adding them; but I suspect exponent space is more the issue here.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5689 on: April 16, 2014, 09:38:54 pm »

Python automatically converts large ints to long, which in Python is basically BigNum.
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 #5690 on: April 18, 2014, 02:43:06 am »

Here's a Gist with the 3 code files but none of the resources files needed to run my program. I have the error

Quote
Traceback (most recent call last):
  File "gen.py", line 135, in <module>
    exportCube(p.center, 2*(p.r+1)+1, p)
  File "gen.py", line 102, in exportCube
    planetoid.rasterize(blocksData["blocks"], blueprints, True)
  File "/home/skyrunner/Desktop/meincraftWorldgen/planetoid.py", line 149, in rasterize
    blueprints[self.r] = pickle.load(f)               
  File "/usr/lib/python2.7/pickle.py", line 1378, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1069, in load_inst
    klass = self.find_class(module, name)
  File "/usr/lib/python2.7/pickle.py", line 1126, in find_class
    klass = getattr(mod, name)
AttributeError: 'module' object has no attribute 'BlockCircle'

From an internet search, it's supposedly a circular reference, but I don't see any of that. :(
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

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5691 on: April 18, 2014, 06:02:12 am »

Here's a Gist with the 3 code files but none of the resources files needed to run my program.

I'm leaving for work shortly so I can't really debug, but did you know you're setting a key in an empty dict and then overwriting it with a new dict?

Reference
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5692 on: April 18, 2014, 09:14:00 am »

This Python discussion reminds me of how much fun I always seem to have with C every time I come back to it from working with scripting languages.  I spent a good two hours yesterday trying to figure out how adding the following two numbers:

0x000800000
0x010000000

produced

0x040800000

That was mystifying.  I mean, how could that happen?  I was beginning to question if the debugger was just going insane (it is Eclipse), but there had to be a reasonable explanation!  The explanation came to me only after I ended up doing the operation as a binary OR after casting the original variable to an unsigned int.

It's because I was originally adding numbers to a pointer to an int.  Of course.  Ints are 4 bytes on this platform, so adding 0x010000000 of them would increase the pointer by 0x040000000.  Considering the code was working with a memory controller, it probably should have been a void pointer anyway and I wouldn't have had that problem, but live and learn.

There's been a time or two when I questioned why people were afraid of pointers.  I don't do that anymore.  Even if this isn't really related to the real reason.  :)
Logged
Through pain, I find wisdom.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5693 on: April 18, 2014, 11:32:41 am »

This Python discussion reminds me of how much fun I always seem to have with C every time I come back to it from working with scripting languages.  I spent a good two hours yesterday trying to figure out how adding the following two numbers:

0x000800000
0x010000000

produced

0x040800000

That was mystifying.  I mean, how could that happen?  I was beginning to question if the debugger was just going insane (it is Eclipse), but there had to be a reasonable explanation!  The explanation came to me only after I ended up doing the operation as a binary OR after casting the original variable to an unsigned int.

It's because I was originally adding numbers to a pointer to an int.  Of course.  Ints are 4 bytes on this platform, so adding 0x010000000 of them would increase the pointer by 0x040000000.  Considering the code was working with a memory controller, it probably should have been a void pointer anyway and I wouldn't have had that problem, but live and learn.

There's been a time or two when I questioned why people were afraid of pointers.  I don't do that anymore.  Even if this isn't really related to the real reason.  :)

OBVIOUSLY you need to implement a full adder with bitwise arithmetic!

Code: [Select]
axb = a ^ b;
c1 = c & axb;
c2 = c & b;
c = c1 | c2;
out = c ^ axb;

It's the only way to be sure!

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5694 on: April 18, 2014, 08:42:04 pm »

Here's a Gist with the 3 code files but none of the resources files needed to run my program.

I'm leaving for work shortly so I can't really debug, but did you know you're setting a key in an empty dict and then overwriting it with a new dict?

Reference
Interesting to know XD
I still haven't fixed the BlockCircle error yhough :(
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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5695 on: April 19, 2014, 09:47:56 am »

Moving a Scala project (yay Scala!) from Maven to SBT meant moving from a 151 line monolithic file down to 3 files that total 23 lines....*shakes fist* grr, xml

Though SBT does define it's own format, maybe a part of me would prefer it if they used an established format like JSON. But still, sbt is still nicer than the verbosity of XML and Maven combined.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5696 on: April 20, 2014, 05:02:23 am »

How do you make Python scripts that depend on modules (eg, flufl.enum) standalone? :c The rudimentary try I did once wasn't very successful. I hear that cxfreeze is where it's at, but finding instructions has proven difficult so far.
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

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5697 on: April 20, 2014, 07:41:16 pm »

How do you make Python scripts that depend on modules (eg, flufl.enum) standalone? :c The rudimentary try I did once wasn't very successful. I hear that cxfreeze is where it's at, but finding instructions has proven difficult so far.

Read up on pip, requirements.txt, and setup.py. If people care enough about what you make, they won't mind dependencies.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5698 on: April 20, 2014, 09:54:23 pm »

It's a real hassle to install Python and modules and pip on windows, though.
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

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5699 on: April 22, 2014, 10:49:05 am »

I thought Brainfuck was difficult. Today I heard about Malbolge.

Quote
Malbolge was so difficult to understand when it arrived that it took two years for the first Malbolge program to appear. That program was not written by a human being: it was generated by a beam search algorithm designed by Andrew Cooke and implemented in Lisp.

Seriously...

Quote from: Hello World program
('&%:9]!~}|z2Vxwv-,POqponl$Hjig%eB@@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#"
`CB]V?Tx<uVtT`Rpo3NlF.Jh++FdbCBA@?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${z@>

NOPE.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.
Pages: 1 ... 378 379 [380] 381 382 ... 796