Giter Club home page Giter Club logo

Comments (3)

timo avatar timo commented on August 26, 2024

👍 on the sorting. also, there really ought to be more tests. tests for 0 or negative numbers, tests for other stuff in lists, tests for other kinds of list (ranges for example. Buf/Blob perhaps?)

from roast.

grondilu avatar grondilu commented on August 26, 2024

I'm not sure how permutations is supposed to behave for zero or negative numbers. I don't think such values should be allowed.

Also permuting lists only uses slices made from permutations(Int $), so it really is the only thing that really needs testing.

We should test for larger value than 3 though, especially now that it is getting faster.

sub slow-permutations($n) {
    $n == 1 ?? ((0,),) !!
    gather for ^$n -> $i {
        my @omitted = grep none($i), ^$n;
        take ($i, |@omitted[@$_]) for slow-permutations($n - 1);
    }
}

use Test;

my $n = 4;
is permutations($n).sort(:by({ .join })).perl, slow-permutations($n).sort(:by({.join})).perl;

from roast.

b2gills avatar b2gills commented on August 26, 2024

There should be 1 permutation of 0 things, as there is exactly one way to order it.

This should hold true for all $n >= 0

+permutations($n) == factorial($n)

factorial 0 is defined as returning 1

I think the only thing that makes sense is for it to return a sequence containing a single empty list. ((),).Seq

from roast.

Related Issues (20)

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.