Question

in Scala programming, I need to solve the problem following,

sjok A little tricker. Make this function return true if every second entry in a list forms a palindrome. eg,List(99, 1,98, 2

in order to pass the test class following,

it should determine if every second entry in a list forms a palindrome in t Challenge1.secondPalindrome (List)) should be (

could you please implement that function?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def secondPalindromeLTlist: ListLT]): Boolean val newList list . zipWithIndex. filter(listTuple-> listTuple.-2 % 2-1).mapClis

Output:

println(secondPalindrome(ListO) println(secondPalindrome(List(1))) println(secondPalindrome(List(l, 2))) printlnsecondPalindr

Add a comment
Know the answer?
Add Answer to:
in Scala programming, I need to solve the problem following, in order to pass the test...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Scala programming, I've done isPalindrome function, but I get stuck with following problem. ...

    in Scala programming, I've done isPalindrome function, but I get stuck with following problem. let me know how to improve this, please in order to pass the test class following CHALLENGE 1: This challenge uses the inbuilt List type in Scala k/ object Challenge1 f /ok A palindrome is a list that is the same forwards as backwards. eg, List(1, 2, 2, 1) Make this function return true if a list is a palindrome. Note, you ARE permitted to use...

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • I need help with this problem this is what I put and these are the errors...

    I need help with this problem this is what I put and these are the errors I got Given the lists list1 and list2 that are of the same length, create a new list consisting of the last element of listi followed by the last element of list2, followed by the second to last element of listi, followed by the second to last element of list2, and so on (in other words the new list should consist of alternating elements...

  • Lesson Assignment There are 13 questions regarding slicing. The first 10 are required to pass. The...

    Lesson Assignment There are 13 questions regarding slicing. The first 10 are required to pass. The last 3 are extra credit. You will place all your answers in the lesson.py tab. Select that tab and take a look at how it's done. For your answers, each function (already defined) returns a tuple: the first item is the answer using index notation (e.g. text[16:20]) the second item is the answer using slice notation (e.g. slice(16,20,None)) the numbers you use for the...

  • The following is for java programming. the classes money date and array list are so I are are pre...

    The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...

  • Implement the following function in the PyDev module functions.py and test it from a PyDev module...

    Implement the following function in the PyDev module functions.py and test it from a PyDev module named t15.py: def matrix_equal (matrixi, matrix2): i.e. have the Compares two matrices to see if they are equal same contents in the same locations. Use: equal matrix_equal (matrix1, matrix2) Parameters: matrix1 the first matrix (2D list of ?) matrix2 the second matrix (2D list of ?) Returns: equal True if matrix and matrix2 are equal, False otherwise (boolean) NMN Sample testing First matrix: 0...

  • Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that...

    Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func)     (cond ((null? input-list) '())           ((func (car input-list))            (cons (car input-list) (filter (cdr input-list) func)))           (else            (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...

  • Complete LinkedListSet.java in java programming language. package Homework3; public class LinkedListSet extends LinkedListCollection { LinkedListSet() {...

    Complete LinkedListSet.java in java programming language. package Homework3; public class LinkedListSet extends LinkedListCollection { LinkedListSet() { } public boolean add(T element) { // Code here return true; } } Below is the LinkedListCollection.java code. Use to complete LinkedListSet.java. public class LinkedListCollection <T> { protected Node<T> head = null; public LinkedListCollection() { } public boolean isEmpty() { return head == null; } public int size() { int counter = 0; Node<T> cursor = head; while (cursor != null) { cursor =...

  • Hi, I have programming problem related to array, sorting, and. swap operation Thank you, Best Regards.....

    Hi, I have programming problem related to array, sorting, and. swap operation Thank you, Best Regards.. A non-empty array A consisting of N integers is given. You can perform a single swap operation in array A. This operation takes two indices I and J, such that 0 S13 J<N, and exchanges the values of A[i] and A[J]. The goal is to check whether array A can be sorted into non-decreasing order by performing at most one swap operation. For example,...

  • I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on)...

    I need the following merge-sort assignment completed using the "ArrayList<Comparable>" (the part I'm really stuck on) with comments: import java.util.ArrayList; public class Mergesort { /** * Sorts list given using the mergesort algorithm * @param list the list to be sorted * @param first the index of the first element of the list to be sorted * @param last the index of the last element of the list to be sorted */ public static void mergesort(ArrayList<Comparable> list, int first, int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT