Coder Social home page Coder Social logo

k-permutations about combinatoricslib3 HOT 2 CLOSED

dpaukov avatar dpaukov commented on May 27, 2024
k-permutations

from combinatoricslib3.

Comments (2)

dpaukov avatar dpaukov commented on May 27, 2024

Hello Stefano,

Thank you for the feedback.

As for k-permutations. There is no a special generator for this type of permutation in the library, but you can always generate them using the existing Combination and Permutation generators together. For example, 2-Permutations without repetitions of the lists (1, 2, 3) can be generated using the following code:

        Generator.combination(1, 2, 3)
            .simple(2)
            .stream()
            .forEach(combination -> Generator.permutation(combination)
                .simple()
                .forEach(System.out::println));

it will print the following six 2-permutations of (1, 2, 3):

   [1, 2]
   [2, 1]
   [1, 3]
   [3, 1]
   [2, 3]
   [3, 2]

Similarly, you can get 2-Permutations with repetitions of the lists (1, 2, 3):

        Generator.combination(1, 2, 3)
            .multi(2)
            .stream()
            .forEach(combination -> Generator.permutation(combination)
                .simple()
                .forEach(System.out::println));

it will print the following nine 2-permutations with repetitions of (1, 2, 3):

   [1, 1]
   [1, 2]
   [2, 1]
   [1, 3]
   [3, 1]
   [2, 2]
   [2, 3]
   [3, 2]
   [3, 3]

I have added these examples here.
Let me know if you still think this is not what you need and a special generator should be added to the library.

from combinatoricslib3.

sdemarch avatar sdemarch commented on May 27, 2024

Hey, thank you for your answer!

This is indeed what I was doing, but in two separate steps. I didn't think about the full power of Streams, and as long as this is possible I think it would be enough.

Thumbs up :)

from combinatoricslib3.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.