Interacting with UDP Simulation Software Using Your Own Code
Interacting with UDP Simulation Software Using Your Own CodeEnvironmentI used Windows 10 x64 for this example, although the operating system should not make much difference. The programs are written in Python. I will use the two simulated devices from the first stage to demonstrate the exchange.
Start two instances of the simulator. In the first, select Device 1 Interface 0; in the second, select Device 2 Interface 0. Click Reload parameters in each window to populate its settings:
On both inst ...
The Git commands I kept having to look up
When I started using GitHub, the easy part was finding interesting repositories. The confusing part was working out where my own changes had gone. I’d edited a file and run git add. Why couldn’t I see the change on GitHub yet?
It helped to follow one edit all the way through. The file I type into lives in my working tree. When I stage a change, Git puts that version in the index, ready for my next commit. A commit records those staged changes in the history on my machine. Only when I push does t ...
Adding digits until only one is left
Start with 38. Add its digits and you get 11. Do it again and you get 2. That’s the whole problem: given a nonnegative integer, tell me which digit I’ll end up with.
A loop would do it. The interesting bit was the follow-up: could I get there in constant time, without a loop or a recursive call? Someone on LeetCode did it in one line:
12def func(num): return (num%9) or (9*bool(num))
It took me a minute to see what 9 had to do with anything. Write a four-digit number as 1000*a + 100*b + 10*c ...
Is it a square? Try subtracting odd numbers
Given a positive integer, decide whether it’s a perfect square. For 16 the answer should be True; for 14, False. My immediate reaction was “just take the square root.” Then I read the next line: no built-in math functions. There went my backup plan involving logarithms, too.
Here was my first stab at it. Try one square after another and stop when one hits the target or overshoots:
12345678910def func(num): if(num<0): return False if(num<=2): return True for i in rang ...
How do you add two numbers without a plus sign?
“Add a and b.” Easy enough: return a+b. Then I read the rest of the question. No plus signs. No minus signs. Oh.
For the record, I submitted return a+b and the judge accepted it. That got a laugh out of me. But the question was worth doing properly. It had to handle negative numbers too: 1 and 2 should give 3, while −2 and 3 should give 1.
Split the answer into a sum and a carryForget carries for a moment. For each bit, 1 and 1 should give 0, 1 and 0 should give 1, and two zeros should stay zero ...







