Haskell number input and output [closed] - haskell

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).

Related

Substitution without creating a new variable in python [closed]

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 8 days ago.
Improve this question
a = 5
b = 3
How to substitution without creating a new variable in python and JS Or other programming language.
The value of (a) should be replaced by (b), and the value of (b) by (a).
Tried but couldn't without creating a new variable.
you can use :
a , b = b , a
hope it was usefull theres other methos but this is the easiest

Find All possible solutions for an expression [closed]

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.

Seating arrangement problem in a circular table [closed]

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))

How to read the arithmetic operators as input in python [closed]

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

Qualified operators [closed]

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 8 years ago.
Improve this question
In GHC (without language extensions) I have to do this:
x = 2 Prelude.+ 1
-- valid: x = (Prelude.+) 2 1
-- invalid: x = Prelude.+ 2 1
-- also invalid: x = 2 `Prelude.+` 1
How to change this behavior?
Quoting the Haskell Report, section 2.4:
The qualifier does not change the syntactic treatment of a name; for example, Prelude.+ is an infix operator with the same fixity as the definition of + in the Prelude
So, assuming the Prelude qualifier is just an example and you want to use the syntax shown in the comments, I don't think there is a way.

Resources