Skip to content

Commit 43f5faa

Browse files
authored
fix factoring (#142)
1 parent a382004 commit 43f5faa

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/models/Factoring.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ end
5151
solution_size(f::Factoring, config) = first(solution_size_multiple(f, [config]))
5252
energy_mode(::Type{<:Factoring}) = SmallerSizeIsBetter()
5353

54-
pack_bits(bits) = sum(i->isone(bits[i]) ? 2^(i-1) : 0, 1:length(bits))
54+
pack_bits(bits) = sum(i->isone(bits[i]) ? BigInt(1) << (i-1) : BigInt(0), 1:length(bits); init=BigInt(0))
5555

5656
function read_solution(factoring::Factoring,solution::AbstractVector) #return a tuple of 2 numbers result
5757
num_m = pack_bits(solution[1:factoring.m])

test/models/Factoring.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ end
77
@testset "read_solution" begin
88
f = Factoring(3, 2, 8)
99
@test ProblemReductions.read_solution(f, [0, 0, 1, 0, 1]) == (4, 2)
10+
# large number
11+
f = Factoring(256, 256, BigInt(4611686018427387847) * BigInt(4611686018427387817))
12+
@test ProblemReductions.read_solution(f, ones(Bool, 512)) == ((BigInt(1) << 256) - 1, (BigInt(1) << 256) - 1)
1013
end
1114

1215
@testset "factoring" begin

0 commit comments

Comments
 (0)