All problems

Is This Leaf Pure?

easyPythonDecision Trees

A rule-book stops working on a group the moment there is nothing left to separate — every claim in it ended the same way. A group like that is called pure, and it becomes a leaf. Ashby Mutual's build tool reports on each group as it goes: either the group is pure, or it is not, in which case the modellers want to see how mixed it still is, measured as Gini impurity. Pure means exactly pure. One claim that ended differently from the rest makes the group impure, however lopsided the mixture is.

Task: Report whether the group is pure, and if it is not, how impure it is.

Input

Two lines. The first holds n, the number of possible outcomes. The second holds n whole numbers separated by single spaces — how many of the group's claims ended in each outcome. Several counts may be zero.

Output

One line. If the group is pure, print exactly pure. Otherwise print the word impure, a single space, and the group's Gini impurity written with exactly 4 digits after the decimal point — so a group that is 0.48 impure prints as impure 0.4800.

Example:

Input:
2
50 0

Output:
pure

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…