Acties:
  • 0 Henk 'm!

  • pastafan
  • Registratie: Februari 2013
  • Laatst online: 13-05 13:19
Ik zoek een website of een programmatje (onder Windows),dat op basis van een ingevoerd woord, alle combinaties geeft van de letters. (het mag ook met getallen werken maar is niet wat ik nodig heb in dit geval):

voorbeeld:
ik geef op als input: woordje

website (of programma): geeft als output:
1. owordje
2. oowrdje
3. djeroow

etc, etc.

dus alle mogelijke combinaties van letters op basis van de opgegeven inputstring.

Wie helpt mij op weg?

Alvast bedankt.

Acties:
  • +2 Henk 'm!

  • g0tanks
  • Registratie: Oktober 2008
  • Laatst online: 14:41

g0tanks

Moderator CSA
Wat heb je zelf al gevonden?

"generate all possible combinations of letters" geeft genoeg relevante zoekresultaten op Google.

Ultrawide gaming setup: AMD Ryzen 7 2700X | NVIDIA GeForce RTX 2080 | Dell Alienware AW3418DW


Acties:
  • 0 Henk 'm!

  • pastafan
  • Registratie: Februari 2013
  • Laatst online: 13-05 13:19
@g0tanks sorry ik had moeten vermelden dat het om > 7 karakters gaat. De websites geven alleen tot 7 karakters aan.

Acties:
  • 0 Henk 'm!

  • RedFox
  • Registratie: November 2001
  • Laatst online: 10:50

RedFox

Heb je een OV ofzo?

Als je elk karakter als los item invoert kan dit op meerdere websites, bijv:
https://planetcalc.com/4242/
https://calculla.com/permutations_generator

You are not special. You are not a beautiful or unique snowflake. You're the same decaying organic matter as everything else.


Acties:
  • 0 Henk 'm!

  • F_J_K
  • Registratie: Juni 2001
  • Niet online

F_J_K

Moderator CSA/PB

Front verplichte underscores

pastafan schreef op zaterdag 3 april 2021 @ 14:15:
De websites geven alleen tot 7 karakters aan.
Ga niet voor een kant-en-klaar tooltje of website, maak het zelf. Iets als [google]generate all possible combinations of letters excel] geeft voorbeelden voor Excel maar het kan ook op andere manieren natuurlijk.

'Multiple exclamation marks,' he went on, shaking his head, 'are a sure sign of a diseased mind' (Terry Pratchett, Eric)


Acties:
  • 0 Henk 'm!

  • dragon4ce
  • Registratie: Oktober 2010
  • Niet online

dragon4ce

hardware freak

Hier een zelfgemaakt voorbeeldje in Python. Ik programmeer niet lang en niet regelmatig dus het zal vast veel efficienter kunnen dan dit, maar het werkt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from itertools import permutations

#temporarily input, you can call GetPermutations with a string and a boolean.
#set boolean to False to get all possible combinations, including doubles.
#set boolean to True to get all combinations without duplicates.
#E.G. if input == "aa" AND boolean = False, result will be [['a', 'a'],['a', 'a']
# if input == "aa" AND boolean = True, result wll be ['a', 'a']

inputstring = "test"
inputboolean = False

def GetPermutations(input, boolean):

    def convert(string):
        list1=[]
        list1[:0]=string
        return list1

    firststage = []
    firststage = convert(str(input))

    secondstage = permutations(firststage)
    thirdstage = []
    for i in list(secondstage):
        thirdstage.append(i)
    if boolean == True:
        fourthstage = []
        for i in thirdstage:
            if i not in fourthstage:
                fourthstage.append(i)
        return fourthstage
    else:
        return thirdstage


#example calls
print(len(GetPermutations(inputstring, inputboolean)))
print(GetPermutations(inputstring, inputboolean))


output van inputstring = "test" , inputboolean = False:

code:
1
[('t', 'e', 's', 't'), ('t', 'e', 't', 's'), ('t', 's', 'e', 't'), ('t', 's', 't', 'e'), ('t', 't', 'e', 's'), ('t', 't', 's', 'e'), ('e', 't', 's', 't'), ('e', 't', 't', 's'), ('e', 's', 't', 't'), ('e', 's', 't', 't'), ('e', 't', 't', 's'), ('e', 't', 's', 't'), ('s', 't', 'e', 't'), ('s', 't', 't', 'e'), ('s', 'e', 't', 't'), ('s', 'e', 't', 't'), ('s', 't', 't', 'e'), ('s', 't', 'e', 't'), ('t', 't', 'e', 's'), ('t', 't', 's', 'e'), ('t', 'e', 't', 's'), ('t', 'e', 's', 't'), ('t', 's', 't', 'e'), ('t', 's', 'e', 't')]


output van inputstring = "test" , inputboolean = True:

code:
1
[('t', 'e', 's', 't'), ('t', 'e', 't', 's'), ('t', 's', 'e', 't'), ('t', 's', 't', 'e'), ('t', 't', 'e', 's'), ('t', 't', 's', 'e'), ('e', 't', 's', 't'), ('e', 't', 't', 's'), ('e', 's', 't', 't'), ('s', 't', 'e', 't'), ('s', 't', 't', 'e'), ('s', 'e', 't', 't')]

[ Voor 26% gewijzigd door dragon4ce op 04-04-2021 11:30 ]

Omdat het kan.


Acties:
  • +1 Henk 'm!

  • Rukapul
  • Registratie: Februari 2000
  • Laatst online: 16:09
dragon4ce schreef op zondag 4 april 2021 @ 11:26:
Hier een zelfgemaakt voorbeeldje in Python. Ik programmeer niet lang en niet regelmatig dus het zal vast veel efficienter kunnen dan dit, maar het werkt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from itertools import permutations

#temporarily input, you can call GetPermutations with a string and a boolean.
#set boolean to False to get all possible combinations, including doubles.
#set boolean to True to get all combinations without duplicates.
#E.G. if input == "aa" AND boolean = False, result will be [['a', 'a'],['a', 'a']
# if input == "aa" AND boolean = True, result wll be ['a', 'a']

inputstring = "test"
inputboolean = False

def GetPermutations(input, boolean):

    def convert(string):
        list1=[]
        list1[:0]=string
        return list1

    firststage = []
    firststage = convert(str(input))

    secondstage = permutations(firststage)
    thirdstage = []
    for i in list(secondstage):
        thirdstage.append(i)
    if boolean == True:
        fourthstage = []
        for i in thirdstage:
            if i not in fourthstage:
                fourthstage.append(i)
        return fourthstage
    else:
        return thirdstage


#example calls
print(len(GetPermutations(inputstring, inputboolean)))
print(GetPermutations(inputstring, inputboolean))


output van inputstring = "test" , inputboolean = False:

code:
1
[('t', 'e', 's', 't'), ('t', 'e', 't', 's'), ('t', 's', 'e', 't'), ('t', 's', 't', 'e'), ('t', 't', 'e', 's'), ('t', 't', 's', 'e'), ('e', 't', 's', 't'), ('e', 't', 't', 's'), ('e', 's', 't', 't'), ('e', 's', 't', 't'), ('e', 't', 't', 's'), ('e', 't', 's', 't'), ('s', 't', 'e', 't'), ('s', 't', 't', 'e'), ('s', 'e', 't', 't'), ('s', 'e', 't', 't'), ('s', 't', 't', 'e'), ('s', 't', 'e', 't'), ('t', 't', 'e', 's'), ('t', 't', 's', 'e'), ('t', 'e', 't', 's'), ('t', 'e', 's', 't'), ('t', 's', 't', 'e'), ('t', 's', 'e', 't')]


output van inputstring = "test" , inputboolean = True:

code:
1
[('t', 'e', 's', 't'), ('t', 'e', 't', 's'), ('t', 's', 'e', 't'), ('t', 's', 't', 'e'), ('t', 't', 'e', 's'), ('t', 't', 's', 'e'), ('e', 't', 's', 't'), ('e', 't', 't', 's'), ('e', 's', 't', 't'), ('s', 't', 'e', 't'), ('s', 't', 't', 'e'), ('s', 'e', 't', 't')]
Probeer het nu eens in 3 regels :P
Import
Permutations
Set (om duplicates te filteren)
Plus optioneel een list comprehension om netjes een list van strings op te leveren

Alle string en list operaties lijken onnodig.

Acties:
  • 0 Henk 'm!

  • NMH
  • Registratie: Oktober 2015
  • Laatst online: 15:00

NMH

Moderator General Chat
Rukapul schreef op zondag 4 april 2021 @ 12:10:
[...]

Probeer het nu eens in 3 regels :P
Import
Permutations
Set (om duplicates te filteren)
Plus optioneel een list comprehension om netjes een list van strings op te leveren

Alle string en list operaties lijken onnodig.
3 regels? Ik bied 2: ;)
Python:
1
2
3
4
5
6
7
8
In [1]: from itertools import permutations

In [2]: print('\n'.join(''.join(tuple) for tuple in set(permutations('woord'))))
rwodo
woodr
[...]
wodor
roowd


@pastafan: hou er rekening mee dat het aantal mogelijke anagrammen explosief stijgt (en het aantal permutaties nog harder) naarmate de invoer langer wordt; dat zal ook de reden zijn dat de meeste websites een maximum lengte hanteren. Als alle letters uniek zijn, is het aantal anagrammen van een woord van n letters n!; het aantal anagrammen van "whiskyproducent" is bijvoorbeeld 1.307.674.368.000. Dat gaat je computer niet leuk vinden. :) (De formule voor woorden met dubbele letters kun je hier vinden.)

Acties:
  • 0 Henk 'm!

  • NMH
  • Registratie: Oktober 2015
  • Laatst online: 15:00

NMH

Moderator General Chat
Ok, ik kon het niet laten, in 1 regel door mijn eigen permutations() implementatie als een recursieve lambda functie te schrijven:
Python:
1
2
3
4
5
6
In [1]: print('\n'.join(set((lambda permutations, word: permutations(permutations, word))((lambda permutations, word: (sum([[word[idx] + tail for tail in permutations(permutations, word[:idx] + word[idx+1:])] for idx in range(len(word))], []) if len(word) > 1 else [word])), 'woord'))))
owodr
orodw
[...]
oorwd
odrow

Correctheid niet gegarandeerd, onleesbaarheid wel. Sorry @Rukapul. ;)
Pagina: 1