Skip to content

Julia version of heap added#16

Open
artemsolod wants to merge 1 commit into
MikeMirzayanov:masterfrom
artemsolod:julia
Open

Julia version of heap added#16
artemsolod wants to merge 1 commit into
MikeMirzayanov:masterfrom
artemsolod:julia

Conversation

@artemsolod

@artemsolod artemsolod commented Feb 22, 2021

Copy link
Copy Markdown

I saw a thread on julia at https://codeforces.com/blog/entry/79 and wanted to help out. This code is a slightly modified copy&paste of python3 version. The biggest difference is julia's 1-based indexing. On my machine running time was within a factor of 2 slower than c++ version.

Also, I've posted a solution to the "Theatre square" problem mentioned in the thread. https://gist.github.com/artemsolod/3eb48e75b06216fd0af317546c793480

julia binaries are available here https://julialang.org/downloads/. The command to run code is julia heap.jl

One thing to note is that julia JIT-compiles code so it seems that every test-case would spend some time recompiling the solution.

Hope this helps!

@MikeMirzayanov

Copy link
Copy Markdown
Owner

Please, provide me a way to check Julia syntax without running the program. Give me full code (I tried some without success).

@artemsolod

Copy link
Copy Markdown
Author

There doesn't seem to be a specific flag to call julia with for performing this task. However, using a suggestion from https://discourse.julialang.org/t/syntax-validation-of-a-julia-file/55946 the following script should do the trick.

validatesyntax(fname) = include(expr -> Meta.isexpr(expr, (:error, :incomplete)) ? expr : nothing, fname) (length(ARGS) == 1) && validatesyntax(ARGS[1])

If this script is stored in validate_syntax.jl than the command to check syntax would be julia validate_syntax.jl file_to_check

@artemsolod

Copy link
Copy Markdown
Author

Hi, @MikeMirzayanov, is this method of checking syntax what you are looking for? Or is there anything else? Btw, that command can be used as a one-liner, i.e. julia -e "validatesyntax(fname) = include(expr -> Meta.isexpr(expr, (:error, :incomplete)) ? expr : nothing, fname);(length(ARGS) == 1) && validatesyntax(ARGS[1])" file_to_check.jl

@Pramodh-G

Copy link
Copy Markdown

Hi @MikeMirzayanov , I want to bump this issue to know what it will take to have julia language in the codeforces languages. Thanks!

@MikeMirzayanov

Copy link
Copy Markdown
Owner

It seems your "Theatre square" uses ~1GB of RAM (Windows 10, 64-bit, Julia 1.7.0). Do you know any workaround to reduce it?

@MikeMirzayanov

Copy link
Copy Markdown
Owner

Also, it uses \n by default as a line-break instead of \r\n (on Windows). Do you know how to force \r\n by default?

@artemsolod

Copy link
Copy Markdown
Author

Could you please share how you measure RAM usage? Regarding linebreaks, does the following version does what you want?

using Base: println
Base.println(io::IO, xs...) = print(io, xs..., "\r\n")

(a,b,c) = [parse(Int, c) for c in split(readline(stdin), ' ')]

println(ceil(Int, a/c) * ceil(Int, b /c))

@goyalyashpal

Copy link
Copy Markdown

ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants