With all of the regexps above, if the regexp matched anywhere in the string, it was considered a match. Sometimes, however, we'd like to specify where in the string the regexp should try to match. Here is how they are used: Since the second regexp is exactly the string, it matches.
I Phil Gold have altered them to be more amenable to programming in Scala. Feedback is appreciatedparticularly on anything marked TODO. The problems have different levels of difficulty.
If you have successfully solved the preceeding problems you should be able to solve them within a few say 15 minutes. You may need more time i. The difficulties were all assigned for the Prolog problems, but the Scala versions seem to be of roughly similar difficulty. Your goal should be to find the most elegant solution of the given problems.
Efficiency is important, but clarity is even more crucial. Some of the easy problems can be trivially solved using built-in functions. However, in these cases, you learn more if you try to find your own solution.
Solutions are available by clicking on the link at the beginning of the problem description. If you feel a particular problem can be solved in a better manner than I did, please let me know that, too.
The solutions to the problems in this section will be in objects named after the problems P01, P02, etc. You can compile the source files with scalac and thereafter use import to bring the functions into scope. Some of the problems can be solved easily by using imported solutions to previous problems.
The files linked here may include multiple solutions, with all but one commented out. By convention, the first element in the list is element 0.
If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.
If a list contains repeated elements they should be placed in separate sublists. Use the result of problem P09 to implement the so-called run-length encoding data compression method.
Consecutive duplicates of elements are encoded as tuples N, E where N is the number of duplicates of the element E. Modify the result of problem P10 in such a way that if an element has no duplicates it is simply copied into the result list. Only elements with duplicates are transferred as N, E terms.
Given a run-length code list generated as specified in problem P10construct its uncompressed version. Implement the so-called run-length encoding data compression method directly.
The length of the first part is given. Use a Tuple for your result. Given two indices, I and K, the slice is the list containing the elements from and including the Ith element up to but not including the Kth element of the original list.
Start counting the elements with 0. Return the list and the removed element in a Tuple. Elements are numbered from 0. Draw N different random numbers from the set Use the solution of problem P In how many ways can a committee of 3 be chosen from a group of 12 people?Another interesting array interview question, where you need to treat the array as Set.
Your task is to write a function in your favorite language e.g. Java, Python, C or C++ to return the intersection of two sorted arrays. Port Manteaux churns out silly new words when you feed it an idea or two. Enter a word (or two) above and you'll get back a bunch of portmanteaux created by jamming together words that are conceptually related to your inputs..
For example, enter "giraffe" and you'll get . If the string is made of no letters or just one letter, it is a palindrome. Otherwise, compare the first and last letters of the string.
If the first and last letters differ, then the string is not a palindrome; Otherwise, the first and last letters are the same.
Strip them from the string, . Given a string, write a recursive function that check if the given string is palindrome, else not palindrome.
Examples: Input: malayalam Output: Yes Reverse of malayalam is also malayalam. Input: max Output: No Reverse of max is not max. Array C/C++ Programs. C Program to find sum of elements in a given array.
C program to find largest element in an array. Recursive C program to linearly search an element in a given . However, the contribution is subjected to a salary ceiling of $6,In other words, if an employee earns $6，, only $6， attracts employee's and employer's contributions, the remaining $ does not..
Write a program called PensionContributionCalculator that reads the monthly salary and age (in int) of an arteensevilla.com program shall calculate the employee's, employer's and total.