Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / How many numbers below one million have increasing digits?

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th May 2006 01:35
How many numbers below one million have increasing digits?

That's the new challenge in the DBPro Coding Challenges (stickied thread above).

A number has increasing digits if each digit is not exceeded by the digit to its left and is said to be an increasing number; for example, 45579. There are exactly 219 increasing numbers below one-thousand, but how many numbers below one million are increasing?

The challenge is to write a piece of code which calculates the answer. The winning code will be the one that does it in the least amount of lines.

Everybody is welcome to enter - the winner will be added to the hall of fame, and will have the honour of setting and judging the next challenge. You have until Thursday 11th May.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th May 2006 01:43
Im trying to understand the concept, so for example there would be 4 increasing numbers in 10? (1 + 2 + 3 + 4)?

Sorry if Im missing something blatantly obvious, just a little confused about what you mean by increasing numbers. Im assuming by using the example you gave of 1000, that 1+2+3+4+5....etc would eventually equal some number close to 1000, and the amount of additions performed is the increasing number?

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th May 2006 02:43
Nothing so complex, Ruccus! Increasing numbers refer simply to the digits which make up the number. The number 12 is made from the digits 1 and 2. As 2 is greater than or equal to 1, the numbers are increasing. The number 10 is made from the digits 1 and 0. But as 0 is less than one, the numbers are not increasing. The number 45579 is increasing because each digit is greater than or equal to the digit to it's left.

Out of all the numbers less than 1 million, we want to know how many of them have increasing digits.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th May 2006 02:48
Ahhh I see, I might get to work on this now then, thanks for clearing it up Ric

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 5th May 2006 02:55
this is best solved using a Binary Search Tree. and recursion.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th May 2006 03:03 Edited at: 5th May 2006 03:03
Ric are you sure that there are 219 increasing numbers in 1000? Because I've come up with a fairly basic system thats returning true results for "known" answers, but as I dont know if 219 is correct for 1000 I may be wrong. Currently my system is returning 1 increasing number for 12 (true), 8 increasing numbers in 20 (true), and 15 increasing numbers in 30 (true), so judging by the results and the fact that I'm using fairly different numbers, it seems like my system is working. However it returns a total of 120 increasing numbers in 1000, is it possible that your answer is wrong?

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th May 2006 03:16
locked the other thread.
DON'T DOUBLE POST

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 5th May 2006 04:40
@CattleRustler
at a quick glance your "MOD" icon looked like it says "MOO". Which I personally think would be more appropriate.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 5th May 2006 15:27
@zen, lol

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 5th May 2006 21:17 Edited at: 5th May 2006 21:21
@ruccus - The difference between your results and rics is that ric is counting equal as increasing digits. This means between 1 an 12 you don't just count 12, but 11 too.

Another difference is that it looks like ric is having 1-9 count as increasing digits because there is no larger digit before it.

Doing this he probably got 5004 as amount of numbers which have increasing digits between 1 and 1 million.

Insanity is just a state of mind
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th May 2006 22:18
Ah I see, but would that not be concidered incorrect then o.O , since 11 doesnt have increasing digits, it has equal digits...

Anyways I checked out the "official" board of these coding challenges and pretty much everyone is using the same theory as I was so not much point in submitting it, as its almost identical to Spooky's

Ahwell maybe next time.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 7th May 2006 20:49
Contest is over, it was done in 1 line

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 7th May 2006 22:01
In the Darkbasic Pro boards. First Stickied Thread.

Login to post a reply

Server time is: 2024-09-24 23:25:40
Your offset time is: 2024-09-24 23:25:40