|
I rarely write in assembly these days but I read it a lot. I've focused more on getting C and particularly C++ to generate the exact machine code I intended if I'd have written by hand, or as is often the case, better.
Real programmers use butterflies
|
|
|
|
|
Do you port all pointers to array access?
Pointers are always the pain for this type of exercise. Some algorithms are easier to understand that way. Multilevel pointers are the worst.
|
|
|
|
|
Whenever I can, that's what I do. I turn it to arrays and indices. It is difficult but actually that process is critical for me to understand it. It's one of the most important parts of the port.
And yeah, double indirection and such gets tricky fast.
Real programmers use butterflies
|
|
|
|
|
Start by determining what data it works with. Then split out the functions and start figuring out the inputs and outputs from each function. Finally, make a process and data flow diagrams for the code. This process makes short work of understanding even the most cryptic code.
If you don't want to spend a day or two doing this process there are tools like sourcetrail that will do the work for you.
|
|
|
|
|
If the project is fairly significant in size with multiple .c and .h files with many functions, I will often turn doxygen (with graphviz) loose on it. Even though the code may not have any doxygen tags or doxygen-compatible comment blocks to generate function and API documentation, it can still give you an idea of "what calls what" in a graphical context.
|
|
|
|
|
My understanding of ranked voting is that a voter puts down his choices as an ordered set, and for the first round, the #1 votes are tallied; if no one has 50%+1, then the lowest vote-getter gets discarded, and everyone who had him as #1 simply have everyone else move up a place, and the process repeats.
As long as there aren't too many candidates - and indeed, there is hardly ever more than 6 candidates who get more than 2% of the vote - than a complete list pertaining to the permutations of the candidates could be released, and done so as they are counted, like a canonical election. I use the number 6 because 6! - 720 is still a digestible number. In fact, the law could be written so only that the first round eliminates everyone outside of the top-6.
For example, using this 6 number, the state's Secretary of State could release the vote total of every permutation of the 6, and election-nerds like the gang at 538.com or the NY Times' (infamous) needle could crank the numbers as they see fit trying to put out the probabilities for the 6 at that instance.
|
|
|
|
|
how is it possible to discuss political elections without getting political?
|
|
|
|
|
There are different ways of implementing Ranked Voting.
Ranked voting - Wikipedia
"Time flies like an arrow. Fruit flies like a banana."
|
|
|
|
|
Ranking all (or all-minus-one) options would be tedious if there were many.
I imagine that "ranking your top three" would simplify things considerably when there are a lot of options from which to choose.
Maybe something like "top three or the SQRT of the number of options" would suffice?
|
|
|
|
|
If we use bit groupings for the ranks of each candidate, that would look something like:
Bits per candidate: floor(log_2(candidateCount)) + 1
Bits per vote: candidateCount * bitsPerCandidate
Total space for election: voters * bitsPerVote
So given 300,000,000 voters with 12 candidates:
space = 300,000,000 * 12 * (floor(log_2(12)) + 1)
space = 14,400,000,000 bits or 1.8 GB
Given the same amount of voters with 24 candidates:
space = 300,000,000 * 24 * (floor(log_2(24)) + 1)
space = 36,000,000,000 bits or 4.5 GB
Space definitely isn't the issue. What about the algorithm?
1) Bin every vote by first-pick candidate.
2) If no bin is >50% of the votes, re-bin the lowest bin and repeat #2.
3) The >50% bin is your winner.
I honestly don't see why this would be an issue. Worst case scenario something like v+(c-2)*(v/2) run-time where v is the vote count and c is the number of candidates. v/2 is just a napkin-math average since the redistributed bins would start out small and grow as the candidate list got shorter.
Again, just a bunch of napkin math so I probably missed something but I never bought the "it's too hard to compute" excuse either And I'm sure there are clever tricks to reduce the time required.
EDIT: For reference, if processing a vote takes:
1 microsecond: 30 minutes to determine a winner @ 300M votes, 12 candidates
1 millisecond: 20 days, 20 hours to determine a winner @ 300M votes, 12 candidates
And this is a single-threaded, un-optimized, brute-force approach.
modified 6-Jul-21 21:48pm.
|
|
|
|
|
|
Dan Neely wrote: You called out the problem here without realizing it. They're binning sheets of paper in stacks and counting the stacks.
I'll never understand how in the US we've been successfully testing millions of kids every year via paper "ballots" (scantron sheets) that are tallied electronically, but when it comes to our literal democracy we suddenly have the IQ of broccoli
|
|
|
|
|
And what exactly do you have against broccoli?
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
I mean... it's tasty but I'd rather not let it make decisions for me
|
|
|
|
|
Given some of my coworkers, broccoli voting just might be an improvement over the current state of affairs.
|
|
|
|
|
If Bruce Willis was found dead beside a bottle of Viagra, did he Die Hard?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If he did, they might have problems closing the lid on the casket...
|
|
|
|
|
I don't know if I Cialis happening any time soon.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Some people may McClane that, but I don't think so.
|
|
|
|
|
All that stiff competition in Hollywood finally got to him.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Two stiff puns for the price of one!
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
Well that wasn't hard difficult!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
He might get have just choked on the pills while trying to swallow them.
Did he complain of a stiff neck?
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
The Kid didn't Survive the Night in Sin City? He was within Striking Distance of being The Last Man Standing and winning The Whole Nine Yards.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Any one been subjected to breath analysis before they can code?
"Rock journalism is people who can't write interviewing people who can't talk for people who can't read." Frank Zappa 1980
|
|
|
|