Menu

PWC 370 Scramble On, Scramblin' Man
📰

PWC 370 Scramble On, Scramblin' Man

DEV Community·Bob Lied·7 months ago
#l6AjyMXk
#pwc#perl#perlweeklychallenge#str2#str1
Reading 0:00
15s threshold

If your girlfriend has been kidnapped by Gollum and the Evil One, and there's nothing you can do, perhaps console yourself with a small programming problem while you listen to Ramble On or Ramblin' Man' .

PWC 370 Task 2: Scramble String

The Task

You are given two strings A and B of the same length. Write a script to return true if string B is a scramble of string A otherwise return false. String B is a scramble of string A if A can be transformed into B by a single (recursive) scramble operation. A scramble operation is:

If the string consists of only one character, return the string.

Divide the string X into two non-empty parts.

Optionally, exchange the order of those parts.

Optionally, scramble each of those parts.

Concatenate the scrambled parts to return a single string.

Examples

Input: $str1 = "abc" , $str2 = "acb" Output: true

split: ["a", "bc"]

split: ["a", ["b", "c"]]

swap: ["a", ["c", "b"]]

concatenate: "acb"

Input: $str1 = "abcd" , $str2 = "cdba" Output: true

split: ["ab",…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.