id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

tmhscs@gmail.com competition > UIL2015_INVA_02_BENFORD
prev  |  next  |  chance

Chris and Matthew are on the committee for a local scientific journal. In the past they’ve had a problem with
accidentally publishing papers whose authors fabricated fraudulent experimental results. As a result, the journal is
having serious funding issues and must come up with a way to detect these academically dishonest papers before
publishing them.

Luckily for the company, Matt was recently browsing Wikipedia (that’s what he does in his free time) and read about
a frequency distribution law, called Benford’s Law, that states that the digit 1 occurs as a leading digit about 30% of
the time in most real life sources of data. Matt wants to write a program that will automatically analyze the
distribution of leading digits in any random set of numbers.

Input: Integer Array
The data points in a test case.

Output: String
For each test case, output whether the numbers in the test case pass Benford’s Law’s distribution. A dataset is said to
pass Benford’s Law if the percentage of numbers that begin with a leading 1 digit is within 30±5%. If the dataset
does not pass Benford’s Law, print the percentage of numbers that began with a leading 1 digit, rounded to the
nearest hundredth.

UIL2015_INVA_02_BENFORD([10, 5, 9, 2]) → "PASSED"
UIL2015_INVA_02_BENFORD([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) → "FAILED: 20.00%"
UIL2015_INVA_02_BENFORD([17, 100, 49]) → "FAILED: 66.67%"

...Save, Compile, Run (ctrl-enter)

public String UIL2015_INVA_02_BENFORD(int[] data) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy