Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
What I need:
Function to calculate N-th decimal digit of Pi. Example:
>>> pi_digit(1)
1
>>> pi_digit(2)
4
>>> pi_digit(3)
1
>>> pi_digit(4)
5
What did I tried:
While searching, found that code. It actually does what I need except one thing - it calculates all N digits, while I need only last. Is this possible to accomplish in efficient way? (if I just slice string for last character it wouldn't be so fast). Thanks in advance.
Why I need it:
I'm going to put that script, which would append digits to text file, onto my server and leave it for 20-30 days, and check the output.
see:
Unbounded Spigot Algorithms for the Digits of Pi
Jeremy Gibbons
The program under discussion is written in Haskell [5], a lazy
functional programming language. As a secondary point of this paper,
we hope to convince the reader that such languages are excellent
vehicles for expressing mathematical computations, certainly when
compared with other general-purpose programming languages such as
Java, C, and Pascal, and arguably even when compared with computer
algebra systems such as Mathematica.
https://www.cs.ox.ac.uk/jeremy.gibbons/publications/spigot.pdf
it can be implemented with pidigits
https://github.com/transmogrifier/pidigits
pidigits is avalaible through Python Package Index (PyPI) using pip.
>>> pip install --upgrade pidigits
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
As we all know in python, there is one type of data - complex . I read the doc and then cannot find the use case, when to use it, and then what's its characters?
a = 20
b = 328
c = complex(a, b)
print(type(c))
Complex data types are used for advanced calculation in Electronics and applied or astrophysics or such type, just like we use complex numbers in the real world.
Complex numbers are used in electronics and electromagnetism. A single complex number puts together two real quantities, making the numbers easier to work with. For example, in electronics, the state of a circuit element is defined by the voltage (V) and the current (I).
In python, some libraries are used these things like:-
SkiDL
PySpice
Numpy
...etc
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have been dipping my feet into programming and originally was making a simple macro in VBA to find a certain combination that sum to a given number when given a list of inputs. I imagined a number of tasks and minutes to do those tasks, and inputted a number of people to divide the minutes approximately equal between them. To give a concrete example, if I had eight tasks and three people, I might have the following variables:
M = [44,39,29,77,102,35,40,59]
N = 3
Avg = sum(M)/N
I want the program to be able to find the set of combinations for each person that sum closest to the average value. For instance in this example, I would like an output of something like:
A = [102, 40], B = [44,39,59], C = [29,77,35]
If anyone can at least lead me in the right direction with regards to this project, I would be grateful. While this began as an aside from a macro for an Excel sheet, I wouldn't mind if I learned more about optimization algorithms in a more suitable language like Python.
Getting each persons work as close as possible to the mean is equivalent to max-min fair allocation problem
It’s essentially an optimization problem — google research did some work on this here
https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45386.pdf
A CS professor wrote a Python module for this https://github.com/anirudhSK/cell-codel/blob/master/schism/utils/max-min-fairness.py
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Although this is a question of maths but I really wanted to figure out if something like this is possible or not by coding it .(preferably in C). I had the question posted in mathsstackexchange where I saw that there's a way to find out the cosets of D_12 in S_6 by using Python programming. Can someone just help me to figure out how are we doing this?
S_n is the group formed by all possible permutations of n-elements and D_2n is formed by the generators <r, s> where r =(123, n) and s=(1n)(2 n-1).
Here's the link to the answer
https://math.stackexchange.com/questions/3880306/find-the-cosets-of-d-2n-in-s-n
Also I am not accustomed to posting questions in stackoverflow, I really don't know how to add mathematical symbols.
Though the logic remains same, the implementation will vary from Python to c due to difference is data types and so on. So you should try learning Python, it’s very easy to learn and you can pick up writing code in Python within few days considering you already you know a few other languages. And writing such complex programs can be easy in Python due to the vast inbuilt libraries and readability. So it’s better if you learn Python and start implementing this in Python.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Can somebody help me write a code using python 3 that can solve the quadratic formula without using "import math"? Please !
As #Aurora001 mentioned, you should not ask for completed code. However, I think addressing the method you might use could be a good answer to your question, and I hope others agree. This is how I would approach the problem:
Prompt for input to get the coefficients a, b, and c.
Write a method that finds the square root of a number (several algorithms exist and can be found with a Google search) - There are also more built-in ways to do exponentiation in Python without the math module but this seems like it is for a class and the point may be to see if you can write a sqrt implementation.
Write a method that uses your custom square root implementation to solve the quadratic equation using the coefficients as parameters.
Test your two methods by doing a few test cases.
I hope this helps; post another question if you have more specific issues. I have noticed more people will be willing to assist if you generate your own code and ask about specific problems that you cannot solve.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Perhaps this is not the correct place to ask this question, and part of me thinks that there is no real answer to it, but I'm interested to see what experienced Python users have to say on the subject:
For maximum readability, concision, and utility, what is a range for an optimal length of a Python function? (Assuming that this function will be used in combination with other functions to do something useful.)
I recognize that this is incredibly dependent on the task at hand, but as a Sophomore Comp. Sci. major, one of the most consistent instructions from professors is to write programs that are comprised of short functions so as to break them up into "simple", discrete tasks.
I've done a big of digging, including through the Python style guide, but I haven't come up with a good answer. If there are any experienced Python users that would like to weigh in on this subject, I would appreciate the insight. Thanks.
I'm sure a lot of people have strong opinions about this, but for new programmers a good rule of thumb is to try and keep it below 10-20 lines. A better rule of thumb is that a function should do one thing and do that one thing well. If it becomes really long, it is likely doing more than one thing and can be broken down into several functions.