Skip to content

Instantly share code, notes, and snippets.

@miguelfermin
Created April 1, 2018 14:03
Show Gist options
  • Save miguelfermin/18372d89df94a0006fe8d5e8001a0c5f to your computer and use it in GitHub Desktop.
Save miguelfermin/18372d89df94a0006fe8d5e8001a0c5f to your computer and use it in GitHub Desktop.
The unscramble-able algorithm written in go
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