How can Prolog be used to parse this arbitrary string?
S → DZ
D → dD
D → d
Z → zZ
Z → z
So far I have this code, but it has proven ineffective.
A represents the input and B represents the resulting string.
s(A,B):- d(A,C), z(C,B).
d([d,d|A],A).
z(z,z|A],A).
We can use prologue to parse this arbitrary string in d following way
The string is
S → DZ
D → dD
D → d
Z → zZ
Z → z
Here A represents the input and b represents d resulting string
s(A,B):- d(A,C), z(C,B).
d([d,d|A],A).
z(z,z|A],A)
Here we get a parse d string.
How can Prolog be used to parse this arbitrary string? S → DZ D → dD...
Task In this challenge you parse RGB colors represented by strings. The formats are primarily used in HTML and CSS. Your task is to implement a function which takes a color as a string and returns the parsed color as a map (see Examples). Input represents one of the following: color The input string 1.6-digit hexadecimal "#RRGGBB" - Each pair of digits represents a value of the channel in hexadecimal: 00 to FF 2.3-digit hexadecimal "#RGB" - Each digit represents...
Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character. Here is an example input: I am an input string a b The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and...
#7 which class is used to parse a line of input? A) BufferedReader B)FileReader C)InputStreamReader D)StringTokenizer #8 in the method below, which statement about the possible outputs in most correct? public static void what() { Integer x = new Integer (5); f(x); System.out.println(x); } A) 0 is a possible output B) 5 is the only possible output C) any positive integer can be ouput D) any integer can be output
1. Match each language to the typing model that best describes it. __ Ruby __ Prolog __ Scala __ lo A. static type checking with strong type safety B. dynamic type checking with strong (duck) type safety C. a prototype-based object model, uses dynamic typing. D. types are not specified, but when it compiles it will give errors if variables are not compatible 2. Match each language with it's corresponding strength __ Ruby __ Prolog __ Scala __ lo A....
How do you alter the following scanf statement in C? I have the following line of code: scanf("%[^.]s)", string); My problem is that this terminates the user input after the user enters a period, followed by Enter. for ex: Enter a string: Today is nice. How can I change this statement so that user would need to enter a new line, followed by a period and then press Enter so that the input would terminate? for ex. Enter a string:...
using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...
As mentioned in Assignment 5. Prolog can be used to solve problems that are quite difficult with other programming languages.This is mainly because of the declarative nature of the languages. What kind of difficulties do you think there will be if you are asked to write a program in another language fe.g. Python) to solve the puzzle in Assignment 5 L Introduction Prolog Is a language that Is sultable for solvins problems in the fleld of artifical Intelligence. That is,...
package week_3; /** Write a method called countUppercase that takes a String array argument. You can assume that every element in the array is a one-letter String, for example String[] test = { "a", "B", "c", "D", "e"}; This method will count the number of uppercase letters from the set A through Z in the array, and return that number. So for the example array above, your method will return 2. You will need to use some Java library methods....
def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...
4. Consider the block diagram shown below where D(s) is a step disturbance input. D(s) Controller Plant R(s) + E(s) C(s) G2(s) Ideally you want your controller design to reject a step disturbance input at D(s). This means that in the steady state for D(s)-1, the value of Y(s) is unchanged (a) Ignoring the input R(s), what is the transfer function器in terms of Gi(s) and G2(s)? (b) For G1(s)Ks 2) and G2(s)0419 what is the steady state error resulting from...