19
I noticed that my car's odometer was at 101101 when I got to work today. Which is a cool number because it's binary (and a palindrome, but that's not important). Now, I want to know when the next time I'll have a binary odometer reading. I can't read the odometer while I'm driving, because that would be dangerous, so it'll have to be binary either when I get to work or get home.
There's really bad traffic on the way to and from my office, so I have to take a different route each day.
For the purposes of this challenge, a day is a round trip and starts with my commute to work.
You'll need to take the initial reading of the odometer and a 10 element sequence representing the amount of miles each way. This sequence should be repeated until you get to a binary odometer reading. You should then output the number of days it takes until we get to a binary reading.
Both the milage for the route and the odometer reading will be positive integers. The count of days will either be x
or x.5
, so your output of the day count needs to support floating point for half days. If the day count is an integer, you don't need to output the .0
. The odometer will always eventually reach a binary state.
Any form of input/output is acceptable and standard loopholes are disallowed.
Test cases:
101101, [27, 27, 27, 27, 27, 27, 27, 27, 27, 27] == 165.0
1, [13, 25, 3, 4, 10, 8, 92, 3, 3, 100] == 22.5
2, [2, 3, 1, 2, 7, 6, 10, 92, 3, 7] == 2.0
Will a day result only ever be an integer or an integer plus a half? – FryAmTheEggman – 2016-02-22T14:49:40.410
2@FryAmTheEggman Yes. Each step is half a day. – Morgan Thrapp – 2016-02-22T14:49:57.603
What should happen if the odometer never becomes binary? – CalculatorFeline – 2016-02-22T16:10:21.233
@CatsAreFluffy It always will. You don't have to worry about that case. – Morgan Thrapp – 2016-02-22T16:10:38.870
The days will be floating point. Could you elaborate a bit on that? – Dennis – 2016-02-22T16:37:37.997
@Dennis The day count will either be
x
orx.5
. That's all I meant. If you want to display that by formatting a string, or some other method, that's fine. It just needs to be in the formatx
orx.5
. – Morgan Thrapp – 2016-02-22T16:38:09.843@MorganThrapp isn't that fixed-point? – cat – 2016-02-22T20:19:49.140
@cat You might be right, my math terminology is shaky at best. – Morgan Thrapp – 2016-02-22T20:21:01.063
5Where do you work/live that 3, 25 and 92 miles (km?) are regular acceptable commute distances? – kingofzeal – 2016-02-22T21:27:43.017
1@kingofzeal A wormhole. – Morgan Thrapp – 2016-02-22T21:30:19.303
Heh, I hit that mark just a few days earlier – 101101 km
– florian h – 2016-02-23T12:37:04.857How many digits in the odometer? Actually, that doesn't matter, because it's a 1 that's lost in the roll-over. So we can code as if it always has enough room for one more digit. :-) – Toby Speight – 2016-02-23T15:38:41.727
1@TobySpeight It's a magical odometer with an infinite number of digits. – Morgan Thrapp – 2016-02-23T15:39:36.410