Why my Racket program does not give me any output? - function

I have this code written for converting measurements. However when I run it with command (fce cm mm 5) I don't see any output and any error.
#lang racket
(define eq equal?)
(define (fce jednotka jednotka2 cislo)
(cond
((eq jednotka "mm") (mm cislo jednotka2))
((eq jednotka "cm") (cm cislo jednotka2))
((eq jednotka "m") (m cislo jednotka2))
((eq jednotka "km") (km cislo jednotka2))))
(define (mm c j)
(cond
((eq j "cm") (format "~a mm = ~a ~a" c (* c 0.1) j))
((eq j "m") (format "~a mm = ~a ~a" c (* c 0.001) j))
((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))
(define (cm c j)
(cond
((eq j "mm") (format "~a mm = ~a ~a" c (* c 0.1) j))
((eq j "m") (format "~a mm = ~a ~a" c (* c 0.001) j))
((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))
(define (m c j)
(cond
((eq j "cm") (format "~a mm = ~a ~a" c (* c 0.1) j))
((eq j "mm") (format "~a mm = ~a ~a" c (* c 0.001) j))
((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))
(define (km c j)
(cond
((eq j "cm") (format "~a mm = ~a ~a" c (* c 0.1) j))
((eq j "m") (format "~a mm = ~a ~a" c (* c 0.001) j))
((eq j "km") (format "~a mm = ~a ~a" c (* c 0.000001) j))))

You forgot to quote the strings, and you're comparing procedures. You should do this instead:
(fce "cm" "mm" 5)
The logic doesn't look right, though. The above prints:
"5 mm = 0.5 mm"
You need to work out the proper conversions and displayed messages in each of the helper procedures.

Related

is there something wrong in my code? i am not receiving the desired output

SELECT
CASE
WHEN (A = B) AND (B = C) THEN 'Equilateral'
WHEN (A = B) OR (B = C) OR (A = C) THEN 'Isosceles'
WHEN ((A+B) < C) OR ((A+C) < B) OR ((C+B) < A) THEN 'Not A Triangle'
ELSE 'Scalene'
END
FROM TRIANGLES;
i am checking the type of triangle if length of the sides are given as A, B, C in the table TRIANGLES.
I think you SQL should be like this.
You should check Not A Triangle condition first, and you should change < operator to <= as well. And I suggest you should select A, B, C as well to make it more readable.
SELECT A, B, C,
CASE
WHEN ((A+B) <= C) OR ((A+C) <= B) OR ((C+B) <= A) THEN 'Not A Triangle'
WHEN (A = B) AND (B = C) THEN 'Equilateral'
WHEN (A = B) OR (B = C) OR (A = C) THEN 'Isosceles'
ELSE 'Scalene'
END
FROM TRIANGLES;

Solving inequality leaves CRootOf in answer

when I try to solve this inequality x^3 + 3*x > 3 I get this output:
octave:5> eqn = x^3 + 3*x > 3
eqn = (sym)
3
x + 3⋅x > 3
octave:6> solve(eqn, x)
ans = (sym)
⎛ 3 ⎞
x < ∞ ∧ CRootOf⎝x + 3⋅x - 3, 0⎠ < x
But when I try to solve simpler inequality everything works fine:
eqn = abs(x^2-3)>3
eqn = (sym)
│ 2 │
│x - 3│ > 3
octave:4> solve(eqn, x)
ans = (sym) (-∞ < x ∧ x < -√6) ∨ (√6 < x ∧ x < ∞)
What can I do with this CRoot?

Haskell program simple game

I am very new in haskell-programming. I try to program a simple dice-game, but I don't know to do it in haskell.
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a₁,a₂,a₃) c (d₁,d₂,d₃)
I want to consider each difference dᵢ - aᵢ (but not if aᵢ > dᵢ) and return False if (d1-a1)+(d2-a2)+(d3-a3) are larger than c. (if aᵢ > dᵢ then I sum up 0 instead the difference)
I try something like this:
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) = ?????
where diff1 = if (d1 > a1) then d1-a1
diff2 = if (d2 > a2) then d2-a2
diff3 = if (d3 > a3) then d3-a3
Because in Haskell, else is not a optional part of an if expression, so you need to define diff1 as diff1 = if d1 > a1 then d1 - a1 else 0. Other two are similar.
Notes that > returns a Bool value, so you could just sum these three differences up and compare it with c, and use it as your condition.
There are several ways to define this function:
suc1 (a1, a2, a3) c (d1, d2, d3) = diff1 + diff2 + diff3 <= c
where diff1 = if d1 > a1 then d1 - a1 else 0
diff2 = if d2 > a2 then d2 - a2 else 0
diff3 = if d3 > a3 then d3 - a3 else 0
suc2 (a1, a2, a3) c (d1, d2, d3) = sum diffs <= c
where diff1 = max (d1-a1) 0
diff2 = max (d2-a2) 0
diff3 = max (d3-a3) 0
diffs = [diff1, diff2, diff3]
suc3 (a1, a2, a3) c (d1, d2, d3) = sum (zipWith diff as ds) <= c
where diff a d = max (d-a) 0
as = [a1, a2, a3]
ds = [d1, d2, d3]
How about this?
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) =
((if a1> d1 then 0 else d1-a1) + (if a2> d2 then 0 else d2-a2) + (if a3>d3 then 0 else d3-a3) > c )
Or alternatively
suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) =
max 0 (d1-a1) + max 0 (d2-a2) + max 0 (d3-a3) > c

Excel VBA UDF Formatting - Change argument values before calculation

I am trying to write a formula in Excel VBA to calculate: RR = ((A / (A + B)) / (C / (C + D)))
When any of the four arguments (A, B, C, D) are 0, I want to change their value to 0.5 in the calculation.
Is there an easy way of doing this? I believe my formatting is wrong or I'm going about it the wrong way. Any helpful tips would be greatly appreciated.
I've tried:
Function RR(A, B, C, D) As Double
If A = 0 And B = 0 Then
A = 0.5
B = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf A = 0 Then
A = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf B = 0 Then
B = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf C = 0 Then
C = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf D = 0 Then
D = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
ElseIf A = 0 And D = 0 Then
A = 0.5 And D = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
Else: RR = ((A / (A + B)) / (C / (C + D)))
End If
End Function
Try this one:
Function RR(A, B, C, D) As Double
If A = 0 Then A = 0.5
If B = 0 Then B = 0.5
If C = 0 Then C = 0.5
If D = 0 Then D = 0.5
RR = ((A / (A + B)) / (C / (C + D)))
End Function

Pari/GP Exceptions/break loops

ellpow(E, P, m) will always throw an exception:
*** ellpow: impossible inverse modulo: Mod(x, y).
*** Break loop: type 'break' to go back to GP
where x and y are integers.
I want to trap the value x, without finishing the program in order to use it
later.
The snippet of the code is:
trap(invmoder,
x,
ellpow(E, P, m)
), n);
The whole program is:
ellcurv(n) = {
local(B, a1, a2, a3, a4, a6, b, E, P, m, x);
B = 20;
a4 = Mod(random(n), n);
b = 4*a4^3 + 27;
b = 1/b;
a1 = a2 = a3 = Mod(0, n);
a6 = Mod(1, n);
E = ellinit([a1, a2, a3, a4, a6]);
P = [0,1];
ellisoncurve(E, P);
m = 1;
for(i = 1, B,
m = lcm(m, i));
print(m);
x = gcd(
trap(,
ellpow(E, P, m),
ellpow(E, P, m)
), n);
}