Beta
The 8 Elements Of Spells
Description:
Welcome to a make-belief world in which magic runs based upon the serveral principles listed below.
- There are four basic elements: Water (W), Earth (E), Air (A), and Fire (F).
- There are four complex elements: Light (Li), Shadow (Sh), Aether (Ae), and Void (Vo).
- Each element has a unique energy requirement.
- To use one unit of an element (W = 1 unit of water; W2 = 2 units of water), there must be enough energy.
- A spell must have more than the required energy. (Use EPSILON = 1e-14 to compare the doubles.)
- If a spell requires no elements (compound.length() == 0), then the function returns true.
- If a spell is cast with an incorrect formula (example: W3T5) it will not cast.
Your objective in this Kata is to complete a function that returns whether or not a given spell can be completed when provided with its Elemental Formulae (similar to how carbon dioxide is written as CO2) and a value of energy available. You will find more information about each element below.
The Four Basic Elements
Water: Written as "W" with energy requirement of 20
Earth: Written as "E" with energy requirement of 10
Air: Written as "A" with energy requirement of 15
Fire: Written as "F" with energy requirement of 5
The Four Complex Elements
Light: Written as "Li" with energy requirement of 17.3
Shadow: Written as "Sh" with energy requirement of 17.3
Aether: Written as "Ae" with energy requirement of 30.2
Void: Written as "Vo" with energy requirement of -10.5
Below are all of the test cases used in samples. Note: You will be required to test 1000 random compounds to complete this kata.
assertEquals(true, SpellCast.castSpell("", 0));
assertEquals(true, SpellCast.castSpell("W", 20.1));
assertEquals(false, SpellCast.castSpell("Vo", -100));
assertEquals(false, SpellCast.castSpell("Li", 17.299));
assertEquals(false, SpellCast.castSpell("F", -4));
assertEquals(false, SpellCast.castSpell("F", 5.0));
assertEquals(false, SpellCast.castSpell("W2", 39.0));
assertEquals(true, SpellCast.castSpell("WVo2", 0));
assertEquals(true, SpellCast.castSpell("AeF10Vo", 70.1));
assertEquals(false, SpellCast.castSpell("LiShAe", 13));
assertEquals(true, SpellCast.castSpell("Li4Vo5E10", 123.935));
assertEquals(false, SpellCast.castSpell("FW", 25.0));
assertEquals(false, SpellCast.castSpell("cookie", -1));
assertEquals(false, SpellCast.castSpell("Li4Vo5T", 999));
Puzzles
Similar Kata:
Stats:
Created | Oct 24, 2018 |
Published | Oct 25, 2018 |
Warriors Trained | 132 |
Total Skips | 37 |
Total Code Submissions | 80 |
Total Times Completed | 15 |
Java Completions | 15 |
Total Stars | 3 |
% of votes with a positive feedback rating | 80% of 10 |
Total "Very Satisfied" Votes | 7 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 9 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |