1. Be terrible and fix it by subtracting the output from 11111111 and using that as the new input :P

2. I am really hungover now, but won't iterating the for loop the other way around fix that?

3. Originally Posted by Hast
I am really hungover now, but won't iterating the for loop the other way around fix that?
I think so. Change it to this:
Code:
```for (int j = 6; j >0; j--){
if (smallstr[j] == '1')
placeholder += pow(2.0,j);

}```
Might need to be >= instead of >.

4. The most significant bit corresponds to the highest power of 2, not the lowest.

It doesn't matter which way you iterate, the result is exactly the same. You just can't use the index for the power.

Edit:
With problems like this it helps to first do it manually on paper, and then work out your algorithm from there. That way you immediately see where this is going wrong and how to fix it.

Edit 2:
On top of being algorithmically wrong, Tarminic's solution also gives you a memory access violation.
Ok, it doesn't but it is still questionable to use length for index.

5. Originally Posted by I Legionnaire
Code:
```int count = 0;
for (int j = 5; j >=0; j--){
if (smallstr[j] == '1')
placeholder += pow(2.0,count);
count ++;
}```
Would be neater something like:
Code:
```int chunk_size = 6;
for (int j = chunk_size-1; j >=0; j--){
if (smallstr[j] == '1')
placeholder += pow(2.0, chunk_size - (j+1));
}```
Or
Code:
```int chunk_size = 6;
for (int j = chunk_size; j>0; j--){
if (smallstr[j-1] == '1')
placeholder += pow(2.0, chunk_size-j);
}```
With the first line being able to move way up the code & variable be used elsewhere, to have less magic numbers floating about to fuck up missing editing one. Though why are you going 6 bits at a time??

6. Originally Posted by I Legionnaire
Code:
```int count = 0;
for (int j = 5; j >=0; j--){
if (smallstr[j] == '1')
placeholder += pow(2.0,count);
count ++;
}```
@MortyM
Thanks, it took me a bit to realize that the index didn't correspond to what power I needed to be using. Using a count was a pretty easy fix.
This is, by the way, the difference between big and little endianness. Quite a bit of existing code and hardware uses little endian (what your code did), even though humans use big endian for actually writing the number out.

7. So, I'm trying to work out how to do something, and for some reason the solution has evaded me when I feel like it should be a relatively simple, straightforward process.

I have two points with an (X,Y) coordinate pair and a cardinal vector V (0, 90, 180, 270), and I know these points are neighbors in some form. For example, if the first point is (3,3) the second point must be (3,2), (3,4), (2,3), or (4,3).

I need to figure out if and how these two points are moving in relation to each other. Specifically:

1. Whether they're colliding (3,3 moving down and 3,4 moving up)
2. Whether they're moving parallel to each other (3,3 moving left and 3,4 moving left/right)
3. Whether they're moving in the same direction (3,3 moving up and 3,4 moving up)
4. Whether they're moving apart (3,3 moving up and 3,4 moving down/left/right)

I feel like this should be easy, but for the life of me I've been at this for 3+ hours and I couldn't quite get it right. I thought I could use the difference between the two vectors and the distance between the two points (after moving them in the direction of those vectors), but I so far I haven't gotten it right yet. I feel like there should be a simple way to do this but it's escaped me up to this point. Halp!

8. Originally Posted by Daneel Trevize
IDK, having to be so verbose about everything really drags. Python 3 lets you do really clear things with slices, zips & list comprehensions, and yet still ensures your explicit about trying to combine e.g. strings and ints.
Code:
```>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> letters
['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> # replace some values
>>> letters[2:5] = ['C', 'D', 'E']
>>> letters
['a', 'b', 'C', 'D', 'E', 'f', 'g']```
Code:
```>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> zipped = zip(x, y)
>>> list(zipped)
[(1, 4), (2, 5), (3, 6)]
>>> x2, y2 = zip(*zip(x, y)) # unzipping
>>> x == list(x2) and y == list(y2)
True```
Code:
```>>> [str(round(pi, i)) for i in range(1, 6)]
['3.1', '3.14', '3.142', '3.1416', '3.14159']```
Ah, so much win from Haskell.
Idk about that, and i'm fucking stupid.

9. You lose, Quackbot! You lose. Sigged.

10. Originally Posted by I Legionnaire
1.) If (ptA.X == ptB.X || ptA.Y == ptB.Y) collision = True

2.) If(ptA.degrees == ptB.degrees || ptA.degrees == ptB.degrees -180) parallel = True

3.) if (ptA.degrees == ptB.degrees ) samedirection = True

4.) If you're strictly talking about moving apart you can (assuming part 1 is not true) check the Xs and Ys against each other after the move is made. If the difference between either is >1 then they are moving apart. Being able to check the points post-move might take a bit of work though.

you can normailze the degrees using this function

Code:
```double constrainAngle(double x){
x = fmod(x,360);
if (x < 0)
x += 360;
return x;
}```
Not nearly that easy, unfortunately. For the first case, (3,3) and (3,4) are only colliding if (3,3)'s vector is down or (4,4)'s vector is up, for example.

I'm trying to figure out a way to do this simply but I'm thinking I'm just gonna end up with a ton of if statements to handle every case.

11. Any good books for learning Python? Coming from a Java background and I've got a reasonable grasp of it.

Any good books for learning Python? Coming from a Java background and I've got a reasonable grasp of it.
About to start a "Beginning Python on Raspberry Pi" book, will see if it's any good over the next few weeks/months. Picking raspi because it's also teaching python for i/o stuff like buttons and LEDs which is cool.

13. Originally Posted by I Legionnaire
Not nearly that easy, unfortunately. For the first case, (3,3) and (3,4) are only colliding if (3,3)'s vector is down or (4,4)'s vector is up, for example.
It is if you treat your "cars" as structs. Pass each object the start position, and direction. Then compute what their second position is, this should only take eight switches , four per car.

Ex:: CarA.degrees = 0
case (0) CarA.secposY = CarA.firstposY ++;
case (90) CarA.secposX = CarA.firstposX ++;
etc etc...

Then you can compare their second positions against each other. In both part one and four. Part two and three are only dependent on direction.
That was my first strategy, actually: Essentially move each the two coords along their specified direction and compare the distance between the two afterwards, but for whatever reason I couldn't get that to work. I was able to get it to work properly, but only after writing some fairly ugly code.

Warning: 120 lines of javascript with 4 switch statements
Spoiler:

Code:
```    object.determineType = function() {
var type = null;

if(isConvergent(pixel1, pixel2)) {
type = Fault.TYPE.CONVERGENT;
} else if(isTransform(pixel1, pixel2)) {
type = Fault.TYPE.TRANSFORM;
} else if(isDivergent(pixel1, pixel2)) {
type = Fault.TYPE.DIVERGENT;
} else if(isInactive(pixel1, pixel2)) {
type = Fault.TYPE.INACTIVE;
} else {
throw new PlanetSimError('Unable to determine fault type', [pixel1, pixel2]);
}

faultType = type;

return type;
}

function isConvergent(pixel1, pixel2) {
var convergent = false;
var vectorDiff = Math.abs(pixel1.getPlate().getVector() - pixel2.getPlate().getVector());
if(vectorDiff != 0) {
convergent = isMovingTowards(pixel1, pixel2) || isMovingTowards(pixel2, pixel1);
}
return convergent;
}

function isMovingTowards(pixel1, pixel2) {
var isMovingTowards = false;
var sameX = pixel1.getX() == pixel2.getX();
var sameY = pixel1.getY() == pixel2.getY();
var vector = pixel1.getPlate().getVector();
switch(vector) {
case 0:   //east
isMovingTowards = sameY && (pixel1.getX() - pixel2.getX() < 0);
break;
case 90:  //south
isMovingTowards = sameX && (pixel1.getY() - pixel2.getY() < 0);
break;
case 180: //west
isMovingTowards = sameY && (pixel1.getX() - pixel2.getX() > 0);
break;
case 270: //north
isMovingTowards = sameX && (pixel1.getY() - pixel2.getY() > 0);
break;
default:
throw new PlanetSimError('Cannot determine if pixel1 is moving toward pixel2: only cardinal vectors are supported', vector);
}
return isMovingTowards;
}

function isTransform(pixel1, pixel2) {
var transform = false;
var sameX = pixel1.getX() == pixel2.getX();
var sameY = pixel1.getY() == pixel2.getY();
var vector = pixel1.getPlate().getVector();
switch(vector % 180) {
case 0: //east or west
transform = sameX;
break;
case 90: //south or north
transform = sameY;
break;
default:
throw new PlanetSimError('Cannot determine if pixel1 is moving parallel to pixel2: only cardinal vectors are supported', vector);
}
return transform;
}

function isDivergent(pixel1, pixel2) {
var divergent = false;
var vectorDiff = Math.abs(pixel1.getPlate().getVector() - pixel2.getPlate().getVector());
if(vectorDiff > 0) {
switch(pixel1.getPlate().getVector()) {
case 0:   //east
divergent = ((pixel1.getX() - pixel2.getX()) == 1);
break;
case 90:  //south
divergent = ((pixel1.getY() - pixel2.getY()) == 1);
break;
case 180: //west
divergent = (pixel1.getX() - pixel2.getX() == -1);
break;
case 270: //north
divergent = (pixel1.getY() - pixel2.getY() == -1);
break;
}
}
return divergent;
}

function isInactive(pixel1, pixel2) {
var inactive = false;
if(pixel1.getPlate().getVector() == pixel2.getPlate().getVector()) {
var sameX = pixel1.getX() == pixel2.getX();
var sameY = pixel1.getY() == pixel2.getY();
var vector = pixel1.getPlate().getVector();
switch(vector % 180) {
case 0:  //east or west
inactive = sameY;
break;
case 90: //south or north
inactive = sameX;
break;
default:
throw new PlanetSimError('Cannot determine if pixel1 is moving parallel to pixel2: only cardinal vectors are supported', vector);
}
}
return inactive;
}```

I need to refactor this so it sucks less, but in the interest of making progress I did it in a way that made it as hard as possible to fuck up. At least it passes the two-dozen unit tests I have running on it.

14. ## Chris' teacher is a bad and noone understands his classes - Coding help thread

Any good books for learning Python? Coming from a Java background and I've got a reasonable grasp of it.
There's a ton of free online resources if you're not set on hard copies of programming books, the official Python docs are pretty good: http://docs.python.org/3/tutorial/

Here's a list of some other resources if you feel the docs aren't your style: http://docs.python-guide.org/en/late.../learning.html

15. Flogging a dead horse here, but the crypto challenges are ideal to pick up a new language. Learning a language from docs alone is dicks, learn it whilst doing fun stuff of some sort.

16. Originally Posted by Rami
Flogging a dead horse here, but the crypto challenges are ideal to pick up a new language. Learning a language from docs alone is dicks, learn it whilst doing fun stuff of some sort.
That's my plan. I've been doing them in Java but I want to learn python for a uni assignment be next year and figure I might as well start now as I've got a bunch of "free" time coming up with summer holidays starting soon and not much going on at work during the time.

I'll work through the docs to get the basics and then look at some of the challenges I've done so far and redo them in python, probably do some of the project euler stuff too as that was good when I did it a age back.

17. They are good fun and doing the first couple of examples in python is easy enough even for a newbie. I should really get back to them but most of my time is taken by my diploma

18. Originally Posted by I Legionnaire
Its kinda win really.. As long as you arent running windows.

I assume you can do this in a browser driveby with the appropriate browser hack?

Oh also because this is educational.. http://technet.microsoft.com/en-us/s...letin/MS10-092

Non-Affected Software
Operating System
Windows XP Service Pack 3
Windows XP Professional x64 Edition Service Pack 2
Windows Server 2003 Service Pack 2
Windows Server 2003 x64 Edition Service Pack 2
Windows Server 2003 with SP2 for Itanium-based Systems
And people laughed at us for not upgrading anything.

19. Originally Posted by I Legionnaire
It's part of the source dump for a worm that was selling for \$40k USD. People on reddit and HN are pretty surprised by how poorly it's written considering how effective it is/was at evading AV, and propagating. Shit's waaay beyond my level.
Most viruses are horribly coded. Most antivirus software is worse.

20. Given that maintainability of virus code isn't exactly needed, it's about the only field in which code quality isn't a huge deal.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•