Jump to content
xisto Community
Sign in to follow this  
redskins

Necklace Problem In Visual Basic

Recommended Posts

I was wondering if anyone could write code for this program. Its the usual Necklace Problem I'll give you the problem.A Necklace is a collection of numbers that begins with two single digit integers, the next number is obtained by adding the first two digits together and saving only the ones digit. This process is repeated until the 'necklace' closes by returning to the original two numbers. I think it is a Do While Loop but i am not sure. Thankyou

Share this post


Link to post
Share on other sites

You are the second person to have reached here for this problem. You can find the VB .NET and C# codes for this problem at http://forums.xisto.com/no_longer_exists/

 

Its fairly easy to do. I'll jot down the algorithm for the Function that returns the output as a string.

 

Function Name: Necklace

Inputs: OrigFirstNum (integer) and OrigSecNum (integer)

Return: String

 

Step 1: Set FirstNum = OrigFirstNum and SecondNum = OrigSecNum

Step 2: Concatenate FirstNum and SecondNum and store the result in Output

Step 3: Repeat Steps 4 - 7 until FirstNum = OrigFirstNum and SecondNum = OrigSecondNum

Step 4: Set Result = FirstNum + SecondNum

Step 5: Set FirstNum = SecondNum

Step 6: Find the last digit of Result and store it in SecondNum

Step 7: Concatenate SecondNum to Output

Step 8: Return Output

 

To find the last digit of a number use the following algorithm:-

 

Function Name: GetLastDigit

Input: Num (integer)

Return: Integer

 

Step 1: Divide Num by 10 and return the remainder

Share this post


Link to post
Share on other sites

I was wondering if anyone could write code for this program. Its the usual Necklace Problem I'll give you the problem.
A Necklace is a collection of numbers that begins with two single digit integers, the next number is obtained by adding the first two digits together and saving only the ones digit. This process is repeated until the 'necklace' closes by returning to the original two numbers.

I think it is a Do While Loop but i am not sure.
Thankyou

You'll need a do loop, as shown in the link posted by turbopowerdmaxsteel. A While loop will need a variable, such as a boolean to be checked every loop. You'll have to exit the loop by changing the variable to false. As for Do loop, you just need to call Exit Do when the condition match what you want.

Share this post


Link to post
Share on other sites

Sounds like a homework problem to me. Not that I have never been guilty of doing “research” on the Internet, but I have always found the best way to retain knowledge is to work the problem out on your own. If you develop the mythology for problem solving then you will be able to apply that to many other areas of your life.Steps off soapbox.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.