Enlarge / The Apple TV and the Horipad Ultimate MFI controller. (credit: Andrew Cunningham)
For those of us fortunate enough to have the privilege, late December and early January bring two things: new toys and a bit of vacation time. That makes it a great time to tinker with little tech projects, things that are inessential and maybe a bit time-consuming but fun enough and useful enough to be worth doing.
One of my projects was to experiment with classic console emulators on the new Apple TV. There aren’t many of them yet, and installation takes a little work (Apple doesn’t allow add-your-own-ROM emulators in the App Store), but new capabilities introduced in iOS 9 and the iOS-based tvOS make it possible to install them.
Right now there are two notable emulation projects targeting tvOS. One is a distant relative of the MAME arcade emulator, though it doesn’t seem as though it’s being maintained. Another, Provenance, is the one we’ll be spending the most time with. It’s a multi-system emulator that supports most major 8- and 16-bit consoles, including the NES, SNES, Sega Master System, Sega Genesis, Sega CD, Game Boy, and Game Boy Advance.
I don't know if any readers play this game, but it's not important. I want to find an algorithm to solve the following problem.
There are several buildings, and each of them have a list of upgrades, the upgrades have to be done in order (these are just simple checking, I can do). The upgrades are measured in days.
I have n builders, for convenience n is from 1~5.
Now I want to schedule the upgrades to the n builders, but here's the trick, I want to have at least a builder finish a build every single day, the reason is not important.
So the following is a valid schedule:
Builder 1: Archer Tower 3 days, Cannon 1 day
Builder 2: Cannon 1 day, Cannon 1 day, Barracks 3 days
Because Builder 1 is free on day 3, 4 and 5, and Builder 2 is free on day 1, 2, 5.
But following is not valid:
Builder 1: Archer Tower 3 days, Cannon 1
Builder 2: Barracks 3 days, Cannon 1, Cannon 1
Because there are no builders free on day 1 and 2.
So is it possible to solve this in reasonable time? Cause I wrote a program to try all combos and it cannot finish in reasonable time.
I'm a second year university student, so my knowledge in this field is still not that much.
Thank you for reading, and thank you for helping out.
The rest of us might be celebrating that we can finally keep playing Candy Crush during takeoff or landing , but flight attendants don't seem to be too happy about the new regulations: the biggest union for flight attendants is suing the FAA to change the rules back.
A group of 3 friends cannot agree on where to eat. Each person prefers a different restaurant and no one is willing to compromise.
Eventually they agree it would be fair to choose the restaurant at random. How can they use a coin to decide, making sure each restaurant is picked with equal chance?
What if the coin is biased, but they don’t know if it produces more heads or tails?
Extension: how can you use a coin to choose between n items equally? What if the coin is biased?
Answer to choosing randomly with a coin
If the coin is fair, there is a simple procedure for choosing between 3 items randomly. The group can flip the coin two times, and that will produce 4 events with equal probability: HH, HT, TH, and TT. Let the first three outcomes correspond to each of the three choices. If the fourth event happens (TT), then disregard it and repeat with two more flips.
In other words, flip the coin two times and then let:
HH: choice 1
HT: choice 2
TH: choice 3
TT: do-over, flip the coin 2 more times and repeat
There will be some do-overs, but mostly this procedure will result in a choice in a matter of a few tries.
As an aside, if we relabel the choices as 0, 1, 2, we can “encode” the coin flips as binary bits for a natural mapping between the flips and the choices. If we let H = 0 and T = 1, then
HH = 00 = choice 0
HT = 01 = choice 1
TH = 10 = choice 2
HH = 11 –> repeat
What if the coin is biased?
If heads occurs more frequently than tails, it will no longer be true that HH and HT occur with the same probability. So how can we choose between 3 items in this case?
It seems like we are stuck, but we can use a trick. Let’s first see how we can choose between 2 items. In other words, let’s make a “fair toss” from this unfair coin.
The procedure is this. Flip the coin 2 times. Let HT denote one choice and TH denote the other. If the flip is HH or TT, then disregard and repeat with two flips again.
We can prove this results in creating two events that happen with equal chance. To see why, let’s say that H occurs with probability p and T with probability 1 – p. When we flip the coin twice, we have:
HT occurs with p(1 – p)
TH occurs with (1 – p)p
We’ve created two events that happen with equal chance, even though the coin itself is biased. The trick was making sure to only consider outcomes where the number of H’s equals the number of T’s.
How can we generalize this for choosing between 3 items?
What we have to do is flip the coin 4 times. Now we disregard the ouctcome if the number of H’s and T’s is not equal. We are left with 6 choices in which there are 2 H’s and 2 T’s. We can label these as follows:
HHTT, HTHT: choice 1
HTTH, THHT: choice 2
THTH, TTHH: choice 3
any other result: disregard and repeat the 4 tosses again
This procedure will result in each of the three restaurants being chosen with equal chance.
(Obviously this is just one way to label the outcomes with choices. Any method that assigns 2 of the equally likely events to each of the 3 choices will be valid.)
Generalizing to n
Based on this logic we can make random choices between n choices using a coin. (This is not the most efficient way to do it, but it’s easy to understand which is important so everyone can agree the procedure is fair!)
If the coin is fair: flip the coin k times with 2k ≥ n > 2k-1. Label n of the equally outcomes with each of the choices 1, 2, …, n. For any other outcome flip the coin again until it results in one of the labeled choices.
If the coin is not fair: We need to flip the coin so there are at least n outcomes where the number of heads is equal to the number of tails. That means we should flip the coin 2k times such that 2k choose k ≥ n. Label n of the equally outcomes with each of the choices 1, 2, …, n. (We can make this slightly more efficient. We can actually accept jn of the outcomes by dividing the outcomes into n groups of j outcomes each. Recall that in the case of n = 3, we has 6= 2*3 outcomes that were divided into 3 groups where each choice got 2 outcomes). For any other outcome flip the coin again until it results in one of the labeled choices.
Watching GoPro footage makes it clear that there is basically nothing cooler than first-person action sport shots. And for those who are spending the day at the skate park, one Kickstarter project is hoping to take that genre of filming to the next level.
STABiLGO is a handheld, motorized GoPro stabilizer that keeps the camera level and steady as you turn down a half-pipe or mountain. Creators Michael Boczon and Christine Reilly have raised $33,885 of their $100K goal so far with 12 days left.
If you’re wondering how this product didn’t exist already — produced by someone like GoPro or one of its die-hard fans, for instance — don’t ask Boczon. He doesn’t know either. A technical producer and video editor at MTV, he said others had advanced directly to creating aerial rigs and somehow bypassed handheld stabilizers. But Boczon and Reilly have clearly caught a technology wave that others are riding, too. The day after they had been rewinding motors for the STABiLGO, a pre-made motor became available for purchase online.
After playing catch-up with the development of the individual components, STABiLGO seems to have broken ahead of the pack. After STABiLGO went up on Kickstarter, six different groups reached out to say that Boczon had beaten them to the punch by only a few weeks.
The aim is to move STABiLGO into retail production in China, which Boczon said he intends to do with or without the Kickstarter money. The prototype costs about $450 in parts to produce, and Boczon said they would likely set the retail price between $600-$700.
“In the end, our goal was to use it when we go snowboarding,” he said. “Come this season, I will have my unit.”