Giter Club home page Giter Club logo

mathpuzzle's Introduction

Problem

Suppose one has matrix

The problem is to find number e if two pairs of numbers (a,b,c,d) is given (using only simple arithmetic operations (+, -, /, *)(brackets are allowed)).

Example of problem

For two given matrices

,

Find e using only simple arithmetic operations (+, -, /, *) (brackets are allowed).

e = 106 (one can run MathPuzzle.sql to check this cd - ab).

Main Idea

  1. Generate all possible combination of 4 letters expressions (using reverse polish notation).
  2. Replace 4 letters with given numbers.
  3. Use Dijkstra's Two-Stack Algorithm to calculate the final value.
  4. Find solution to the problem by SQL query.

Solution

  1. Stack.typ is ordinary stack structure implimented in PL/SQL.
  2. MathPuzzle.pck this file contains declaration and body which allow to solve current problem
  • function is_operand(x varchar2) return boolean
    Function returns True if current element of the string is operand
  • function get_infix_from_postfix(string_ varchar2) return varchar2
    Function return infix notation from postfix
    723*- --> 7 - 2*3.
  • function can_add_operator(string_ varchar2) return boolean
    The function returns True if we can add operator to current expression:
    we scan the list and add +1 to counter when we meet a letter
    and we add -1 when we meet an operator (it reduces
    last two letters into 1 (say ab+ <--> a + b)
  • function concat (ilist1 as_array, ilist2 as_array) return as_array
    Function returns two concatinated collections
  • function possible_elements(items as_array, string_ varchar2) return as_array
    The function returns a list, that contains operators and
    letters, one of which we can add to the current expression.
  • procedure rec(exp varchar2)
    Main procedure that generates all possible 4 letters expressions and writes them into table.
  • function calculator (in_string varchar2 default '(1+((2+3)(45)))') return number
    Function returns evaluation of expression using Dijkstra's Two-Stack Algorithm
  • function substitute_letter_to_numbers(in_str varchar2, a number, b number,c number, d number) return varchar2
    Function returns numerical expression
    (((b+a)*c)+d) --> (((1+2)*3)+4) if a=1, b=2, c=3, d=4
  1. MathPuzzle.sql is the example of usage

Installation

  1. Run Stack.typ
  2. Run MathPuzzle.pck
  3. Run "begin MathPuzzle.rec(''); end;" to fill main table
  4. One can run queries agains filled table rpn_combinations

mathpuzzle's People

Contributors

alexeypustynnikov avatar

Watchers

 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.