The input is a Boolean formula in 2-CNF, given as a string of symbols.
Example: p /\ (p -> q) /\ (p -> ~r) /\ (~r \/ ~s) /\ (s \/ ~q)
1) check whether the given 2-CNF is satisfiable.
2) given a 2-CNF, report that it is not satisfiable or return one of its satisfying assignments.
Solution in Python3
For the first task, you should implement a function called is_satisfiable, which takes the string with the 2-CNF as an argument and returns either True (satisfiable) or False (not satisfiable). The second task should be implemented as a function called sat_assignment. This function also takes one argument (string) and returns an associative array (dictionary) with the satifying assignment (e.g., { 'p': True, 'q': False, 'r': True }) or None, if the 2-CNF is not satisfiable.
Warning: the automatic tests run several iterations of your functions, with different CNFs. If you use global variables, please make sure that their values from previous iterations do not make the next one work incorrectly.
10 have requested this problem solution
The more requests, the faster the answer.
Check is 2-CNF satisfiable? Return one of its satisfying assignments.
10 points (bonus) A propositional formula on n variables, P(ri,2,... ,Tn) is satisfiable if there exists an assignment of truth values (true or false) to its variables such that it evaluates to true. (a) Give an algorithm (pseudocode) that, given a formula P determines if it is satisfiable or not. Analyze your algorithm. b) Suppose that we are given a free" algorithm A that, given P and a partial assignment of truth values (that is, some variables are set to...
JavaScript 1) The function "hill" is implemented as follows: function hill(x) { return -2 * (x - 4) * (x - 16); } Write a function called quadratic that takes a constant factor and two roots and returns an anonymous function that computes that curve. In other words, quadratic(-2,4,16) should return an anonymous function that behaves the same as hill. 2) The function wrapString(inString, tag) is implemented as follows, so wrapString('foo','em') would return"<em>foo</em>"`: function wrapString(inString, tag){ return "<" + tag...
Make a function dict build(keys, values) which takes as argument two lists, one containing keys, one values to be put into a dictionary (in order). If the lists are of the same length put them into a dictionary form, and return the dictionary from the function. Otherwise return the keyword None from the function. For example: Test print(di ct_build(['a', 'b' , 'c'], [1,2,3])={ 'a': 1, 'b': 2, 'c': 3 r example: Result ildCC'a', 'b', 'c'], [1,2,3])-= { 'a': 1, 'b':...
Python Write a function square(a) that takes a list a of numbers and squares each of the numbers in the list. The function should not return a value (more specifically, it should return None). Write a function squared(a) that takes a list a of numbers and returns a new list that contains each value in a squared. The original list a should not be modified by your function. Write a function lowercase(a) that takes a list a of strings and...
Vliestion (1) while make testman I will generate an executable called Testman IX to test your program for Question (2). If you just issue make, then both will be generated. (1) In this question, you will re-implement the question in Assignment 1 by using vectors instead dynamic arrays. All the functionalities are the same. Of course, you need to make appropriate changes to the function declarations by using vectors instead of pointers to strings or string arrays). See below. Also...
Q1)(20p)Write a static member function called
removeLongestRepeatingSegment that takes a String argument. The
method will return a new String by removing the logest segment that
contains consequtively repeating characters.
public static void main(String []args){
String s=”1111222223333311111111444455552222”;
String res= removeLongestRepeatingSegment(s); will return
“11112222233333444455552222”
}
public static String removeLongestRepeatingSegment(String
s){
---------------
Q2)15p)Given a list of objects stored (in ascending order) in a
sorted linked list, implement member method which performs search
as efficiently as possible for an object based on a key....
Assignment 1 Year 2 ICTEDU term 1 2019 For question 1 and 2 the report should consist the following sections on each task: Task Description: Pseudo code / Algorithm: Testing: implementation (working program) screenshots NOTE: Question 1 and 2 Attach a well commented C source file of the program in a zipped file QUESTION 1-Simple C functions 1. Write a short C function that takes an integer (year) and checks whether the year is a Leap Year or not. If...
Python Programming Task 2: Leap Years Part A - Is this a leap year? Write a function is leap year(year) that calculates whether a given (CE) year is a leap year. The function must: • take one argument: a positive integer representing a year (assumed to be CE) • return True if that year was a leap year; return False if not NOTE: all years that are divisible by four are leap years, unless they are also divisible by 100,...
Write a recursive function called sumover that has one argument n, which is an unsigned integer. The function returns a double value, which is the sum of the reciprocals of the first n positive integers. (The reciprocal of x is the fraction 1/x.) For example, sumover(1) returns 1.0 (which is 1/1); sumover(2) returns 1.5 (which is 1/1 + 1/2); sumover(3) returns approximately 1.833 (which is 1/1 + 1/2 + 1/3). Define sumover(0) to be zero. Do not use any local...
In C++ 9) (5 pts) Complete the following function that takes 3 arguments of a circle : - radius (input argument) - area (output argument, to be calculated) - circumference (output argument, to be calculated) All arguments are double type. If a radius is negative, the function returns false, otherwise it returns true. The function does only calculation, and does nothing else. Assume that all #include are already there // Fill in your Function prototype bool circleAreaAndCircumference ( _______,...