wu :: forums
« wu :: forums - Pick digits in a given number for minimal sum »

Welcome, Guest. Please Login or Register.
May 15th, 2024, 3:32am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Eigenray, towr, ThudnBlunder, Icarus, SMQ, william wu, Grimbal)
   Pick digits in a given number for minimal sum
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Pick digits in a given number for minimal sum  (Read 773 times)
Bala69
Newbie
*





   


Gender: male
Posts: 5
Pick digits in a given number for minimal sum  
« on: Aug 31st, 2011, 6:39am »
Quote Quote Modify Modify

Can anyone plz give me algorithm for following problem:  
 
Requirements:
Input a single decimal number of arbitrary length.  
Treat each digit in the number as a single separate digit.  Pick digits from the input so that the sum of your choice is the minimum possible - you can skip *at most* one digit in a row. (If you skip digit n, then digit n+1 must be included in the total).  
Print out the input number, the set of numbers added, and the minimum total.  
 Examples:  
 Input 2413    Output 2+1=3  
Input 111114     Output 1+1+1=3
Input 39915691      Output 9+1+6+1=17
Input 142159119    Output 1+2+5+1+1=10(Note:here you are adding two adjacent digits i.e 1+1)  
 Note:You can add two adjacent digits but you cant skip two adjacent digits)
IP Logged
Grimbal
wu::riddles Moderator
Uberpuzzler
*****






   


Gender: male
Posts: 7527
Re: Pick digits in a given number for minimal sum  
« Reply #1 on: Aug 31st, 2011, 7:51am »
Quote Quote Modify Modify

Consider the partial problem of finding the best sum for the first n numbers:
a(n) = smallest possible sum with the first n numbers, including the last digit in the sum,
b(n) = smallest possible sum with the first n numbers, excluding the last digit in the sum.
 
Can you compute a(1), b(1)?
Can you compute a(n), b(n) from a(n-1),b(n-1)?
Can you compute the best sum overall from the a(n), b(n)?
IP Logged
iPhone-5
Newbie
*





   
WWW

Posts: 1
Re: Pick digits in a given number for minimal sum  
« Reply #2 on: Sep 1st, 2011, 6:26pm »
Quote Quote Modify Modify

Thanks Grimbal
 
I solved my similar problem  Grin
IP Logged
Bala69
Newbie
*





   


Gender: male
Posts: 5
Re: Pick digits in a given number for minimal sum  
« Reply #3 on: Sep 1st, 2011, 10:19pm »
Quote Quote Modify Modify

Thanks Grimbal Smiley.
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board