Pages

October 25, 2011

Project Euler #315

Problem: Digital Root Clocks

Solution: [Spoiler Ahead]

       One of the easy problems and one of the easy solutions.
       It's just straight forward,

the number of LED on-off by SAM's clock - the number of LED on-off by MAX's clock

       Globals I used, a noOfLEDsForDigit[] array holding the number of led's required to glow a particular digit.
A digits[] array holding hex values for the number that represent the ON-OFF LED. e.g.






bit LED
------------
0 top
1 middle
2 bottom
3 top-left
4 top-right
5 bottom-left
6 bottom-right



     Digit   Binary representation    Hex_value
-------------------------------------------------------
0 0111 1101                      0x7d
1 0101 0000                      0x50
2 0011 0111                      0x37
3 0101 0111                      0x57e
4 0101 1010                      0x5a
5 0100 1111                      0x4f
6 0110 1111                      0x6f
7 0101 1001                      0x59
8 0111 1111                      0x7f
9 0101 1111                      0x5f

                 Now the calculations become very easy,

For SAM: it's just the twice the sum of number of LED's in the digit(or no. of 1's in it's binary representation according to above user-defined digits)

For MAX: we need to get the common LED that will not be turn off when number changes from 'a' to 'b', this is given by XORing both value i.e.(a^b), plus the LED's that need to be turned on to complete the number 'b'.


There it is , therein lies the rub !


No comments:

Post a Comment