Giter Site home page Giter Site logo

discomath / discomathserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from greyscaled/discmathapplicationsserver

0.0 0.0 0.0 167 KB

Applications of Discrete Math provided as a web service for educational purposes.

License: GNU General Public License v3.0

Java 99.71% Shell 0.29%
discrete-mathematics educational-project prime-factorizations prime-numbers

discomathserver's People

Watchers

 avatar

discomathserver's Issues

Factorization Message Can Be Not In Numerical Order

Describe the bug
It seems that the factorization sometimes shows out of numerical order.

Example: 2 * 2 * 11 * 5

Expected behavior
Factorization display is always in numerical order, ie: 2 * 2 * 5 * 11

factorization ordering

{
  "computationalSteps":[
    {
      "message":"divide 1589 by primes until the remainder is prime",
      "equation":""
    },
    {
      "message":"1589 is not prime",
      "equation":"try 2|1589"
    },
    {
      "message":"1589 is not prime",
      "equation":"try 3|1589"
    },
    {
      "message":"1589 is not prime",
      "equation":"try 5|1589"
    },
    {
      "message":"1589 is not prime",
      "equation":"try 7|1589"
    },
    {
      "message":"7|1589",
      "equation":"1589 = 7⋅227"
    },
    {
      "message":"remainder is prime, stop",
      "equation":""
    }
  ],
  "result":{
    "factors":{
      "227":1,
      "7":1
    },
    "number":1589,
    "message":"∴ 1589 = 227⋅7",
    "resultIsLogicallyTrue":true
  }
}

Rework ComputationalResult

I think a better approach for future is re-working base class into an Interface, and then specifying @JsonIgnore etc at the implementation level.

public Interface ComputationalResult {
    String getMessage();
    boolean resultILogicallyTrue();
}
public PrimeFactorizationResult implements ComputationalResult { }
public DivisibilityResult implements ComputationalResult { }
...

This way we're always guaranteed resultIsLogicallyTrue and message in the JSON deserialization, but we can add new properties as we see fit.

  • Method return in Controller can just guarantee the Interface
  • Internal services can use the implementation

Originally posted by @vapurrmaid in #3 (comment)

Add Divisibility Service for 11, 7

11

The divisibility rule for 11 is pretty trivial and is as follows:

Take the alternating sum of the digits (First - Second + Third....) -> is the result divisible by 11 ?

function isDivisibleBy11 (Number num):
  String N[ ]
  n = num.toString()
  n -> N[d0, d1, d2...]
  sum = 0; subtract = true;
  while (not empty(N)):
    if (subtract) sum -= N.pop()
    else sum += N.pop()
    subtract = !subtract

  return |sum| % 11 == 0

7

7 is a bit more challenging (recursive):

double the last digit and subtract it from the rest of n -> repeat until remainder is a multiple of 7 or not.

  • Verify that the base case for the above recursion is as follows: compute until 1 digit remains. If absolute value is 7, number is divisible by 7. Else number is not divisible by 7.

Open An Endpoint for Awakening The Service

Because that this project is hosted freely, the server is prone to sleep times which can cause an unnecessary wait time on the frontend.

Proposed Fixes

  • Add Actuator or similar endpoints that can be used to ping the server.

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.