Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to create permutations of words without repetition in Go

1 Answer

0 votes
package main

import (
    "fmt"
    "strings"
)

func permutations_of_words(arr []string, left, right int) {
    if left == right {
        fmt.Println(strings.Join(arr, " "))
    } else {
        for i := left; i <= right; i++ {
            arr[left], arr[i] = arr[i], arr[left] // swap
            permutations_of_words(arr, left + 1, right)
            arr[left], arr[i] = arr[i], arr[left] // backtrack
        }
    }
}

func main() {
    arr := []string{"Go", "Programming", "Language"}
    
    permutations_of_words(arr, 0, len(arr) - 1)
}



/*
run:

Go Programming Language
Go Language Programming
Programming Go Language
Programming Language Go
Language Programming Go
Language Go Programming

*/

 



answered Jan 20, 2025 by avibootz

Related questions

1 answer 99 views
2 answers 97 views
1 answer 89 views
1 answer 88 views
1 answer 90 views
2 answers 1,840 views
...