Beta

The 8 Elements Of Spells

Description:

Welcome to a make-belief world in which magic runs based upon the serveral principles listed below.

  1. There are four basic elements: Water (W), Earth (E), Air (A), and Fire (F).
  2. There are four complex elements: Light (Li), Shadow (Sh), Aether (Ae), and Void (Vo).
  3. Each element has a unique energy requirement.
  4. To use one unit of an element (W = 1 unit of water; W2 = 2 units of water), there must be enough energy.
  5. A spell must have more than the required energy. (Use EPSILON = 1e-14 to compare the doubles.)
  6. If a spell requires no elements (compound.length() == 0), then the function returns true.
  7. 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:

CreatedOct 24, 2018
PublishedOct 25, 2018
Warriors Trained132
Total Skips37
Total Code Submissions80
Total Times Completed15
Java Completions15
Total Stars3
% of votes with a positive feedback rating80% of 10
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • WaveSplash Avatar
Ad