Search found 1812 matches

by Cosmologicon
Mon Apr 26, 2010 11:43 am UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

I don't know about that. If you actually want to be able to represent 4.2 exactly, yes, you want decimal numbers. However, that's rarely the case, and I would say that floating point numbers are the ones you "probably" want. does anyone ever really want to represent numbers inexactly? flo...
by Cosmologicon
Mon Apr 26, 2010 2:05 am UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

you're using floating point numbers. you probably want decimal numbers instead I don't know about that. If you actually want to be able to represent 4.2 exactly, yes, you want decimal numbers. However, that's rarely the case, and I would say that floating point numbers are the ones you "probab...
by Cosmologicon
Tue Apr 20, 2010 10:10 pm UTC
Forum: Logic Puzzles
Topic: Cipher: the story of two rivals
Replies: 8
Views: 2384

Re: Cipher: the story of two rivals

Huzzah.
by Cosmologicon
Tue Apr 20, 2010 6:30 pm UTC
Forum: Logic Puzzles
Topic: Cipher: the story of two rivals
Replies: 8
Views: 2384

Re: Cipher: the story of two rivals

Yes, there's a simple rule that gives you the answer. It's not a random mapping.
by Cosmologicon
Tue Apr 20, 2010 5:02 pm UTC
Forum: Coding
Topic: What does this do in Python?
Replies: 15
Views: 1700

Re: What does this do in Python?

thoughtfully wrote:There is an "else" clause, that is executed if there was no exception. You can't use else and finally together, that is an error.

I don't see why that would be the case. Anyway, you can do it in Python 2.5 and 2.6.
by Cosmologicon
Tue Apr 20, 2010 4:53 pm UTC
Forum: Logic Puzzles
Topic: Cipher: the story of two rivals
Replies: 8
Views: 2384

Re: Cipher: the story of two rivals

Harder than I thought I guess. More hints:
Spoiler:
With the exception of 100, each number encodes one letter

Spoiler:
Multiple numbers encode the same letter. For instance, 2 and 10 are the same letter.

Spoiler:
With one exception, there are only seven distinct letters in the plain text.

Spoiler:
8 = E
by Cosmologicon
Sat Apr 17, 2010 7:33 pm UTC
Forum: Logic Puzzles
Topic: Cipher: the story of two rivals
Replies: 8
Views: 2384

Re: Cipher: the story of two rivals

Okay, maybe some hints: Obviously it involves numbers, but it's not mathematical. You don't have to do any calculations to decipher it. Only letters are encoded. Punctuation and spaces have been removed to make it harder. But each line corresponds to a sentence. The cipher text uniquely maps...
by Cosmologicon
Thu Apr 15, 2010 4:19 pm UTC
Forum: Logic Puzzles
Topic: Cipher: the story of two rivals
Replies: 8
Views: 2384

Cipher: the story of two rivals

Here you go, another dumb cipher. It's probably pretty easy, but I'll post the answer if nobody gets it in a week. 6 8 11 5 8 9 2 1 9 7 8 11 11 9 0 1 4 11 9 10 1 19 7 5 1 8 8 9 0 1 1 14 3 8 9 10 1 7 7 8 7 1 1 0 11 2 8 9 4 11 8 3 1 9 10 1 14 18 9 3 1 9 6 9 1 6 11 17 1 5 11 9 3 1 19 20 1 6 6 8 16 1 9 ...
by Cosmologicon
Wed Apr 14, 2010 6:38 pm UTC
Forum: Coding
Topic: How Do I Learn About [n]?
Replies: 181
Views: 365897

Re: How Do I Learn About [n]?

Any good intermediate/advanced resources on Javascript/DHTML/CSS/Ajax or whatever? I want to write video games with it and I need secret hacks and dirty tricks.
by Cosmologicon
Tue Apr 13, 2010 9:30 pm UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

Can't you take a working MD5 implementation and add outputs of intermediate values?
by Cosmologicon
Mon Apr 12, 2010 3:31 pm UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

EDIT : Yet again, I've solved solved my own problem. I disabled hardware acceleration and it worked. I guess it has something to do with video memory or buffers or something shrouded by Python's abstraction. Sorry for wasting your time again. :D Well, I'm glad you got it working, but I just want to...
by Cosmologicon
Mon Apr 12, 2010 1:06 am UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

class foo (pygame.sprite.Sprite):  def __init__ (self, screen):    self.image = #whatever    self.screen = screen    self.blit_to_screen ((0, 0))  def blit_to_screen (self, (x, y)):    screen.blit (self.image, x, y)   I'm not sure if this will fix your problem, but you obviously need to use self.sc...
by Cosmologicon
Sat Apr 10, 2010 2:07 pm UTC
Forum: Coding
Topic: Epic coding moments
Replies: 127
Views: 21181

Re: Epic coding moments

Here's a commit message I just had the pleasure of writing (after checking an ASCII table): Fix a sign error. This checkin flips one bit (< is 0x3C, > is 0x3E) and fixes two bugs. The ASCII-table has a lot of those groupings. Left and right parentheses are also the same save for the least significa...
by Cosmologicon
Wed Apr 07, 2010 10:30 pm UTC
Forum: Coding
Topic: Calculating a large number's order of magnitude
Replies: 8
Views: 1828

Re: Calculating a large number's order of magnitude

That is pretty good, but I think you do need all the terms. Here's a comparison of the base-10 log of 576000!, calculated three different ways:

3067853.00817675 - actual
3067853.00817674 - all terms
3067849.72887550 - first 2 terms
by Cosmologicon
Mon Mar 29, 2010 9:49 pm UTC
Forum: Coding
Topic: Epic coding moments
Replies: 127
Views: 21181

Re: Epic coding moments

Here's a commit message I just had the pleasure of writing (after checking an ASCII table):

Code: Select all

Fix a sign error.
This checkin flips one bit (< is 0x3C, > is 0x3E) and fixes two bugs.
by Cosmologicon
Fri Mar 26, 2010 3:02 pm UTC
Forum: Coding
Topic: Coding: Hacks and Snippets
Replies: 434
Views: 778083

Re: Coding: Hacks and Snippets

TheChewanater wrote:Image

What's more, you can do multiple replacements in a single sed invocation, so you don't need any pipes there at all:

Code: Select all

sed 's/gkt/gtk/g;s/GKT/GTK/g' file > file.new
by Cosmologicon
Fri Mar 19, 2010 8:54 pm UTC
Forum: Coding
Topic: Is C++ Getting Phased Out?
Replies: 67
Views: 7615

Re: Is C++ Getting Phased Out?

But if it uses a vtable to implement the polymorphism, that's a pointer dereference, which Berengal seems to be saying is costly.
by Cosmologicon
Fri Mar 19, 2010 5:00 pm UTC
Forum: Coding
Topic: .obj file in openGL causing framerate issues
Replies: 9
Views: 1684

Re: .obj file in openGL causing framerate issues

I'm not *that* good with OpenGL, but I know the pygame/pyopengl OBJ loader uses a display list. It's not quite as fast as a vertex array, but it's much faster than immediate mode rendering, and it's very simple. You compile the list once by: gl_list = glGenLists(1) glNewList(gl_list, GL_COMPILE) [ r...
by Cosmologicon
Wed Mar 17, 2010 2:16 pm UTC
Forum: Coding
Topic: Is C++ Getting Phased Out?
Replies: 67
Views: 7615

Re: Is C++ Getting Phased Out?

C++ is basically C with objects and a few higher level features. You can make use of a lot of C++ features including templates and OOP with no more runtime than C. With a tiny bit of extra runtime for virtual functions and hooking malloc to new, then you get most of C++. Sorry, I'm not familiar wit...
by Cosmologicon
Tue Mar 16, 2010 6:49 pm UTC
Forum: Coding
Topic: python sound
Replies: 4
Views: 1022

Re: python sound

pygame allows you to use an array to produce a sound through the sndarray module. It should be as easy as:

Code: Select all

make_sound(array('c', [int(127*sin(2*pi*t*freq/mixer_freq)) for t in range(duration*mixer_freq)]))
Or something like that. I haven't tested it.
by Cosmologicon
Mon Mar 15, 2010 6:06 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1827804

Re: Coding: Fleeting Thoughts

Well YMMV, but in my experience, API documentation auto-generated from comments tends to encourage useless comments and useless documentation. ODE_API dReal dWorldGetAutoDisableLinearAverageThreshold ( dWorldID ) Get auto disable linear average threshold for newly created bodies. Returns: the thresh...
by Cosmologicon
Mon Mar 15, 2010 2:24 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1827804

Re: Coding: Fleeting Thoughts

Indeed, idiomatic code doesn't get a single byte wasted on comments.... I write API documentation (javadoc-ish comments). I'm not sure whom you're responding to, but aren't javadoc-ish comments exactly the sort of thing You, sir, name? was complaining about? I hate when people code like this /* cro...
by Cosmologicon
Sun Mar 14, 2010 4:48 pm UTC
Forum: Coding
Topic: Overload ofstream and ostream?
Replies: 10
Views: 2900

Re: Overload ofstream and ostream?

I guess you're right. I guess anybody who makes a class that behaves like a stream with the shift operators had better make it inherit from the appropriate stream. In which case you can get by with just defining it for ostreams.
by Cosmologicon
Sat Mar 13, 2010 10:16 pm UTC
Forum: Coding
Topic: Overload ofstream and ostream?
Replies: 10
Views: 2900

Re: Overload ofstream and ostream?

I think that in practice the danger is very minimal. Presumably your function makes use of some properties of an ostream. It might say something like this: friend T & operator<<(T & ostr, const employee & e) { return ostr << e.name << " [" << e.id << "]"; } There are ...
by Cosmologicon
Sat Mar 13, 2010 8:57 pm UTC
Forum: Coding
Topic: Overload ofstream and ostream?
Replies: 10
Views: 2900

Re: Overload ofstream and ostream?

ISTM that this might be a good use of templates:

Code: Select all

  template <class T>
  friend T & operator<<(T & ostr, const employee & e);
That's what I usually do to avoid worrying about remembering the names of any classes. Is there some down side to this way?
by Cosmologicon
Sat Mar 13, 2010 8:48 pm UTC
Forum: Coding
Topic: Mother...
Replies: 9
Views: 1200

Re: Mother...

Another technique that works for 3 dimensions as well as 2 is to choose a random point in the unit circle (or sphere), then normalize it. You can choose a random point uniformly from the unit circle by choosing vx and vy uniformly from [-1, 1], and repeating until vx^2 + vy^2 <= 1. For 2-D I usually...
by Cosmologicon
Sat Mar 13, 2010 2:05 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1827804

Re: Coding: Fleeting Thoughts

If you're going to point out how you'd write control structures vs function calls, it's probably best to name your function something other than "do".
by Cosmologicon
Mon Mar 01, 2010 1:09 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1827804

Re: Coding: Fleeting Thoughts

No, as Melissa O'Neill points out, your algorithm is not a sieve at all. You're using what's called trial division. It's not a crazy way to find primes, if you don't need more than a hundred thousand or so, but it's nowhere near as efficient as a sieve for generating large lists of primes. If you do...
by Cosmologicon
Sat Feb 27, 2010 1:20 am UTC
Forum: Coding
Topic: dynamically size multidimensional arrays in C/C++
Replies: 23
Views: 5004

Re: dynamically size multidimensional arrays in C/C++

In C++, you can use a Vector<Vector*>, or however deep you want it. Just be sure to use indexes to access data, rather than pointers, since iirc, it uses realloc to increase in size. You can even initialize the whole thing without a loop! I think this is right for a 3-D array: vector<vector<vector<...
by Cosmologicon
Fri Feb 26, 2010 11:03 pm UTC
Forum: Coding
Topic: dynamically size multidimensional arrays in C/C++
Replies: 23
Views: 5004

Re: dynamically size multidimensional arrays in C/C++

In C++ you should make a class and overload the subscript operator. The C++ FAQ has some info on this topic.
by Cosmologicon
Thu Feb 25, 2010 4:48 pm UTC
Forum: Science
Topic: Vacuum Zeppelin
Replies: 146
Views: 62971

Re: Vacuum Zeppelin

but I have a much better idea: why not make a vaccum-filled zeppelin, and use photonic pressure to keep it inflated? The downside would be that it requires kazillion of energy to produce that much light. The upside is that could use LEDs to make that light. I doubt that would work very well, due to...
by Cosmologicon
Thu Feb 25, 2010 2:52 am UTC
Forum: Logic Puzzles
Topic: Anyone feel they can crack this code?
Replies: 50
Views: 14745

Re: Anyone feel they can crack this code?

Well, let me be clear what I mean by that. It's (probably) not a random string of letters, and (probably) not something that tends to uniformize the letter frequencies, like a keyword cipher. That doesn't mean it has to be a rearrangement of letters that appear in the solution, and it certainly does...
by Cosmologicon
Sat Feb 20, 2010 5:53 pm UTC
Forum: Coding
Topic: Python typing
Replies: 21
Views: 1863

Re: Python typing

Except for the fact that you can put arbitrary statements in a switch. Yes, if all you have is a list of zero-argument functions to call, the structuring is no worse in Python. The difficulty comes in when you need more complicated operations, such as assignments, as Berengal inadvertently demonstra...
by Cosmologicon
Fri Feb 19, 2010 8:53 pm UTC
Forum: Logic Puzzles
Topic: Anyone feel they can crack this code?
Replies: 50
Views: 14745

Re: Anyone feel they can crack this code?

The frequencies of letters in the grid match up with the frequencies of English letters, to 99.92% confidence. That was probably evident to most people, but thought you'd like a statistical confirmation.
by Cosmologicon
Fri Feb 19, 2010 8:12 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1827804

Re: Coding: Fleeting Thoughts

You, sir, name? wrote:That is ambiguous. Is it O(((2n+1)^n)^2) = O(e^(2n log(n))) or O((2n+1)^(n^2)) = O(e^(n^2 log(n)))

It's the latter. Exponentiation is right-associative. Always has been. The fact that BASIC and Excel do it the other way simply proves the point, I think. :)
by Cosmologicon
Fri Feb 19, 2010 6:56 pm UTC
Forum: Coding
Topic: Python typing
Replies: 21
Views: 1863

Re: Python typing

You'd replace this C code: switch (x) { case 5: func5(); break; case 10: func10(); break; case 15: func15(); break; case 20: func20a(); func20b(); break; } with this Python code: def func20(): func20a() func20b() funcs = dict((5, func5), (10, func10), (15, func15), (20, func20)) funcs[x]() Obviously...
by Cosmologicon
Fri Feb 19, 2010 6:06 pm UTC
Forum: Coding
Topic: Python typing
Replies: 21
Views: 1863

Re: Python typing

The somewhat more pythonic way is to have a dict mapping values to functions. That should be simpler than a binary search and probably as fast.
by Cosmologicon
Thu Feb 11, 2010 2:53 am UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

Do people really not know this? That's surprising giving how much people seem to complain about && and ||. Where did you learn C++, huh?
by Cosmologicon
Wed Feb 10, 2010 10:39 pm UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

Folks, "and" and "or" are part of C++ and they mean exactly the same thing as "&&" and "||", which is to say, they mean the same as in Python.
by Cosmologicon
Wed Feb 10, 2010 10:18 pm UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525018

Re: The "IT DOESN'T WORK!" thread

e of pi wrote:And boolean logic...don't even get me started. "if x>0 and y==4" is so much easier to write, remember, and understand than the C++ equivalent.

The C++ equivalent being:

Code: Select all

if (x>0 and y==4)
?

Go to advanced search