• Create Account

# Cagnazzo

Member Since 06 Jun 2012
Offline Last Active Private

### In Topic: Trying to solve mathematical problem using programing skills

29 November 2012 - 10:32 AM

Python is great for this kind of thing. I just pull up the shell and hack a quick function together. Great for GCD, LCM, co-primality, etc. Quicker than C++ to compile and run.
I just rewrite the function every session I want to use it, which ends up with me learning the definitions of these things very thoroughly (and degrading my mental arithmetic).

Python is pretty good, but you'd be amazed at how well Haskell does with Project Euler.

There are tons of problems that it just chews through with no thought. Which is exactly what you'd expect from a purely functional language, really

### In Topic: Bitwise Confusion

25 November 2012 - 04:58 PM

I think you might be mixing 16 up with 15.

255 is, in binary, 11111111.
16 is, in binary, 0001000.

The reason you can take any number up to 255 and logical and it with 255 and get that number back, is because 255 is basically ones everywhere - so if the number you're &ing has a zero in a slot, the result is zero in that slot - if it has a one, the result is one. 1&x is simply equal to x.

0&x is always equal to zero though. So if you're &ing with 16, the the sixteenth place is always going to be the only place that could possibly be nonzero. You'll end up with either 16 or 0.

Does that make sense? I suspect you meant to be using 15, which would be 00001111.

### In Topic: What is the difference between CPU and GPU?

24 November 2012 - 11:32 PM

I think about it like this:

CPU does the math, GPU does the rendering.

Ta-Da (I'm not a smart programmer ).

GPU does the math too. I would say it's more like, CPU does the logic that brings everything together, and GPU is the powerhouse that drives rendering, and possibly physics (and perhaps other stuff too).

Perhaps the best way to say it is that a CPU is a generalized processor, and a GPU is a processor designed to efficiently operate on graphical entities. It's more or less a very specialized CPU - what it is designed to do, it does much faster than a general CPU, and what it wasn't designed to do, it does much, much, much slower.

### In Topic: Ordering Byte Pairs by Frequency In A File

30 October 2012 - 06:46 PM

Yeah, if you can make a file in storage, things will be a lot easier.

You can make a 64k bytemap and count up to 256 occurrences there - if you have more crop up, make a 64k temp file and increment the corresponding byte in it, then set the one in your memory to zero.

Unless a number comes up more than 65536 times you won't need to worry (and if it does, you can create a second file in storage). After you're done reading your input, you just have to go through the files in storage in descending order - the highest there is the highest overall, and ties are broken by a lesser storage file if there's more than one or the one in memory as the base case.

### In Topic: How to avoid game state hell (huge switchs)?

21 June 2012 - 07:34 PM

Yeah, the need for experimentation is pretty often unstated, but very important. People are notoriously bad at seeing what actually is costing them time so they try to optimize everything. It's variable on the code, of course, but I have a software engineering book here whose author mentions several times that 5% of his code caused about 90-95% of the slowdown. Optimizing everything as it's written in that case means 95% of the work is wasted.

You might call that habit suboptimal

(Not that you shouldn't ignore obvious inefficiencies as you write, of course, but weigh "this'll be easy to change later" and "this is easy to read" over "it'll run faster if I do this," especially before you actually profile it)

PARTNERS