Adding a Dig Deeper approach to the C# Perfect Numbers exercise

I wanted to add an approach to this exercise, is this something I can add a PR for?

If so:

  • Are there docs for this process?
  • I would like to use the 2nd iteration of my solution for this.
  • The differences with the existing approach are:
  • Using a (modern) switch statement
  • Avoiding the less than one check on the number by using a Range until number - 1 (which defaults to an empty range in case of a less than one number). This has a downside in performance.
  • Using the function in the Sum function to avoid using a separate Where.

My only concern is that this might be too much for a single approach in an easy exercise, or wouldn’t this be a problem?

The docs: Approaches | Exercism's Docs

Various authors have various styles. I recommend looking at a few from several authors for inspiration.

Unfortunately C# is the only track right now that has Perfect Numbers approaches.

This need not be a problem. Just explain everything that you feel requires explaining. There’s plenty of space.

If you really have a lot of material to explain, then be sure to organize it well so that the student can determine for themself which parts to read and which parts to skip.

1 Like

I think second approach that uses a switch expression would make a lot of sense.

I think both changes should also be made to the existing approach, as they make the code easier to read (I would recommend though still starting the approach explanation with the current contents but adding some content to refactor to the above changes.

2 Likes

Do you mean first adding a PR for a second approach (switch) and then adding a PR refactoring the existing (if) approach using the Range and Sum refactorings?

1 Like

Yep! That would be great

1 Like

@ErikSchierboom I’ve added this PR: Add switch expression approach to 'perfect numbers' exercise #2142 by aage · Pull Request #2143 · exercism/csharp · GitHub, can you have a look?

Edit: Wait, I need to fix something.

Edit: @ErikSchierboom Should be good now.

1 Like

@ErikSchierboom I’ve added a PR for suggested refactorings of the existing if statements approach: Combine where and sum when using sum only in 'perfect numbers' exercise approach by aage · Pull Request #2145 · exercism/csharp · GitHub