From 93911dd559316b146a93b0fa47b8958b3f2f8a88 Mon Sep 17 00:00:00 2001 From: Jiahao Chen Date: Fri, 6 Nov 2015 14:16:00 -0500 Subject: [PATCH] combinatorics: keep only factorial and basic permutations All other methods are moved to Combinatorics.jl --- base/combinatorics.jl | 522 +++--------------------------------------- base/docs/helpdb.jl | 109 --------- test/combinatorics.jl | 55 ----- test/euler.jl | 3 - test/numbers.jl | 4 - test/sorting.jl | 1 - 6 files changed, 37 insertions(+), 657 deletions(-) diff --git a/base/combinatorics.jl b/base/combinatorics.jl index cd436a1e255ab..c1fd0c8f18030 100644 --- a/base/combinatorics.jl +++ b/base/combinatorics.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license +# Factorials + const _fact_table64 = Int64[1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800, 87178291200,1307674368000,20922789888000,355687428096000,6402373705728000, @@ -51,67 +53,12 @@ function gamma(n::Union{Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64}) @inbounds return Float64(_fact_table64[n-1]) end -# computes n!/k! -function factorial{T<:Integer}(n::T, k::T) - if k < 0 || n < 0 || k > n - throw(DomainError()) - end - f = one(T) - while n > k - f = Base.checked_mul(f,n) - n -= 1 - end - return f -end -factorial(n::Integer, k::Integer) = factorial(promote(n, k)...) - -## other ordering related functions ## -function nthperm!(a::AbstractVector, k::Integer) - k -= 1 # make k 1-indexed - k < 0 && throw(ArgumentError("permutation k must be ≥ 0, got $k")) - n = length(a) - n == 0 && return a - f = factorial(oftype(k, n-1)) - for i=1:n-1 - j = div(k, f) + 1 - k = k % f - f = div(f, n-i) - - j = j+i-1 - elt = a[j] - for d = j:-1:i+1 - a[d] = a[d-1] - end - a[i] = elt - end - a -end -nthperm(a::AbstractVector, k::Integer) = nthperm!(copy(a),k) - -function nthperm{T<:Integer}(p::AbstractVector{T}) - isperm(p) || throw(ArgumentError("argument is not a permutation")) - k, n = 1, length(p) - for i = 1:n-1 - f = factorial(n-i) - for j = i+1:n - k += ifelse(p[j] < p[i], f, 0) - end - end - return k -end -function invperm(a::AbstractVector) - b = zero(a) # similar vector of zeros - n = length(a) - for i = 1:n - j = a[i] - ((1 <= j <= n) && b[j] == 0) || - throw(ArgumentError("argument is not a permutation")) - b[j] = i - end - b -end +# Basic functions for working with permutations +""" +Returns `true` if `v` is a valid permutation. +""" function isperm(A) n = length(A) used = falses(n) @@ -142,6 +89,11 @@ function permute!!{T<:Integer}(a, p::AbstractVector{T}) a end +""" +Permute vector `v` in-place, according to permutation `p`. No checking is done to verify that `p` is a permutation. + +To return a new permutation, use `v[p]`. Note that this is generally faster than `permute!(v,p)` for large vectors. +""" permute!(a, p::AbstractVector) = permute!!(a, copy!(similar(p), p)) function ipermute!!{T<:Integer}(a, p::AbstractVector{T}) @@ -167,359 +119,30 @@ function ipermute!!{T<:Integer}(a, p::AbstractVector{T}) a end +"Like permute!, but the inverse of the given permutation is applied." ipermute!(a, p::AbstractVector) = ipermute!!(a, copy!(similar(p), p)) -immutable Combinations{T} - a::T - t::Int -end - -eltype{T}(::Type{Combinations{T}}) = Vector{eltype(T)} - -length(c::Combinations) = binomial(length(c.a),c.t) - -function combinations(a, t::Integer) - if t < 0 - # generate 0 combinations for negative argument - t = length(a)+1 - end - Combinations(a, t) -end - -start(c::Combinations) = [1:c.t;] -function next(c::Combinations, s) - comb = [c.a[si] for si in s] - if c.t == 0 - # special case to generate 1 result for t==0 - return (comb,[length(c.a)+2]) - end - s = copy(s) - for i = length(s):-1:1 - s[i] += 1 - if s[i] > (length(c.a) - (length(s)-i)) - continue - end - for j = i+1:endof(s) - s[j] = s[j-1]+1 - end - break - end - (comb,s) -end -done(c::Combinations, s) = !isempty(s) && s[1] > length(c.a)-c.t+1 - -immutable Permutations{T} - a::T -end - -eltype{T}(::Type{Permutations{T}}) = Vector{eltype(T)} - -length(p::Permutations) = factorial(length(p.a)) - -permutations(a) = Permutations(a) - -start(p::Permutations) = [1:length(p.a);] -function next(p::Permutations, s) - perm = [p.a[si] for si in s] - if isempty(p.a) - # special case to generate 1 result for len==0 - return (perm,[1]) - end - s = copy(s) - k = length(s)-1 - while k > 0 && s[k] > s[k+1]; k -= 1; end - if k == 0 - s[1] = length(s)+1 # done - else - l = length(s) - while s[k] >= s[l]; l -= 1; end - s[k],s[l] = s[l],s[k] - reverse!(s,k+1) - end - (perm,s) -end -done(p::Permutations, s) = !isempty(s) && s[1] > length(p.a) - - -# Integer Partitions - -immutable IntegerPartitions - n::Int -end - -length(p::IntegerPartitions) = npartitions(p.n) - -partitions(n::Integer) = IntegerPartitions(n) - -start(p::IntegerPartitions) = Int[] -done(p::IntegerPartitions, xs) = length(xs) == p.n -next(p::IntegerPartitions, xs) = (xs = nextpartition(p.n,xs); (xs,xs)) - -function nextpartition(n, as) - if isempty(as); return Int[n]; end - - xs = similar(as,0) - sizehint!(xs,length(as)+1) - - for i = 1:length(as)-1 - if as[i+1] == 1 - x = as[i]-1 - push!(xs, x) - n -= x - while n > x - push!(xs, x) - n -= x - end - push!(xs, n) - - return xs - end - push!(xs, as[i]) - n -= as[i] - end - push!(xs, as[end]-1) - push!(xs, 1) - - xs -end - -let _npartitions = Dict{Int,Int}() - global npartitions - function npartitions(n::Int) - if n < 0 - 0 - elseif n < 2 - 1 - elseif (np = get(_npartitions, n, 0)) > 0 - np - else - np = 0 - sgn = 1 - for k = 1:n - np += sgn * (npartitions(n-k*(3k-1)>>1) + npartitions(n-k*(3k+1)>>1)) - sgn = -sgn - end - _npartitions[n] = np - end - end -end - -# Algorithm H from TAoCP 7.2.1.4 -# Partition n into m parts -# in colex order (lexicographic by reflected sequence) - -immutable FixedPartitions - n::Int - m::Int -end - -length(f::FixedPartitions) = npartitions(f.n,f.m) - -partitions(n::Integer, m::Integer) = n >= 1 && m >= 1 ? FixedPartitions(n,m) : throw(DomainError()) - -start(f::FixedPartitions) = Int[] -function done(f::FixedPartitions, s::Vector{Int}) - f.m <= f.n || return true - isempty(s) && return false - return f.m == 1 || s[1]-1 <= s[end] -end -next(f::FixedPartitions, s::Vector{Int}) = (xs = nextfixedpartition(f.n,f.m,s); (xs,xs)) - -function nextfixedpartition(n, m, bs) - as = copy(bs) - if isempty(as) - # First iteration - as = [n-m+1; ones(Int, m-1)] - elseif as[2] < as[1]-1 - # Most common iteration - as[1] -= 1 - as[2] += 1 - else - # Iterate - local j - s = as[1]+as[2]-1 - for j = 3:m - if as[j] < as[1]-1; break; end - s += as[j] - end - x = as[j] += 1 - for k = j-1:-1:2 - as[k] = x - s -= x - end - as[1] = s - end - - return as -end - -let _nipartitions = Dict{Tuple{Int,Int},Int}() - global npartitions - function npartitions(n::Int,m::Int) - if n < m || m == 0 - 0 - elseif n == m - 1 - elseif (np = get(_nipartitions, (n,m), 0)) > 0 - np - else - _nipartitions[(n,m)] = npartitions(n-1,m-1) + npartitions(n-m,m) - end - end -end - -# Algorithm H from TAoCP 7.2.1.5 -# Set partitions - -immutable SetPartitions{T<:AbstractVector} - s::T -end - -length(p::SetPartitions) = nsetpartitions(length(p.s)) - -partitions(s::AbstractVector) = SetPartitions(s) - -start(p::SetPartitions) = (n = length(p.s); (zeros(Int32, n), ones(Int32, n-1), n, 1)) -done(p::SetPartitions, s) = s[1][1] > 0 -next(p::SetPartitions, s) = nextsetpartition(p.s, s...) - -function nextsetpartition(s::AbstractVector, a, b, n, m) - function makeparts(s, a, m) - temp = [ similar(s,0) for k = 0:m ] - for i = 1:n - push!(temp[a[i]+1], s[i]) - end - filter!(x->!isempty(x), temp) - end - - if isempty(s); return ([s], ([1], Int[], n, 1)); end - - part = makeparts(s,a,m) - - if a[end] != m - a[end] += 1 - else - local j - for j = n-1:-1:1 - if a[j] != b[j] - break - end - end - a[j] += 1 - m = b[j] + (a[j] == b[j]) - for k = j+1:n-1 - a[k] = 0 - b[k] = m - end - a[end] = 0 - end - - return (part, (a,b,n,m)) - -end - -let _nsetpartitions = Dict{Int,Int}() - global nsetpartitions - function nsetpartitions(n::Int) - if n < 0 - 0 - elseif n < 2 - 1 - elseif (wn = get(_nsetpartitions, n, 0)) > 0 - wn - else - wn = 0 - for k = 0:n-1 - wn += binomial(n-1,k)*nsetpartitions(n-1-k) - end - _nsetpartitions[n] = wn - end - end -end - -immutable FixedSetPartitions{T<:AbstractVector} - s::T - m::Int -end - -length(p::FixedSetPartitions) = nfixedsetpartitions(length(p.s),p.m) - -partitions(s::AbstractVector,m::Int) = length(s) >= 1 && m >= 1 ? FixedSetPartitions(s,m) : throw(DomainError()) - -function start(p::FixedSetPartitions) - n = length(p.s) - m = p.m - m <= n ? (vcat(ones(Int, n-m),1:m), vcat(1,n-m+2:n), n) : (Int[], Int[], n) -end -# state consists of: -# vector a of length n describing to which partition every element of s belongs -# vector b of length n describing the first index b[i] that belongs to partition i -# integer n - -done(p::FixedSetPartitions, s) = isempty(s[1]) || s[1][1] > 1 -next(p::FixedSetPartitions, s) = nextfixedsetpartition(p.s,p.m, s...) - -function nextfixedsetpartition(s::AbstractVector, m, a, b, n) - function makeparts(s, a) - part = [ similar(s,0) for k = 1:m ] - for i = 1:n - push!(part[a[i]], s[i]) - end - return part - end - - part = makeparts(s,a) - - if m == 1 - a[1] = 2 - return (part, (a, b, n)) - end - - if a[end] != m - a[end] += 1 - else - local j, k - for j = n-1:-1:1 - if a[j]1 - a[j]+=1 - for p=j+1:n - if b[a[p]]!=p - a[p]=1 - end - end - else - for k=m:-1:2 - if b[k-1]= x -# for integer n1, n2, n3 +For a list of integers i1, i2, i3, find the smallest + i1^n1 * i2^n2 * i3^n3 >= x +for integer n1, n2, n3 +""" function nextprod(a::Vector{Int}, x) if x > typemax(Int) throw(ArgumentError("unsafe for x > typemax(Int), got $x")) @@ -558,88 +181,17 @@ function nextprod(a::Vector{Int}, x) return Int(best) # could overflow, but best to have predictable return type end -# For a list of integers i1, i2, i3, find the largest -# i1^n1 * i2^n2 * i3^n3 <= x -# for integer n1, n2, n3 -function prevprod(a::Vector{Int}, x) - if x > typemax(Int) - throw(ArgumentError("unsafe for x > typemax(Int), got $x")) - end - k = length(a) - v = ones(Int, k) # current value of each counter - mx = [nextpow(ai,x) for ai in a] # allow each counter to exceed p (sentinel) - first = Int(prevpow(a[1], x)) # start at best case in first factor - v[1] = first - p::widen(Int) = first - best = p - icarry = 1 - while v[end] < mx[end] - while p <= x - best = p > best ? p : best - p *= a[1] - v[1] *= a[1] - end - if p > x - carrytest = true - while carrytest - p = div(p, v[icarry]) - v[icarry] = 1 - icarry += 1 - p *= a[icarry] - v[icarry] *= a[icarry] - carrytest = v[icarry] > mx[icarry] && icarry < k - end - if p <= x - icarry = 1 - end - end - end - best = x >= p > best ? p : best - return Int(best) -end - -const levicivita_lut = cat(3, [0 0 0; 0 0 1; 0 -1 0], - [0 0 -1; 0 0 0; 1 0 0], - [0 1 0; -1 0 0; 0 0 0]) - -# Levi-Civita symbol of a permutation. -# The parity is computed by using the fact that a permutation is odd if and -# only if the number of even-length cycles is odd. -# Returns 1 is the permutarion is even, -1 if it is odd and 0 otherwise. -function levicivita{T<:Integer}(p::AbstractVector{T}) - n = length(p) - if n == 3 - @inbounds valid = (0 < p[1] <= 3) * (0 < p[2] <= 3) * (0 < p[3] <= 3) - return valid ? levicivita_lut[p[1], p[2], p[3]] : 0 - end - - todo = trues(n) - first = 1 - cycles = flips = 0 +#Functions that have been moved out of base in Julia 0.5 +#Note: only the two-argument form of factorial has been moved +for deprecatedfunc in [:combinations, :factorial, :prevprod, :levicivita, + :nthperm!, :nthperm, :parity, :partitions, :permutations] - while cycles + flips < n - first = findnext(todo, first) - (todo[first] $= true) && return 0 - j = p[first] - (0 < j <= n) || return 0 - cycles += 1 - while j ≠ first - (todo[j] $= true) && return 0 - j = p[j] - (0 < j <= n) || return 0 - flips += 1 - end + @eval begin + $deprecatedfunc(args...) = error(string($deprecatedfunc, args, + " has been moved to the package Combinatorics.jl.\n", + "Run Pkg.add(\"Combinatorics\") to install Combinatorics on Julia v0.5-")) end - - return iseven(flips) ? 1 : -1 end -# Computes the parity of a permutation using the levicivita function, -# so you can ask iseven(parity(p)). If p is not a permutation throws an error. -function parity{T<:Integer}(p::AbstractVector{T}) - epsilon = levicivita(p) - epsilon == 0 && throw(ArgumentError("Not a permutation")) - epsilon == 1 ? 0 : 1 -end diff --git a/base/docs/helpdb.jl b/base/docs/helpdb.jl index 96eaba71ceb1e..63ba5b74878a6 100644 --- a/base/docs/helpdb.jl +++ b/base/docs/helpdb.jl @@ -1043,13 +1043,6 @@ Compute the minimum absolute values over the singleton dimensions of `r`, and wr """ minabs! -doc""" - prevprod([k_1,k_2,...], n) - -Previous integer not greater than `n` that can be written as $\prod k_i^{p_i}$ for integers $p_1$, $p_2$, etc. -""" -prevprod - doc""" @evalpoly(z, c...) @@ -1147,34 +1140,6 @@ Get the precision of a floating point number, as defined by the effective number """ precision -doc""" - partitions(n) - -Generate all integer arrays that sum to `n`. Because the number of partitions can be very large, this function returns an iterator object. Use `collect(partitions(n))` to get an array of all partitions. The number of partitions to generate can be efficiently computed using `length(partitions(n))`. -""" -partitions(n::Integer) - -doc""" - partitions(n, m) - -Generate all arrays of `m` integers that sum to `n`. Because the number of partitions can be very large, this function returns an iterator object. Use `collect(partitions(n,m))` to get an array of all partitions. The number of partitions to generate can be efficiently computed using `length(partitions(n,m))`. -""" -partitions(n::Integer, m::Integer) - -doc""" - partitions(array) - -Generate all set partitions of the elements of an array, represented as arrays of arrays. Because the number of partitions can be very large, this function returns an iterator object. Use `collect(partitions(array))` to get an array of all partitions. The number of partitions to generate can be efficiently computed using `length(partitions(array))`. -""" -partitions(array) - -doc""" - partitions(array, m) - -Generate all set partitions of the elements of an array into exactly m subsets, represented as arrays of arrays. Because the number of partitions can be very large, this function returns an iterator object. Use `collect(partitions(array,m))` to get an array of all partitions. The number of partitions into m subsets is equal to the Stirling number of the second kind and can be efficiently computed using `length(partitions(array,m))`. -""" -partitions(array, m::Integer) - doc""" readlines(stream) @@ -2022,13 +1987,6 @@ Compute hyperbolic sine of `x` """ sinh -doc""" - permutations(array) - -Generate all permutations of an indexable object. Because the number of permutations can be very large, this function returns an iterator object. Use `collect(permutations(array))` to get an array of all permutations. -""" -permutations - doc""" ```rst .. ceil([T,] x, [digits, [base]]) @@ -4765,15 +4723,6 @@ Suggest that collection `s` reserve capacity for at least `n` elements. This can """ sizehint! -doc""" - permute!(v, p) - -Permute vector `v` in-place, according to permutation `p`. No checking is done to verify that `p` is a permutation. - -To return a new permutation, use `v[p]`. Note that this is generally faster than `permute!(v,p)` for large vectors. -""" -permute! - doc""" ifelse(condition::Bool, x, y) @@ -5948,20 +5897,6 @@ Returns an array of lowered ASTs for the methods matching the given generic func """ code_lowered -doc""" - nthperm(v, k) - -Compute the kth lexicographic permutation of a vector. -""" -nthperm(v,k) - -doc""" - nthperm(p) - -Return the `k` that generated permutation `p`. Note that `nthperm(nthperm([1:n], k)) == k` for `1 <= k <= factorial(n)`. -""" -nthperm(p) - doc""" values(collection) @@ -7294,13 +7229,6 @@ The `dir` keyword argument can be used to specify a working directory for the co """ setenv -doc""" - invperm(v) - -Return the inverse permutation of v. -""" -invperm - doc""" lowercase(string) @@ -7765,13 +7693,6 @@ The inverse of `ind2sub`, returns the linear index corresponding to the provided """ sub2ind -doc""" - isperm(v) -> Bool - -Returns `true` if `v` is a valid permutation. -""" -isperm - doc""" super(T::DataType) @@ -8069,13 +7990,6 @@ Register a function `f(x)` to be called when there are no program-accessible ref """ finalizer -doc""" - nextprod([k_1,k_2,...], n) - -Next integer not less than `n` that can be written as $\prod k_i^{p_i}$ for integers $p_1$, $p_2$, etc. -""" -nextprod - doc""" <<(x, n) @@ -9817,13 +9731,6 @@ The smallest power of two not less than `n`. Returns 0 for `n==0`, and returns ` """ nextpow2 -doc""" - ipermute!(v, p) - -Like permute!, but the inverse of the given permutation is applied. -""" -ipermute! - doc""" ```rst .. full(F) @@ -10190,13 +10097,6 @@ An iterator that generates at most the first `n` elements of `iter`. """ take -doc""" - combinations(array, n) - -Generate all combinations of `n` elements from an indexable object. Because the number of combinations can be very large, this function returns an iterator object. Use `collect(combinations(array,n))` to get an array of all combinations. -""" -combinations - doc""" frexp(val) @@ -10439,15 +10339,6 @@ Tests whether a character is a lowercase letter, or whether this is true for all """ islower -doc""" -```rst -.. nthperm!(v, k) - -In-place version of :func:`nthperm`. -``` -""" -nthperm! - doc""" cell(dims) diff --git a/test/combinatorics.jl b/test/combinatorics.jl index 4989e9645663f..d54903402cf6a 100644 --- a/test/combinatorics.jl +++ b/test/combinatorics.jl @@ -29,42 +29,6 @@ let a = 2:-1:1 @test ipermute!(permute!([1, 2], a), a) == [1, 2] end -@test collect(combinations("abc",3)) == Any[['a','b','c']] -@test collect(combinations("abc",2)) == Any[['a','b'],['a','c'],['b','c']] -@test collect(combinations("abc",1)) == Any[['a'],['b'],['c']] -@test collect(combinations("abc",0)) == Any[Char[]] -@test collect(combinations("abc",-1)) == Any[] -@test collect(permutations("abc")) == Any[['a','b','c'],['a','c','b'],['b','a','c'], - ['b','c','a'],['c','a','b'],['c','b','a']] - -@test collect(filter(x->(iseven(x[1])),permutations([1,2,3]))) == Any[[2,1,3],[2,3,1]] -@test collect(filter(x->(iseven(x[3])),permutations([1,2,3]))) == Any[[1,3,2],[3,1,2]] -@test collect(filter(x->(iseven(x[1])),combinations([1,2,3],2))) == Any[[2,3]] - -@test collect(partitions(4)) == Any[[4], [3,1], [2,2], [2,1,1], [1,1,1,1]] -@test collect(partitions(8,3)) == Any[[6,1,1], [5,2,1], [4,3,1], [4,2,2], [3,3,2]] -@test collect(partitions(8, 1)) == Any[[8]] -@test collect(partitions(8, 9)) == [] -@test collect(partitions([1,2,3])) == Any[Any[[1,2,3]], Any[[1,2],[3]], Any[[1,3],[2]], Any[[1],[2,3]], Any[[1],[2],[3]]] -@test collect(partitions([1,2,3,4],3)) == Any[Any[[1,2],[3],[4]], Any[[1,3],[2],[4]], Any[[1],[2,3],[4]], - Any[[1,4],[2],[3]], Any[[1],[2,4],[3]], Any[[1],[2],[3,4]]] -@test collect(partitions([1,2,3,4],1)) == Any[Any[[1, 2, 3, 4]]] -@test collect(partitions([1,2,3,4],5)) == [] - -@test length(permutations(0)) == 1 -@test length(partitions(0)) == 1 -@test length(partitions(-1)) == 0 -@test length(collect(partitions(30))) == length(partitions(30)) -@test length(collect(partitions(90,4))) == length(partitions(90,4)) -@test length(collect(partitions('a':'h'))) == length(partitions('a':'h')) -@test length(collect(partitions('a':'h',5))) == length(partitions('a':'h',5)) - -for n = 0:7, k = 1:factorial(n) - p = nthperm!([1:n;], k) - @test isperm(p) - @test nthperm(p) == k -end - @test factorial(7) == 5040 @test factorial(Int8(7)) == 5040 @test factorial(UInt8(7)) == 5040 @@ -76,16 +40,8 @@ end @test factorial(UInt64(7)) == 5040 @test factorial(Int128(7)) == 5040 @test factorial(UInt128(7)) == 5040 -@test factorial(7,3) == 7*6*5*4 -@test_throws DomainError factorial(3,7) -@test_throws DomainError factorial(-3,-7) -@test_throws DomainError factorial(-7,-3) @test factorial(0) == 1 @test_throws DomainError factorial(-1) -#Issue 9943 -@test factorial(big(100), (80)) == 1303995018204712451095685346159820800000 -#Issue 9950 -@test_throws OverflowError factorial(1000,80) @test factorial(Int64(20)) == 2432902008176640000 # issue #6579 @test_throws OverflowError factorial(Int64(21)) @@ -94,14 +50,3 @@ if Int === Int32 @test factorial(Int32(12)) === Int32(479001600) @test_throws OverflowError factorial(Int32(13)) end - -@test_throws ArgumentError parity([0]) -@test_throws ArgumentError parity([1,2,3,3]) -@test levicivita([1,1,2,3]) == 0 -@test levicivita([1]) == 1 && parity([1]) == 0 -@test map(levicivita, collect(permutations([1,2,3]))) == [1, -1, -1, 1, 1, -1] -@test let p = [3, 4, 6, 10, 5, 2, 1, 7, 8, 9]; levicivita(p) == 1 && parity(p) == 0; end -@test let p = [4, 3, 6, 10, 5, 2, 1, 7, 8, 9]; levicivita(p) == -1 && parity(p) == 1; end - -@test Base.nsetpartitions(-1) == 0 -@test collect(permutations([])) == Vector[[]] diff --git a/test/euler.jl b/test/euler.jl index 06734d8d849d6..b3aef922012ab 100644 --- a/test/euler.jl +++ b/test/euler.jl @@ -254,10 +254,7 @@ end #21: 31626 #22: 871198282 #23: 4179871 - #24: 2783915460 -@test nthperm!([0:9;],1000000) == [2,7,8,3,9,1,5,4,6,0] - #25: 4782 #26: 983 #27: -59231 diff --git a/test/numbers.jl b/test/numbers.jl index aa78abd831b93..1cac324542b3e 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2267,10 +2267,6 @@ end @test nextprod([2,3,5],30) == 30 @test nextprod([2,3,5],33) == 36 -@test_throws ArgumentError prevprod([2,3,5],Int128(typemax(Int))+1) -@test prevprod([2,3,5],30) == 30 -@test prevprod([2,3,5],33) == 32 - @test nextfloat(0.0) == 5.0e-324 @test prevfloat(0.0) == -5.0e-324 @test nextfloat(-0.0) == 5.0e-324 diff --git a/test/sorting.jl b/test/sorting.jl index 03d6c4f201245..e8eca5a60d8e0 100644 --- a/test/sorting.jl +++ b/test/sorting.jl @@ -30,7 +30,6 @@ let a=[1:10;] end end @test sum(randperm(6)) == 21 -@test nthperm([0,1,2],3) == [1,0,2] numTypes = [ Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UInt128,