samipshah86
BAN USER1 #!/usr/bin/python
2
3 import sys
4
5 # get number
6 l_input = sys.argv[1]
7 print l_input
8
9 l_output = ""
10 l_carry = 0
// reverse string
12 l_input = l_input[::-1]
13 print l_input
14 for i in l_input:
15 if int(i) > 7:
16 l_output = l_output + "4"
17 l_carry = 1
18 elif int(i) == 7 and l_carry == 1:
19 l_output = l_output + "4"
20 l_carry = 1
21 elif int(i) > 4:
22 l_output = l_output + "7"
23 l_carry = 0
24 elif int(i) == 4 and l_carry == 1:
25 l_carry = 0
26 l_output = l_output + "7"
27 else:
28 l_output = l_output + "4"
29 l_carry = 0
30
31 if l_carry == 1:
32 l_output = l_output + "4"
33
34 l_output = l_output[::-1]
35 print l_output
Logic is simple goes from LSD to MSD if number is greater than 7 make it 4 and make the carry 1 , carry is cleared if next digit goes from < 4 to 4 or < 7 to 7 but if it is greater than 7 carry is carry forwarded to next and so on. if there is carry at the end most significant digit "4" is added. This seems to work for all if next lucky number is equal to or more than the given number
- samipshah86 April 18, 2014I would use a graph. I already wrote the application and it seems to be working. However in the case I wrote my own graph using vector which was good for finishing it in a day. I am able to get any size boggle board and I can check any word whether it has a path or not. I just need a dictionary now in order to see if the entries are valid or not and the game is complete . And some nice UI.
- samipshah86 September 10, 2011
basically dictionary created for translation and then there is an iterate loop which is called recursively to print the number in words.
- samipshah86 April 19, 2014