Skip to content
Open

test #291

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions day-14/part-1/quick_silvestre.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function update_mask(line, one_mask, zero_mask)
one_mask = 0
zero_mask = 0
for idx in 1:36
if line[7 + idx] == '1'
one_mask |= 1 << (36 - idx)
elseif line[7 + idx] == '0'
zero_mask |= 1 << (36 - idx)
end
end
return (zero_mask, one_mask)
end

function run(s)
# Your code here
one_mask::Int = 0
zero_mask::Int = 0
memory = Dict{Int,Int}()
addr::Int = 0
value::Int = 0
for line in readlines(IOBuffer(s))
if line[2] == 'a'
(zero_mask, one_mask) = update_mask(line, one_mask, zero_mask)
else
parts = split(line, " = ", limit=2)
addr = parse(Int, SubString(parts[1], 5, lastindex(parts[1]) - 1))
value = parse(Int, parts[2])
memory[addr] = (value | one_mask) & ~zero_mask
end
end
return sum(values(memory))
end

#########################################

function main()
run(ARGS[1])
res, time, memory = @timed run(ARGS[1])
println("_duration:$(time * 1000)")
println(res)
end

main()
2 changes: 1 addition & 1 deletion day-14/part-1/silvestre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function run(s)
addr::Int = 0
value::Int = 0
for line in readlines(IOBuffer(s))
if startswith(line, "mask")
if line[2] == 'a'
(zero_mask, one_mask) = update_mask(line, one_mask, zero_mask)
else
parts = split(line, " = ", limit=2)
Expand Down
49 changes: 49 additions & 0 deletions day-14/part-1/silvestre_module.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Test

export run

function update_mask(line, one_mask, zero_mask)
one_mask = 0
zero_mask = 0
for idx in 1:36
if line[7 + idx] == '1'
one_mask |= 1 << (36 - idx)
elseif line[7 + idx] == '0'
zero_mask |= 1 << (36 - idx)
end
end
return (zero_mask, one_mask)
end

function run(s)
# Your code here
one_mask::Int = 0
zero_mask::Int = 0
memory = Dict{Int,Int}()
addr::Int = 0
value::Int = 0
for line in readlines(IOBuffer(s))
if line[2] == 'a'
(zero_mask, one_mask) = update_mask(line, one_mask, zero_mask)
else
parts = split(line, " = ", limit=2)
addr = parse(Int, SubString(parts[1], 5, lastindex(parts[1]) - 1))
value = parse(Int, parts[2])
memory[addr] = (value | one_mask) & ~zero_mask
end
end
return sum(values(memory))
end

end

#########################################
using .Test: run

function main()
res, time, memory = @timed run(ARGS[1])
println("_duration:$(time * 1000)")
println(res)
end

main()
50 changes: 50 additions & 0 deletions day-14/part-1/silvestre_module_compiled.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
__precompile__()
module Test

export run

function update_mask(line, one_mask, zero_mask)
one_mask = 0
zero_mask = 0
for idx in 1:36
if line[7 + idx] == '1'
one_mask |= 1 << (36 - idx)
elseif line[7 + idx] == '0'
zero_mask |= 1 << (36 - idx)
end
end
return (zero_mask, one_mask)
end

function run(s)
# Your code here
one_mask::Int = 0
zero_mask::Int = 0
memory = Dict{Int,Int}()
addr::Int = 0
value::Int = 0
for line in readlines(IOBuffer(s))
if line[2] == 'a'
(zero_mask, one_mask) = update_mask(line, one_mask, zero_mask)
else
parts = split(line, " = ", limit=2)
addr = parse(Int, SubString(parts[1], 5, lastindex(parts[1]) - 1))
value = parse(Int, parts[2])
memory[addr] = (value | one_mask) & ~zero_mask
end
end
return sum(values(memory))
end

end

#########################################
using .Test: run

function main()
res, time, memory = @timed run(ARGS[1])
println("_duration:$(time * 1000)")
println(res)
end

main()