Signs and Numerals
Description:
Description
You are a baby, and you have a box of toys... or rather, a box of wooden math symbols and numbers. Your parents give you a number and ask you to find every configuration of the symbols and numbers that lead you to the number they gave you.
You are an exceptionally lazy baby, so you decide to create a program on your 3DS to help you.
Given a String e consisting of numbers and operators separated by spaces and a singular integer x, return an array of Strings representing of all possible configurations of the signs and numerals in e that equate to x.
Example:
Input: e = "3 * 2 + 10", x = 23
Output: ["10 * 2 + 3", "2 * 10 + 3", "3 + 10 * 2", "3 + 2 * 10"]
Assumptions
Each number in e will be between -100 and 100 inclusively.
Your toybox can only fit up to 5 numerals.
The count of operators in e will always be equal to the count of numbers in e minus 1.
You don't know decimals yet, so you simply round them down.
Signs and numerals are always be separated by a single space in your input.
The only operators in your box are
+
,-
,*
, and/
.You do not take signs and numerals out of your box in any particular order. Expect to recieve input Strings that look like
"2 + 3 10 4 * /"
.
Requirements
All output Strings must be valid equations.
- Equations dividing by zero can be considered to be invalid.
Signs and numerals should be separated by a single space in your output.
Order output Strings lexigraphically.
- E.g.
*
has a unicode value of 42 while+
has a unicode value of 43, so"2 * 2"
comes before"2 + 2"
.
- E.g.
Every equation in the output string should be unique. That is, you do not need to repeat any Strings. :)
- E.g. given an input e =
0 + 0 + 0 + 0
and x =0
, your output should be0 + 0 + 0 + 0
.
- E.g. given an input e =
Similar Kata:
Stats:
Created | Oct 28, 2024 |
Published | Nov 3, 2024 |
Warriors Trained | 15 |
Total Skips | 0 |
Total Code Submissions | 48 |
Total Times Completed | 7 |
Java Completions | 7 |
Total Stars | 2 |
% of votes with a positive feedback rating | 50% of 3 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |