Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Anagram in Haskell 1. If the number of letters in the plaintext sentence is 2-co

ID: 3670019 • Letter: A

Question

Anagram in Haskell

1. If the number of letters in the plaintext sentence is 2-composite -- fine

2. If not, take it up to the next 2 composite length by adding X's to the end. (EX: "LEND ME FIVE BUCKS" has 18 characters. The next 2 composite is 21, so we add three X's: LEND ME FIVE BUCKSXXX

3. Arrange the letters in a block:

The message you send comes from reading down the columns: L UEFCNIKDVS EXM XEBX

Implement a function to encrypt messages in the anagram code:

anagramEncode :: [Char] -> [Char]

EX:

>anagramEncode "Chig-gar-roo-gar-rem/Chig-gar-roo-gar-rem/Rough Tough! Real Stuff!"

"Cihhg i-Tggo-augrga-hrr!-o roRo-eoga-algr a-Srrt-eurmfe/fmR!/oXCuXhgX"

and a function to decrypt the messages:

anagramDecode :: [Char] -> [Char]

L E N D M E F I V E B U C K S X X X

Explanation / Answer

import java.util.Scanner;

/* Two strings are called anagrams if they contain same set of characters but in different order.*/

public class AnagramProgram

{

static void isAnagram(String s1, String s2)

    {

       //Removing all white spaces from s1 and s2

         String copyOfs1 = s1.replaceAll("\s", "");

        String copyOfs2 = s2.replaceAll("\s", "");

        //Initially setting status as true

        boolean status = true;

        if(copyOfs1.length() != copyOfs2.length())

        {

            //Setting status as false if copyOfs1 and copyOfs2 doesn't have same length

            status = false;

        }

        else

        {

            //Changing the case of characters of both copyOfs1 and copyOfs2 and converting them to char array

              char[] s1Array = copyOfs1.toLowerCase().toCharArray();

             char[] s2Array = copyOfs2.toLowerCase().toCharArray();

           //Sorting both s1Array and s2Array

          Arrays.sort(s1Array);

         Arrays.sort(s2Array);

//Checking whether s1Array and s2Array are equal

    status = Arrays.equals(s1Array, s2Array);

        }

        //Output

       if(status)

        {

            System.out.println(s1+" and "+s2+" are anagrams");

        }

        else

        {

            System.out.println(s1+" and "+s2+" are not anagrams");

// next 2 composite length by adding X's to the end

           Int d= copyOfs1.length()-copyOfs2.length();

                      System.out.print(s1);

For(i=0;i<d;i++)

{

                      System.out.print("x");

}

        }

    }

    public static void main(String[] args)

    {

       System.out.println(" Enter string1 ");

     Scanner input = new Scanner(System.in);

    String s3 = input.nextLine();

     System.out.println(" Enter string2 ");

   Scanner input = new Scanner(System.in);

    String s4= input.nextLine();

        isAnagram(s3,s4);

    }

}

public class AnagramProgram

{

static void isAnagram(String s1, String s2)

    {

       //Removing all white spaces from s1 and s2

         String copyOfs1 = s1.replaceAll("\s", "");

        String copyOfs2 = s2.replaceAll("\s", "");

        //Initially setting status as true

        boolean status = true;

        if(copyOfs1.length() != copyOfs2.length())

        {

            //Setting status as false if copyOfs1 and copyOfs2 doesn't have same length

            status = false;

        }

        else

        {

            //Changing the case of characters of both copyOfs1 and copyOfs2 and converting them to char array

              char[] s1Array = copyOfs1.toLowerCase().toCharArray();

             char[] s2Array = copyOfs2.toLowerCase().toCharArray();

           //Sorting both s1Array and s2Array

          Arrays.sort(s1Array);

         Arrays.sort(s2Array);

//Checking whether s1Array and s2Array are equal

    status = Arrays.equals(s1Array, s2Array);

        }

        //Output

       if(status)

        {

            System.out.println(s1+" and "+s2+" are anagrams");

        }

        else

        {

            System.out.println(s1+" and "+s2+" are not anagrams");

// next 2 composite length by adding X's to the end

           Int d= copyOfs1.length()-copyOfs2.length();

                      System.out.print(s1);

For(i=0;i<d;i++)

{

                      System.out.print("x");

}

        }

    }

    public static void main(String[] args)

    {

       System.out.println(" Enter string1 ");

     Scanner input = new Scanner(System.in);

    String s3 = input.nextLine();

     System.out.println(" Enter string2 ");

   Scanner input = new Scanner(System.in);

    String s4= input.nextLine();

        isAnagram(s3,s4);

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote