#๐Ÿ”’ accelerate python program (I'm a beginner)

23 messages ยท Page 1 of 1 (latest)

dense vectorBOT
#

@leaden echo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

leaden echo
#

Hello everyone, I'm working on a project and I need help. I need to create a program that calculates the number of 1's you can put (there's a rule: you can't have more than two 1's in a row, column and diagonal) for an n x n grid.

I've managed (I think) to code this, but now I'd like to drastically improve the speed of calculation as it's very time-consuming (4x4 = 0.5s; 5x5 = 25s; 6x6 = 30min). But I don't know how to do it.

I started python not so long ago, so please don't talk Chinese to me lol

thank you!!

#

I heard about opencl, multiprocess, cython... but it seems very hard for me

slender musk
#

I probably won't be able to help you with code off the bat, but I suspect there would be a mathematical approach to this, vs a brute force.

leaden echo
#

the aim is to find the mathematical function (this is a problem that has not yet been solved by researchers), so the safest way is to use brute force.

slender musk
#

...ah.

dusky prairie
#

you mean having 2 for loops in your program?

leaden echo
#

at the end, the program displays the maximum number of 1's that can be entered according to the rule

dusky prairie
#

this aproach has a worst case time complexity of n^2

#

i'd sugest go and write it in any compiled language rather than python

#

go has an easy syntax and should make the code way faster

leaden echo
#

I tried in C but I don't know the language well enough, I have lots of problems when I try to convert my program, but I also think it's the easiest :/

dusky prairie
#

c/c++/rust would provide the best results but are hrad

leaden echo
#

yesss really

dusky prairie
#

give go a try maybe will be easier

#

or i've read about a superset for python

#

i belive it's called mojo

#

but never tried it out, not even sure if it's public yet

leaden echo
#

do you have a few notions of C or none at all?

dusky prairie
#

only a bit from uni, doubt i'll be able to help you

leaden echo
#

no problem, thanks anyway, that's nice!

dense vectorBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.