[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Guys, I need a function that given an integer n, will generate

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 19
Thread images: 2

File: chad.png (739KB, 620x616px) Image search: [Google]
chad.png
739KB, 620x616px
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
>>
File: sup.webm (779KB, 640x480px) Image search: [Google]
sup.webm
779KB, 640x480px
>>59836483
yeh. he should've give dick a try.
>>
>>59842095
hey faggot, this is google code jam
not homework, faggot
Thread posts: 19
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.