Guys, I need a function that given an integer n, will generate the set of all numbers with number of digits n, which have the property of being tidy.
Being tidy means a number which has their digits ordered from lowest to biggest, like so, "12289" or "1334589"
Can somebody help, I can't even begin to imagine how to implement such a function, thanks.
First way I though of to do this is to write a function to separate a number into its digits in an array.
Then test if that array is sorted and if it is then the number is "tidy".
Then write the main function where the input decides the number of digits so lower lim is 10^n and upper lim is 9.....9 n times and return all the tidy nums between the limits.
Place numbers in a base ten system are 10, 100, 1000, etc.
n/1000 =digit in 1000s place
n/100=digit in 100s place
... so on. If you do it this way you don't need to know how long the number is because you can discard a number <1.
Now that you've saved them, check the digits in descending order.
>>59834540
Is that the Rodger
>>59834540
This is isomorphic to subsets of 8 numbers from the set 1 to N+8. Think of each chosen number from the subset as a "divider", e.g. if you have the subset [1, 2, 3, 4, 9, 10, 11, 12] you have ||||....|||| and your number is 5555. If your language has a way to generate combinations and permutations, you're halfway there.
>>59836538
Fun fact, the natural way of doing this transforms the lexicographically ordered subsets into the reverse lexicographically ordered tidy numbers.
>>59834540
recursion n times
at each node, only allow Int's that are equal to or less than the parent
then concatenate the digits as a string
>>59836561
won't n-ary trees work better?
>>59834540
n = 5:
11111
11112
^^^^^subproblem of n = 4, recursion with max of 2:
1112
1122
1222
2222
back to normal problem:
11113
11123
11223
12223
22223
11133
etc. stick 'em in an array or whatever while you go or act on them or whatever. What are you using this for?
>>59837871
i.e. basic recursion function would be to check if the first digit is equal to the max, if not increase it by one and then the recursion on all the digits to the left of it with a max of the current digit.
>>59834540
Ok, OP. Give me fifteen minutes while I do your fucking homework you.
Be right back.
>>59839847
>1 hour ago
>>59840412
Almost done, just a few more minutes.
>>59834540
This is the google code jam assignment, right?
>#!/usr/bin/python3
>import sys
>n= int(sys.argv[1]) if len(sys.argv) ==2 else >sys.exit(1)
>for num in range(int("1"*n),10**n):
> num= str(num)
> if not any(int(num[p+1]) < int(num[p]) for p in range(n-1)):
> print(num)
Am I right?
don't know why the fuck a ">" between the "else" and "sys.exit(1)" is. sry
>>59834540
H O M E W O R K
O
M
E
W
O
R
K
>>59836483
yeh. he should've give dick a try.
>>59842095
hey faggot, this is google code jam
not homework, faggot