Period of decimal fraction
📁 method, Advanced Python Topics, example
Problem: the function receives two integers (int(a), int(b)) as input. It should return the quotient a/b, with repeating digits (the period) enclosed in parentheses.
Examples:
1/3 = > 0.(3)29/12 = > 2.41(6)5/3 = > 1.(6)I approached solving the problem using brute force. I iterated through the fractional part, looking for matches. But in the case of 1/117, the period contains more than 90 digits, and iterating through the numbers takes longer than allowed by the problem.
What
My approach is to iterate through the database and check for matches:
First, let's get the database from this source
In the left window, in step 3, select Russian (Cyrillic) - in the right window I select United States, for generation specify only the fields we are interested in: Gender, Given Name and Surname, make the database the largest: 50000
Also, let's order a database for English names by analogy.
The process is not fast, so you can go make some tea and have a cigarette. When we come back, we will receive 2 emails with download links for our databases.
Let's write the code:
import pandas as pddfru = pd.read_csv('FNru.csv')dfen = pd.read_csv('FNen.csv') Log in to leave an answer