## CSE 131 Module 8: Abstract Data Types

Important!

Before beginning any work, do a Team...Pull in your repository.

## Extension 1: Sad Cycles (5 points):

Authors
• Fede Rozenberg
This extension needs a unit test. For now, run it as indicated at the end of this assignment.

#### Overview

So it turns out that numbers can feel things. We define a happy or sad number through this process:

1. Split up the number into its digits.
2. Square the digits and sum them.
3. Repeat with the new sum until you reach a set of numbers that repeat or the number 1.
4. If your process results in a repeating 1, your initial number was happy! Otherwise, it has fallen into a cycle of depression, characterized by the repeating numbers [4, 16, 37, 58, 89, 145, 42, 20, 4...] How sad.
For example, starting with the number 15, our process yields:
• 12 + 52 = 26
• 22 + 62 = 40
• 42 + 02 = 16
• 12 + 62 = 37
• 32 + 72 = 58
Here you can see our number has fallen into the beginning stages of depression...

In this extension you will be designing a program that uses sets to find the sad cycle of a number for an arbitrary power.

#### Procedure

• Create a method Set<Long> findCycle(int base, long n) that takes in a number n and either returns a Set<Long> with the base-sad cycle for n or with 1 as its only element.
A long is simply twice as long as an int. I recommend using it here because some of the numbers found in higher base-sad cycles can be quite large.
• Feel free to create any other methods you might need.
I highly recommend partitioning the splitting of digits, raising to the power of base, and summing into one method. The trick here is figuring out how to treat every digit in a number as its own entity.
• Test your program on inputs you find documented here. Show these results to a TA and convince him or her they are right for credit on this assignment.

When you are done with this extension, you must be cleared by the TA to receive credit.
• Do a Team…Pull to update your repository. You must do this or the commit/push below may fail.
Make certain this has worked by logging into bitbucket. There you will see the commit(s) in your news feed if it was successful. You can also check the Source page to locate and ensure your code was received.

It is your responsibility to make certain the code has been pushed. Some of your work receives credit through testing of your pushed code. You will receive no credit for such work if you failed to push. We generally reserve the right to revoke credit for any of your work that has not been pushed on-time.

• Fill in the form below with the relevant information
• Have a TA check your work
• The TA should check your work and then fill in the TA's name
• Click OK while the TA watches
• If you request propagation, it does not happen immediately, but should be posted in the next day or so

This demo box is for extension 8.1
 Last name WUSTL Key Propagate? (NOT your numeric ID) Do not propagate lower case only e.g. Smith j.smith 1

Acknowledgements and assertion of integrity