while performing a hands on code practice i am facing cannot resolve symbol x from intellj
error code line
println(lst.reduceLeft((x,y) => {println(x + " , "+ y) x +y}))
println(lst.reduceRight((x,y) => {println(x + " , "+ y) x -y}))
i have tried to debugg from the suggestions from intellj but not working
Intellj
Build #IC-221.5591.52, built on May 10, 2022
scala version
scala-sdk-2.11.12
reference
http://www.codebind.com/scala/scala-reduce-fold-scan-leftright/?unapproved=192475&moderation-hash=8cdabb0f7834cbe19792b863eb952538#comment-192475
//In Scala Reduce, fold or scan are most commonly used with collections in the form of reduceLeft, reduceRight, foldLeft, foldRight, scanLeft or scanRight.
// In general, all functions apply a binary operator to each element of a collection.
// The result of each step is passed on to the next step.
package pack {
}
object obj2 {
println
println("=====started=======")
println
//val is a constant (which is an un changeable variable),A variable holds a value / address to a value in memory
val lst = List(1, 2, 3, 5, 7, 10, 13)
val lst2 = List("A", "B", "C")
def main(args: Array[String]) {
println(lst.reduceLeft(_ + _))
println(lst2.reduceLeft(_ + _))
println(lst.reduceLeft((x,y) => {println(x + " , "+ y) x +y}))
println(lst.reduceLeft(_ - _))
println(lst.reduceRight(_ - _))
println(lst.reduceRight((x,y) => {println(x + " , "+ y) x -y}))
println(lst.foldLeft(100)(_ + _))
println(lst2.foldLeft("z")(_ + _))
println(lst.scanLeft(100)(_ + _))
println(lst2.scanLeft("z")(_ + _))
}
}
println(lst.reduceLeft((x,y) => { println(x + " , " + y) x + y }))
The code inside the { } is not a valid expression. It looks like you are expecting Scala to work out that there are two expressions here, but it can't. You need to put in an explicit ; to fix it:
println(lst.reduceLeft((x,y) => { println(x + " , " + y); x + y }))
println(lst.reduceLeft((x,y) => {println(x + " , "+ y) x +y})) is not valid. If you want several instructions in a anonymous function you need either to separate them with ; or make it multiline:
println(lst.reduceLeft((x, y) => { println(x + " , " + y); x + y }))
or
println(lst.reduceLeft((x, y) => {
println(x + " , " + y)
x + y
}))
Also better use string interpolation instead of concatenation:
println(lst.reduceLeft((x, y) => {
println(s"$x , $y")
x + y
}))
Could someone please show me how to get the answer? The correct answer is c):
Simplify the following Boolean algebraic expressions (where ’ means not):
A.B’ + A.(B + C)’ + B.(B + C)’
a) B.C’
b) B + C
c) A.B’
d) A + B’
e) None of the above
First simplify the parentheses
A.B’ + A.(B + C)’ + B.(B + C)’=
A.B’ + A.B’.C’ + B.B’.C’
Now B.B’=0 so the third term is gone:
A.B’ + A.B’.C’
Now you can regroup A.B’:
A.B’.(1 + C’)
Finally 1+C’=1 so all that's left is
A.B’
Anyone can help me reduce this to 4 literals?
F = ( A + C + D) ( A + C + D') (A + C' + D) ( A + B')
i tested in logic friday the answer was F = C D B' + A.
Assuming the ⋅ operator represents binary conjunction, the + binary disjunction and the ' or the ¬ unary negation, I would apply the laws of Boolean algebra this way:
(a + c + d)⋅(a + c + ¬d)⋅(a + ¬c + d)⋅(a + ¬b)
((a + d) + (c⋅¬c))⋅(a + c + ¬d)⋅(a + ¬b) //distributivity
((a + d) + (0))⋅(a + c + ¬d)⋅(a + ¬b) //complementation: c⋅¬c = 0
(a + d)⋅(a + c + ¬d)⋅(a + ¬b) //identity for +: (a + d) + (0) = (a + d)
(a) + (d⋅(c + ¬d)⋅¬b) //distributivity
(a) + ((d⋅c + d⋅¬d))⋅¬b) //distributivity: d⋅(c + ¬d) = (d⋅c + d⋅¬d)
(a) + ((d⋅c + 0))⋅¬b) //complementation: d⋅¬d = 0
(a) + (d⋅c⋅¬b) //identity for +: (d⋅c + 0) = d⋅c
a + ¬b⋅c⋅d
The final line is the minimal DNF. You can also transform it to it's minimal CNF this way:
(a) + (¬b⋅c⋅d)
(a + ¬b)⋅(a + c)⋅(a + d) //distributivity
For this small number of variables, you could have used Karnaugh maps to quickly find the minimal forms or to control your result. In the following picture (generated using latex) is the original expression next to it's minimal DNF and minimal CNF.
After finding the mean term you can use
Quine McCluskey Technique to solve the experssion. The result will same as K-Map. But it is fast technique for many veriable boolean expression.
Quine McCluskey online solver
I have a function
A'B'C + AC'D + ABC + BC'D'
I have simplified to
C(A'B' + AB) + C'(AD + BD')
(C + AD + BD')(C' A'B' + AB)
Is this the right course? The last step is where I am getting stuck.
I'm trying to solve this:
So far I have:
a) a+b+c
b) a+bc
c) a+b
d) a+b
But for e) I can't progress further since I don't know how to deal with a'bc in this case. Can anyone help?
e) The expression is [a + (~a)bc + (~b)c]
a + [(~a)b + (~b)]c we can say that [(~a)b + (~b)] <--> [(~a) + (~b)] (Prove it by yourself:-)
a + [(~a) + (~b)]c
a + (~a)c + (~b)c we can say that [a + (~a)c] <--> [a + c]
a + c + (~b)c it is obvious that [c + (~b)c] <--> [c]
So [a + c] is the reduced expression.