Skip to content

Instantly share code, notes, and snippets.

@harshithjv
Created February 16, 2016 16:19
Show Gist options
  • Select an option

  • Save harshithjv/fc490a904a06aba0b502 to your computer and use it in GitHub Desktop.

Select an option

Save harshithjv/fc490a904a06aba0b502 to your computer and use it in GitHub Desktop.
"""
For implementation of digits_0to5 refer this gist: https://gist.github.com/harshithjv/969f4fb820dd96e4739c
"""
from base_5_generator import digits_0to5
from collections import Counter
for i in digits_0to5(50000):
i_str = str(i)
digit_repr = tuple([int(j) for j in i_str])
num_counts = {'0':0, '1':0,'2':0,'3':0,'4':0}
num_counts.update(dict(Counter(i_str)))
num_counts_tuple = tuple([num_counts[str(k)] for k in range(5)])
if digit_repr == num_counts_tuple:
print i
break
@harshithjv
Copy link
Copy Markdown
Author

Puzzle description:

Its a 5 digit number where…

1st digit denotes how many zeroes are there in the number

2nd digit denotes how many ones are there in the number

3rd digit denotes how many twos are there in the number

4th digit denotes how many threes are there in the number

5th digit denotes how many fours are there in the number

Can you guess the number?

Answer:

Lets say there are 4 0’s, so number should be 40000, but this violates that 5th digit tells how many 4’s are there.

Now lets say there 3 0’s then number can be 30010, but thus also violates, 2nd digit tells number of 1’s

Now if there are 2 0’s then 21200 satisfies all the conditions.

The solution solves the puzzle in 800 cycles in the for loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment