Subleq: Difference between revisions
Content added Content deleted
(Tweak task description spacing and capitalization...) |
|||
Line 892: | Line 892: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{works with|Julia|0.6}} |
|||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
'''Module''': |
'''Module''': |
||
<lang julia>module Subleq |
<lang julia>module Subleq |
||
using OffsetArrays |
|||
⚫ | |||
using Compat |
|||
⚫ | |||
# Helper function because julia has 1-indexed arrays |
|||
using MacroTools |
|||
macro shiftgetindex(shift, blk) |
|||
return esc(MacroTools.postwalk(blk) do x |
|||
if isa(x, Expr) |
|||
if x.head == :ref |
|||
x.args[2] = :($(x.args[2]) + $shift) |
|||
elseif x.head == :call && x.args[1] == :getindex |
|||
x.args[3] = :($(x.args[3]) + $shift) |
|||
end |
|||
end |
|||
return x |
|||
end) |
|||
end |
|||
⚫ | |||
⚫ | |||
buf = IOBuffer() |
buf = IOBuffer() |
||
ip = 0 |
ip = 0 |
||
while true |
|||
a, b, c = words[ip:ip+2] |
a, b, c = words[ip:ip+2] |
||
ip += 3 |
ip += 3 |
||
Line 937: | Line 921: | ||
return String(take!(buf)) |
return String(take!(buf)) |
||
end |
end |
||
interpret(src::AbstractString) = interpret(parse.(Int, split(src))) |
interpret(src::AbstractString) = interpret(parse.(Int, split(src))) |
||
end # module Subleq |
end # module Subleq |
||
</lang> |
|||
'''Main''': |
'''Main''': |
||
<lang julia>using .Subleq |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<pre> |
|||
⚫ | |||
</pre> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |