Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Go program to do the following: Reads problems from STDIN as a list of positive integers separated by whitespace, one problem per line.

Write a Go program to do the following:

Reads problems from STDIN as a list of positive integers separated by whitespace, one problem per line. Output a solution to the problem to STDOUT that makes the equation valid. Each +, -, *, /, and = must be passed by one space on each side. If no solution is found simply output a blank line to STDOUT. Errors in parsig STDIN exit with a non-zero status code after writing the error to STDERR. Your program must use recursion to search for solutions

use only Go standard library.

Example Output

$ echo "3 1 2" | go run . 3-1=2 $ echo "5 4 2 22" | go run . 5*4+2=22 $ (echo "3 1 2" && echo "9 2 18") | go run . 3-1=2 9*2=18 $ echo "6 2 3 4" | go run . 6*2/3=4 $ go run . < testdata/basic.txt 3 - 1 = 2 9 + 0 = 9 2 * 3 = 6 4 + 5 = 9 4 + 5 + 6 = 15 2 + 3 + 1 = 6

With multiple solutions it looks like:

$ echo "7 3 3 7" | go run . -all 7+3-3=7, 7-3+3=7, 7*3/3=7 $ go run . -all < testdata/basic.txt 3 - 1 = 2 9 + 0 = 9, 9 - 0 = 9 2 * 3 = 6 4 + 5 = 9 4 + 5 + 6 = 15 2 + 3 + 1 = 6, 2 * 3 * 1 = 6, 2 * 3 / 1 = 6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions