GithubHelp home page GithubHelp logo

Comments (3)

devkabiir avatar devkabiir commented on September 14, 2024 1

If I'm not mistaken this would require handling the new cases with BigInt.

You are correct, int in Dart is limited to 64 bits. We have to use BigInt

Do you think this would be a good addition for this track?

Yes, I have been bitten by not using the correct numeric type in my Databases and code in the past. It's helpful to know.
As far as I know, we don't cover this anywhere? @Stargator

Right now armstrong-numbers is listed as difficulty 1 (scale is 1-10). Would adding BigInt complicate matters enough that we would have to bump the difficulty up a bit? Do we want to do that?

The complexity would not increase. It is a matter of changing types. If we must increase the difficulty, I would say increase by 0.5.

I don't have a strong opinion, but at the moment I'm leaning slightly in favor of leaving the exercise as is. I'm happy to be convinced otherwise, though.

The existing solutions would break for sure.
However, it would be good dogfood for your test generator and see how it reacts?. Generating tests for this exercise would not be trivial!


To make the tests spec compliant and working, following changes would need to be made

example.dart
class ArmstrongNumbers {
  /// The parameters and variables within the method that are set to final in order to prevent the accidentally modification of the value.
  /// As those variables are not needed to be changed.
  bool isArmstrongNumber(final String input) {
    final numOfDigits = input.length;
    var sum = BigInt.from(0);

    for (var count = 0; count < numOfDigits; count++) {
      final digitAsString = input.substring(count, count + 1);
      final digit = BigInt.parse(digitAsString);
      sum += digit.pow(numOfDigits);
    }

    return input == sum.toString();
  }
}
armstrong_numbers_test.dart

Instead of using number literals, we need to use '<literal>'

-    final bool result = armstrongNumbers.isArmstrongNumber(0);
+    final result = armstrongNumbers.isArmstrongNumber('0');

from dart.

kytrinyx avatar kytrinyx commented on September 14, 2024 1

Excellent. Difficulties are ints, not floats, so we could bump it to 2.

I will give this a shot.

from dart.

Stargator avatar Stargator commented on September 14, 2024

As far as I know, we don't cover this anywhere? @Stargator

Correct. We don't use BigInt anywhere nor do we have anything related to databases.

I agree with devkabiir's response. This shouldn't be a change, despite breaking the current solutions.

from dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.