tag:blogger.com,1999:blog-1436098877388372574.post4855942527233405185..comments2023-10-25T09:07:12.472+00:00Comments on oogifu: Coding ChallengeTango Juliethttp://www.blogger.com/profile/13490879613902305035noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-1436098877388372574.post-89749970912296454082008-06-29T09:20:00.000+00:002008-06-29T09:20:00.000+00:00Nice solution from CB:http://crazybob.org/BeustSeq...Nice solution from CB:<BR/><BR/>http://crazybob.org/BeustSequence.java.htmlTango Juliethttps://www.blogger.com/profile/13490879613902305035noreply@blogger.comtag:blogger.com,1999:blog-1436098877388372574.post-24683204500861043292008-06-28T19:59:00.000+00:002008-06-28T19:59:00.000+00:00Following my investigation, a "clever" solution, o...Following my investigation, a "clever" solution, only valid when max is a multiple of 10: 1000, 10,000, 100,000....<BR/>Result is immediate:<BR/><BR/>public class CC2 {<BR/>static final int[] PCA = {<BR/>9,<BR/>9 * 9,<BR/>9 * 9 * 8,<BR/>9 * 9 * 8 * 7,<BR/>9 * 9 * 8 * 7 * 6,<BR/>9 * 9 * 8 * 7 * 6 * 5,<BR/>9 * 9 * 8 * 7 * 6 * 5 * 4,<BR/>9 * 9 * 8 * 7 * 6 * 5 * 4 * 3,<BR/>9 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2<BR/>};<BR/>static final int[] ST = {<BR/>9,<BR/>98,<BR/>987,<BR/>9876,<BR/>98765,<BR/>987654,<BR/>9876543,<BR/>98765432,<BR/>987654321<BR/>};<BR/><BR/>public static void main(String[] args) {<BR/>// 4 is up to 9999, 5 up to 99,999, 9 up to 999,999,999,<BR/>// Biggest is 9,876,543,210<BR/>int nbd = Integer.parseInt(args[0]);<BR/>int max = (int)Math.pow(10, nbd);<BR/>int nbt = 0;<BR/>for(int i=1; i <= nbd; i++) {<BR/>nbt += PCA[i-1];<BR/>}<BR/>int rjump = max - ST[nbd-1];<BR/>System.out.println("For Max "+ max);<BR/>System.out.println("Total Count Of Numbers: " + nbt);<BR/>System.out.println("Relative Jump: "+rjump);<BR/><BR/>}<BR/>}Tango Juliethttps://www.blogger.com/profile/13490879613902305035noreply@blogger.comtag:blogger.com,1999:blog-1436098877388372574.post-16386861873844117652008-06-28T13:25:00.000+00:002008-06-28T13:25:00.000+00:00But, there is an easier solution to the total coun...But, there is an easier solution to the total count of numbers, for 1 to 10,000:<BR/>I am going to do it from 1, to 9,999 as 10,000 is not part of it (4 0s):<BR/><BR/>How many 4 digits number can be made out of 0, 1, ..., 9 if no digit can repeat:<BR/>9 (9 choices for the first digit, no 0) * 9 (for the second) * 8 (third) * 7 (fourth) = 4,536<BR/><BR/>How many 3 digits number can be made out of 0, 1, ..., 9 if no digit can repeat:<BR/>9 (9 choices for the first digit, no 0) * 9 (for the second) * 8 (third) = 648<BR/><BR/>How many 2 digits number can be made out of 0, 1, ..., 9 if no digit can repeat:<BR/>9 (9 choices for the first digit, no 0) * 9 = 81<BR/><BR/>How many 1 digits number can be made out of 0, 1, ..., 9 if no digit can repeat:<BR/>9 (9 choices for the first digit, no 0) = 9 (0 excluded)<BR/><BR/>So the total count is 4,536 + 648 + 81 + 9 = 5,274<BR/><BR/>As for the biggest jump, it can only appear in the 4 digits one, so it is 10,000 - 9,876 = 124<BR/>(99xx, 9899, 9898, etc.. going down to 9,876)<BR/><BR/>Thierry<BR/><BR/>PS: also posted on Cedric's blogTango Juliethttps://www.blogger.com/profile/13490879613902305035noreply@blogger.com