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 8 days ago.
Improve this question
I'm currently looking for how to get all possible solutions for an expression in Rust
// example expression
x * y = 8
// more complex expression
4x^2 + y^2 = 961
and now the results should be for the first expression:
[(1,8), (2,4), (4,2), (8,1)]
Is something like this possible without going through every number in a for loop?
// this would be a way (but i guess its a bad way)
for i in 1..8 {
if 8 % i == 0 {
// add this i option to the vector and get the division factor
let division_factor 8 / i
possible_solutions.push((i, division_factor));
}
}
And this is surely not the best practice, and I'm looking for a way with a good performance.
Related
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 6 months ago.
Improve this question
I have two forms of "percent" that I need in a grammar:
PERCENT_1
: 'PERCENT'
;
PERCENT_2
: '%'
;
One is the word PERCENT, for example used with something like LIMIT 10 PERCENT and the other is the modulo operator. What might be a good way to differentiate these two things?
One is a keyword, the other an operator. I usually name keyword tokens <name>_SYMBOL and operators <name>_OPERATOR (see the MySQL grammar). Of course this is totally up to you, but should be consistently used throughout your grammar(s).
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 2 years ago.
Improve this question
I often have code like
if condition {
// code that deserves to
// be formatted as block
}
else { None } // or some other trivial expression
Now, is there a way to prevent rustfmt from wasting two lines formatting the trivial else part like this:
else {
None
}
Note that single_line_if_else_maxwidth doesn't help, as the "then" part is too long.
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 4 months ago.
Improve this question
N people sit around a circular table. You have to find the probability that two particular people won't be sitting together.
The input will have the number N and the output should have the probability printed as a float type number rounded off to four decimal places.
Here's the link for the derived formula
You can find the step by step derivation over there
Here's the simple python implementation as per the thread
n = 5
result = (n-3)/(n-1)
print(result)
n= int(input())
import math
print(round(1-math.factorial(n-2)*math.factorial(2)/math.factorial(n-1),4))
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 3 years ago.
Improve this question
How to take operator as input and how to perform operations using tat operator
I have tried using functions
If we provide the input 2,5,+. the program should give output as 7.
I'm not going to give you all of the code, but here's a good starting point.
In Python, check out the operator module:
>>> import operator
>>> sum = operator.add(2, 5)
>>> sum
7
>>> diff = operator.sub(2, 5)
>>> diff
-3
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 5 years ago.
Improve this question
I am trying to code something in Haskell and can't find a breakthrough. What I'm trying to do, is from GHCi input one pair of numbers, do some equations with them and print out results. Let say the input is (a,b). Equations could be as simple as c = b **2 + a **3 - sin b and d = a - b
The output should be (c,d). Is it possible to do it and how.
Here is a sample ghci session:
> a = 3
> b = 4
> (b**2 + a**3 - sin b, a - b)
(43.75680249530793,-1)
If this does not meet your needs, you will need to be more specific about your needs (preferably in a fresh question that refers to this one and explains why the new question is different from this one).