Created
April 1, 2018 14:03
-
-
Save miguelfermin/18372d89df94a0006fe8d5e8001a0c5f to your computer and use it in GitHub Desktop.
The unscramble-able algorithm written in go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
r := unscrambleable("hello", "llohe") | |
fmt.Println("is unscrambleable? ", r) | |
} | |
func unscrambleable(s1, s2 string) bool { | |
if len(s1) != len(s2) { | |
return false | |
} | |
indices := []int{} | |
for i := 0; i < len(s1); i++ { | |
indices = append(indices, 0) | |
} | |
for i := 0; i < len(s1); i++ { | |
for j := 0; j < len(s2); j++ { | |
if indices[i] == 0 && s1[i] == s2[j] { | |
indices[i] = 1 | |
} | |
} | |
if indices[i] == 0 { | |
return false | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment