Be terrible and fix it by subtracting the output from 11111111 and using that as the new input :P
Be terrible and fix it by subtracting the output from 11111111 and using that as the new input :P
I am really hungover now, but won't iterating the for loop the other way around fix that?
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.
Last edited by MortyM; June 21 2013 at 04:43:33 PM.
Would be neater something like:OrCode: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)); }
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??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); }
Last edited by Daneel Trevize; June 22 2013 at 08:59:35 AM. Reason: (j+1)
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!
![]()
![]()
Status of Babby: 100% Formed
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.
![]()
![]()
Status of Babby: 100% Formed
Any good books for learning Python? Coming from a Java background and I've got a reasonable grasp of it.
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:
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.
![]()
![]()
Status of Babby: 100% Formed
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
Definitely start with python 3, much better than 2 imo.
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.
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![]()
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
And people laughed at us for not upgrading anything.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
Last edited by Lana Torrin; June 26 2013 at 02:38:20 AM.
Originally Posted by lubica
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.![]()
Bookmarks