Giter Site home page Giter Site logo

uglycalc's Introduction

UglyCalc

Simple calculator with add, subtract and multiply that supports lazy evaluation.

Setting up

Install

Compile: (Windows)

g++ -std=gnu++11 uglycalc.cpp -o uglycalc.exe

On linux you can use the makefile: make.

Run

Run: (Windows)

uglycalc.exe

to read from the standard input, or

uglycalc.exe < [filepath]

if the input is in a file, or

uglycalc.exe [filepath]

to read from a file.

On linux you can use make test and put the test files in the input folder.

Assumptions & Limitations

  • If there are cycles in the dependecy graph of the input variables, then there can be contradictions. For example:
a add b
b add 10
b add a
print a

will result in a = 10 + a, a contradiction. So, my calculator throws an exception whenever there is a cycle in the dependency graph of the input variables. Even the case of a self-cycle like a add a.

  • The problem specification does not ban full numeric register names, like 123. I assume this is not allowed since it causes ambiguity. For example the following input:
x add 10
10 add 20
x add 10
print x

can return 20 or 30 or 40. So, my calculator does not allow full numeric register names.

  • My calculator supports integer numbers that fit in c++ int data type (including negative numbers), which usually corresponds to a 32-bit integer and returns a warning if an input number is out of the range of int. It also assumes that all the evaluations whenever print is called stay within the long long range, otherwise the printed value may be wrong.

  • I use map<string, int> map_values for memoization, i.e. to avoid computing the value of a register more than once during each evaluation.

uglycalc's People

Contributors

meysamaghighi avatar

Watchers

James Cloos avatar  avatar

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.