Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:12:05+00:00 2026-06-15T11:12:05+00:00

Given an expression in the form of a string, solve for x. The highest

  • 0

Given an expression in the form of a string, solve for x. The highest power of x in the expression will be equal to 1. Operators allowed are +, * and -. These are all binary operators. So, 2x would be written as 2*x. Every operator will be followed by a single term or a constant.

For example, consider the following equation:

2*x+5-(4*x-7+(4-2))=10*x-9

This is a perfectly valid equation. Expressions of the form 1*2*3 are invalid, but 1*(2*3) is valid.

Given such an equation, we need to find a solution to x. If the equation is invalid, the program should display an error message.

Can someone give any idea about how this problem can be solved? The only thing that is coming to my mind right now is Lexical Analysis and Parsing using Context Free Grammars. But I have a feeling there is a much easier solution than that. Can someone throw some light on it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:12:07+00:00Added an answer on June 15, 2026 at 11:12 am

    (1) Convert e1 = e2 into e = 0 where e = e1 - e2.

    (2) Convert e into ax + b, for some a and b.

    (3) Solve, x = -b/a.

    Step (2) can be handled recursively, like this:

    F(k)     = 0x + k    // For any constant k.
    F(x)     = 1x + 0
    F(p + q) = let a_1x + b_1 = F(p)
               and a_2x + b_2 = F(q) 
               in  (a_1 + a_2)x + (b_1 + b_2)
        // Similarly for subtraction.
    F(p * q) = let a_1x + b_1 = F(p)
               and a_2x + b_2 = F(q) // At least one of a_1 and a_2 must be zero.
               in  (a_1*b_2 + a_2*b_1)x + (b_1*b_2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Evaluating a math expression given in string form Sorry about the long
I need to reduce this boolean expression to its simplest form. Its given that
Given a regular expression: /say (hullo|goodbye) to my lovely (.*)/ and a string: my
What regular expression can I use (if any) to validate that a given string
Given the following jQuery expression $(form).each(function () { var info = validationInfo(this); if (info)
Given an arbitrary input string I'm meant to find the sum of all numbers
Problem Given a boolean expression consisting of the symbols 0, 1, &, |, ^
Given a set of java regular expression patterns separated by an OR (i.e |
Given a thrush operator, I have a filter expression as one of the forms.
I have the following expression that should match the entire given word in case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.