We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Fast Python! Coding competitions with CPython and PyPy

00:00

Formal Metadata

Title
Fast Python! Coding competitions with CPython and PyPy
Title of Series
Number of Parts
160
Author
License
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Fast Python! Coding competitions with CPython and PyPy [EuroPython 2017 - Talk - 2017-07-12 - Anfiteatro 2] [Rimini, Italy] In a coding competition you want to solve problems ""fast""... why would you choose a ""slow"" interpreted language like Python? Because the ""slow"" Python wins competitions more often that most people think. We will show how coding competitions work, what are the resources and constraints that competitors need to take into account, and we will find out that, like very often in real life, the actual processing time is only a small term in the complex equation that describe a competition. The ""faster"" PyPy may help in gaining raw speed, but that is not the real advantage it gives you in a competition
Coding theorySoftwareIntelOpen setFormal languageStatisticsRoundingBound stateComputer-generated imageryLattice (order)Computer programmingMultiplication signSoftware industryMachine codeFormal languagePoint (geometry)RankingProduct (business)General relativityProgramming languageRoundness (object)Single-precision floating-point formatJava appletLimit (category theory)Complete metric spaceCASE <Informatik>GoogolEuler anglesProgrammer (hardware)Formal verificationLecture/ConferenceComputer animation
Punched cardRankingRoundingMenu (computing)GradientMachine codeTwin primePairwise comparisonFormal languageMathematical analysisComputer programmingGoogolUniverse (mathematics)Video gameIntrusion detection systemRun time (program lifecycle phase)outputCompilerPersonal digital assistantSample (statistics)Rule of inferenceCondition numberRange (statistics)Phase transitionSpacetimeBefehlsprozessorCoding theoryProcess modelingUltraviolet photoelectron spectroscopyRoundness (object)Formal languageMachine codeProgrammer (hardware)CASE <Informatik>LengthResultantInitial value problemLogicoutputRankingRevision controlUniform resource locatorOnline chatMultiplication signWave packetSampling (statistics)Different (Kate Ryan album)MereologyUniverse (mathematics)Parameter (computer programming)Point (geometry)Civil engineeringSet (mathematics)Video gameRun time (program lifecycle phase)SummierbarkeitBitSoftware testingPower (physics)Function (mathematics)Insertion lossAlgorithmRule of inference2 (number)Total S.A.Limit (category theory)Statement (computer science)Sparse matrixPairwise comparisonView (database)Structural loadPlanningBefehlsprozessorKeyboard shortcutEndliche ModelltheorieConstraint (mathematics)Independence (probability theory)NeuroinformatikProgramming languageStaff (military)Inheritance (object-oriented programming)Computer programmingWeightRoutingDivisorVulnerability (computing)Data storage deviceJava appletComplete metric spaceTunisTheoryMachine codeTask (computing)Optimization problemGoogolComputer animation
Line (geometry)RoundingMachine codeChi-squared distributionEmailPoint (geometry)MathematicsoutputMaxima and minimaFunction (mathematics)Computer-generated imageryMetreLimit (category theory)MiniDiscStructural loadSample (statistics)CASE <Informatik>LoginUsabilityMenu (computing)Maß <Mathematik>10 (number)Local ringRevision controlState transition systemElectronic data interchangeError messageAbsolute valueNumeral (linguistics)Execution unitSource codeRankingSimultaneous localization and mappingWechselseitige InformationDependent and independent variablesHill differential equationGamma functionJava appletVacuumWaveTable (information)Hacker (term)Multiplication signRadiusMereologyDescriptive statisticsCASE <Informatik>Workstation <Musikinstrument>ResultantUniverse (mathematics)Software testingState of matterExergieMaxima and minimaOrder (biology)WritingLine (geometry)Right angleNumberSampling (statistics)TheoryoutputDecision theoryNeuroinformatikLevel (video gaming)Statement (computer science)Power (physics)Single-precision floating-point formatComplete metric spaceMusical ensembleFunction (mathematics)Bit rateLogical constantSlide ruleProcess (computing)Resolvent formalismWordPosition operatorLimit (category theory)Reading (process)Forcing (mathematics)Stress (mechanics)Device driverMachine codeVelocityBus (computing)String (computer science)DistanceElectronic mailing listInterior (topology)Real numberComputer animationLecture/Conference
Phase transitionMachine codeCoding theoryRun time (program lifecycle phase)Process modelingMathematical analysisSolvable groupSpacetimeBefehlsprozessorPairwise comparisonFormal languageJava appletLibrary (computing)Data storage deviceMachine codeMultiplication signImplementationMereologyFormal language2 (number)Constraint (mathematics)Programmer (hardware)Data structureLimit (category theory)Java appletLetterpress printingPower (physics)Phase transitionBitMachine codeInstallable File SystemEndliche ModelltheorieCASE <Informatik>Stack (abstract data type)Point (geometry)Different (Kate Ryan album)Thresholding (image processing)Statement (computer science)Just-in-Time-CompilerReal numberMathematical optimizationRun time (program lifecycle phase)Pairwise comparisonNumberKey (cryptography)CompilerWeightChannel capacityTunisNetwork topologySurvival analysisInformation technology consultingGreatest elementBus (computing)Fraction (mathematics)Game theoryComputer programmingStaff (military)AlgorithmBefehlsprozessorInternet forumGenderProcess (computing)XML
Process modelingFormal languagePairwise comparisonJava appletoutputAddress space8 (number)Data managementFocus (optics)Stress (mechanics)Endliche ModelltheorieRoundness (object)Staff (military)Multiplication signCASE <Informatik>System callForcing (mathematics)Spherical capStrategy gameLevel (video gaming)Functional (mathematics)Instance (computer science)Bit rateClosed setComputer programmingPoint (geometry)Different (Kate Ryan album)Selectivity (electronic)Machine codeAsynchronous Transfer ModeInterface (computing)PlanningLoop (music)State of matterGame controllerMathematical optimizationNetwork topologyWhiteboardPhase transitionLocal area networkFocus (optics)MereologyResultantInsertion lossGoogolImage resolutionXML
Stress (mechanics)Focus (optics)Data managementUltraviolet photoelectron spectroscopySolvable groupVolumeCompilation albumSimultaneous localization and mappingLibrary (computing)CompilerComputer programmingCoding theoryProcess modelingUniverse (mathematics)Open setSatelliteMachine code1 (number)Client (computing)Video gameLetterpress printingReal numberLibrary (computing)Point (geometry)Volume (thermodynamics)DebuggerProcess (computing)Limit (category theory)ResultantAlgorithmFormal languageMultiplication signRepresentation (politics)Latent heatPower (physics)Statement (computer science)TunisBitNeuroinformatikCountingData type2 (number)outputStandard deviationData managementComputer architectureStress (mechanics)Scaling (geometry)Focus (optics)Software bugStack (abstract data type)CASE <Informatik>Set (mathematics)Tracing (software)Product (business)Expert systemBlock (periodic table)Office suiteSemiconductor memoryNetwork topologyLogic gateFactory (trading post)State of matterComputer programmingMeasurementCellular automatonSheaf (mathematics)Execution unitWeb pageWordMetropolitan area networkAutocovarianceMereologyLine (geometry)XML
Transcript: English(auto-generated)
Hi there. Thank you for joining. So, my name is Alessandro Remiciu. I work for Biobahn, a software company in Rome. We use mostly Python and since I do
my hobby most of the time involved programming and coding, I often happen to do coding competitions. It's a very fun sport. I'm just an amateur. I'm not very high in the rankings. I do it
as a weekend hobby. But I think I learn quite a lot about how the general theory of coding competitions I found it was fun, but it also helped me being a better programmer overall, even if it's not
what you would expect. It's not that you know so many new tricks that you use. It's really a more general attitude toward programming and this is what I want to talk about in this talk. The first point is, why would you
do coding competitions with Python? Usually you would say that if you want to compete with others, you need to have the language that is as fast as possible, which is true. In fact, most of the competitors use one of those three languages
which is for typical coding competitions this is the Google Code Jam. It's the largest single coding competition that is online. It's the main topic, it's the example that we use throughout the talk, because it's
the cleaner and easier to track. The three most used programming languages are C++, Python, and Java, especially in the beginning, in the initial rounds. Verification rounds are open to everybody then you need to qualify for the rounds and then the audience
becomes smaller and smaller until in the final round only a handful of people, actually 25 or 26 of the very best competitors in the app, and you see even if half of the people, I mean, compared to the C++ crowd, the Python crowd, it's more or less
half of the very beginning, it becomes one tenth at the end. But still, there are people who do use Python in the finals and the reason is that there are some of, there have been cases where the only solution that could be submitted to one of the problems was Python.
In 2011, round three, it's one of the final rounds, only the top 25 competitors qualify and user Linguo who is a proficient Python programmer, he codes in nine or ten languages in the competitions for fun
but then when things get tough, he uses Python, and he was the only one, he was ranked first because he solved the large input data sets of problem D with Python, no one else managed to do it not even the very best C++ programmers. In
2013, round two, something if you want even more interesting happened because be married, one of the professionals, one of the guys who can win the competitions, and he is a C++ guy he uses C++ almost for everything, but the
last problem of the round two, he managed to solve, he was the only one who solved it, and he solved it in Python, so he switched in just half the time, or even less than half the time that the other C++ competitor had, he managed to implement the Python version
and to get it. Now, notice that he finished two minutes, 29 and 54 seconds it's two hours and a half is the whole competition and he squeezed the last winning submission just six seconds before the end. This is also one of
the things that you learn, never give up. Finally, in the 2017, this happened last month user Kevin Sogo, who is one of the very, very younger and very best in the scene, he is a Python guy, he uses mostly Python except C++
when he thinks that he really needs the speed boost, and he managed to finish, it's one of the only four people who submitted a correct solution for the final problem, and three of them use Python, including Kevin Sogo
So, the point is, it is not it is, it might be, in certain cases, a good idea to use Python, let's try to understand why, also during the time more and more people are using Python, but in the initial rounds where, I mean, you, there are a lot of people who are not as good as in the
final rounds, but also in the final rounds It's actually, in the past two years, Python actually overcame Java as a language in the very final round So, the plan for the talk is to give an intro to what is exactly to compete, for example, for the Google Code Jam, then
we will try to solve the problem live They say, never do live coding, let's see And then, we try to understand from the theoretical point of view, what is that really matters in a coding competition, then, once we have this, we can
try to do a programming language comparison to understand why what are the advantages and the weaknesses of every language, and then we see what we can do, how, what we have learned that is, what if I want to do this competition for fun, and what can I actually get something for my
day-to-day coding, or even for live So, Google Code Jam, that's the main entry point It's a competition, it's run once per year, it has several online rounds and just one on-site round on a Google
location, it has quite sizable price a total of 20k of dollars and then, usually you need to solve, depending on the round, from 3 to 5 problems, there are problems with a known correct solution, so there are
other kinds of competitions where the complete solution optimal solution is not known, but you can judge a solution if it's better than another Here, it's on-off, either it's correct or it's incorrect. You can program in any programming languages, because you do it on your computer, you download sample input
you run code on your computer, and you upload the output if the output is correct, an online judge will decide if the output is correct The competition is time-boxed in a few hours 2.5 hours is the typical length, but some are longer, some rounds are longer some rounds are shorter. The run time of your code
it's a few minutes. 4 minutes for the small input for the small dataset, and 8 minutes for the long dataset So every problem usually has a simple more small, simpler dataset, and then a more complex
more broad, large dataset and you get different, you get independent scores if you get the first or the first and the second. Finally you get ranking based on the problem score, that is how many
problems you solved and how difficult they were you have given the score in advance and your submission time, so you need to be fast in submitting the solution so you get points if you are correct, and you
get an advantage if you do it fast So usually a problem is done like this, you have a problem statement that describes the universe actors, rules, parametric rules usually, and a question what you want, what is your task then you have limits, this is very important
the parameter and the initial condition of your universe are described as we will not give you more than taught actors or so on, 10,000 or 10 or something, and there are different limits, usually for small and large inputs, this is the main difference, so typically
the problem is simpler to solve, you need less insight to solve the small input and more steps, more insight to solve the large input Then you have sample test cases with the solution so you can check if you're if the solution you developed is actually
working on a sample dataset, and then you have the real test cases, the one that you download, and if you solve them, you get points So typically, the problem solving is, you have two things to keep in mind
first you have constraints, you have your CPU, RAM and storage, this is what you usually think as important thing in solving a problem with a computer and then you have the code running time, your code can run more than 4 minutes or 8 minutes depending on the input but then you have wall clock time, that is really the big part
because you need to solve as many problems as possible in the two and a half hours that I gave you, and if you solve it faster, then you are you are higher in the ranking. Coding phases, we will talk quite a bit about those, usually the steps
of this, you read the problem, you try to understand how to map the universe in some algorithm that solved the question that you are given, then you need to implement the algorithm actually typing it in, and then depending on the problem, you may need performance tuning or debugging
Debugging is anything that you do after you are pretty sure you coded well and it doesn't work, and performance tuning instead is when you realize that the solution to the model that you have is too slow, and then you have run time, run time is how much time you need to download the stuff, run
and upload it again. Now, to give you an idea of how this looks like, we will try to do a live training session that is, we read the problem and we
try to code it, download it, run, upload and see if it works, hopefully we will do it in time. Now, the reason that the problem that I am proposing I actually did live in one of the easier rounds, and I made it in 7 minutes and
11 seconds, first time that I saw it, now I saw it already so hopefully it will not be long, and still was not enough to qualify so I, the first thousand competitors qualified and I was 1046 so, tough luck. So, now
the hard part that is switching this and going here, okay, so can you read the statement? So usually the problem statements are the
universe is describing some kind of funny or interesting way so you don't lose the fun of it so it's about Annie is a bus driver with high stress jobs, she tried to do something and in the end he wants to do some horseback riding for fun, so today Annie
this is, now it's describing our universe, we need to capture how to make this into a code Annie is riding her horse to the east along a narrow one way road and runs west to east she is currently at kilometer zero of the road and the destination is
kilometer D, kilometers along the road are numbered from west to east there are other horses traveling east to the same road, all of them go traveling forever and all of them are currently between Annie, horse and her destination and the ith horse as initial kilometer KI and traveling at the maximum speed SI
then he says that horses cannot overcome each other and the question is you can go at any, it doesn't have any maximum speed, you can go at whatever speed you want but as long as it doesn't pass any other horse, so the problem is that
we have horses running on a segment of a line and we cannot pass them and we want to choose to ensure smooth driving for her and the horse, Annie wants to choose a single constant cruise control speed of her horse for the entire trip, from the current position to the destination
so that her horse will not pass any other horses, what is the maximum such speed that he can choose? This is very typical, this is very simple universe, then you have description of the input this is typical input you have number of test cases, then a line with
D and N, how many other horses, how long you need to go and then N lines with where every horse started and what is his speed, output needs to be a string where we say what is the cruise speed velocity limits, for the small data set
the interesting part is that we have only one or two other horses in the case of the large data set, we have up to 1000 horses now, you have an input and for this input you know what is the output typically some of those, the problems are quite standard
in a way that they give you the this is my solution, my scaffold solution I read the number of test cases then I arrange on test cases, I build some kind of result and I print the result, if I do run this right now I just get zero because I don't do any computing
now, this is quite simple, at least quite simple for me I know that since horses cannot overcome every horse has a precise maximum time when he arrives, he reaches the final destination and somehow I want to
look just for the slowest horse, that is the horse that will reach the destination in the maximum time and then I want to go there at the same time as him that's easy, I mean
even if you're not practicing coding you can get it done in slightly longer than seven minutes, but it's very fast to do it once you have the hunger so basically what I'm saying is that first I need to read all my
my D and N so I get for every test case
I get an input, I split it in D and N which is the order in which the first line is given then I have a number of
of horses so I do it for N, I need to read N more lines so I go input, again these are two numbers, so I split it and I map it
with int, everything is an int and then I need to do a list here, because map returns a generator here, I don't need it, but here I do let's see if this works, usually you do something very rough I want just to see okay, I can read it more or less
so now I have the result now for every horse I can't tell at what time the horse will be in the D, at the end of my destination so I have K and S
in I, and my result is the maximum result itself, D minus K so this is the distance that the
that is remaining for the horse divided its speed, now Python 3 is very nice, so this is already float and everything, let's see if this works and this says that this is the time it takes since I really don't want to have the
time, but I need to give the speed I think I need to divide this by to do the rest, let's see if it works and yes, so this was fast, now how do I know
if this is correct, I need to download the practice solution, I already am in the correct thing, so I replace it, now this is I'm really testing if it's not on the sample
test case, but on the real stuff, during the completion this is how I get the score I need to get the small input, yes very fast, so I save it to the small out, and now I can submit my solution, which is small out
and see case one case zero, ok, this is a very difficult mistake, ok, now this is debugging, sometimes you have a problem
and you need to understand what is the problem and solve it let's see if this was the real problem, submit correct, great, now in this case, I already know that I can handle thousand horses as well as
few, so I just go and download the large case the large problem, I save it to large in replace, then I do the same with
large in, and I save the output in a large out and I need to select it submit, correct, great
so, this is how typically things works for very simple problem what is interesting is that first there was no need to, yes
thank you, first I didn't hit any of the constraints the problem was so simple that really CPU, RAM, storage running time was not a problem, in the large data sets it was couple of seconds
so the only thing that really counts in this case was wall clock time, because you get it's not a score, it's not part of the score, but it is something that makes you higher in the ranking so, if you look at more or less the various
coding phases went, modeling was just slower now because I need to read the statement aloud, but usually it's fast, and then coding it's usually fast if you don't have any hit, performance tuning it's not needed, in this case was not needed, and debugging was just
tried, I mean just test the thing, work, you have a small problem, but you fix it immediately, and then run time was zero as well so, the seven minutes, you can't submit a problem in five minutes, this is what the really good people do usually for at least one or two of the problems
and everybody has a threshold where the problem is easy enough, that this is your target time, if you want to compete then there are generalized absorbable problems there is something that you are able to solve, it's not easy straightforward or this one, but it's something that you are able to solve how do you recognize this kind of problems? Usually, most of the time
especially when you begin, there's still no real need to keep the constraint, because usually the main problem is to do the modeling, you can take from two minutes to twenty minutes to do the modeling, that is going from the text
to an actual algorithm, to data structure, etc. and then coding is usually again not the real problem usually, performance tuning you don't need, it's very rare, only if you do some mistake at the beginning and this is the real place where PyPy beats CPython
because you need even less performance tuning the problem is debugging, the real key and the real reason Python has an advantage is that if something goes wrong, if you did a mistake in implementation or even a mistake in the modeling, if
things don't work, you need to understand where, how and when and this is, the debugging part is where Python has a huge advantage, oh, first, the language that you know the most is the one that has the advantage but Python, if you know more than one language very well, Python has the advantage
to have stack traces, very powerful print statement so debugging is where Python shines really and it's the largest and more risky of the coding phases, because maybe you don't need any debugging at all even in C++, but if you do, it might
grow, it's easy to get one hour stack on a problem that you know you can solve, but just you made silly mistakes somewhere. So how do you recognize a simple unsolvable problem?
This depends on you, really, because there are usually, if you keep an eye on the scoreboard, you see that the pros can submit the correct solution to a problem very fast, or I mean, it doesn't take long, so you know that this is a simple problem in the
general way, but it's not solvable for you if you don't know how to do the modeling. This is where there is really the big stuff, the big difference between experienced programmer or experienced competitor and new people.
The other part is debugging, because if you have a compiler, you might have a model that you, at the end you might I mean, you find what is the algorithm, data structure that describe it, but if the things are at the limit of your capacity, the time
most of the time will be spent in debugging again. These are the real two key assets. So the key assets is your time, and the too big
the way you spend your time is mostly modeling and debugging. The rest is usually a fraction or in the typical case is a fraction. Then you have generalized unsolvable problems, which is something that is completely out of scope for you and you can easily recognize
because the pros are having hard time to solve it so this doesn't care. You may not care. Language comparison. So why people still use C++, but a lot of people are using Python. C Python and Python
are slightly different since we are interested in Python I have them separated. Now the point is, in the modeling part both Python and C Python is the best, because you have access to a huge number of libraries. Sometimes the solution is just to know you already know a library
and you just need to code how to describe the problem to a library and the library solves it. With PyPy you have slightly less an advantage because some of the libraries are not working, and with C++ and Java usually it's harder to install stuff, so unless you have the perfect setup
you may not, and also interfacing with libraries is harder, so many more competitors just go with a straight-typed solution, not going for a library. Coding. The coding time in Python is excellent because it's very terse, you can be very clean
and the same, it's C++, Java it's a little bit longer but coding is not really that important. I mean, unless there are thousands of ifs because you have a very strange problem, the coding is not what makes a difference. Performance tuning instead
can in some cases be important and this is the reason why the pros use C++. Performance tuning in C++ usually you don't need to do because C++ is fast and it's the compiler that does most of the optimizations. Java and PyPy have a JIT
just-in-time compiler, so it's fine to use them. See, Python sometimes are very seaweed optimization that you need to track and if you don't it can be very slow, usually they are very ingrained in our brains so it's very easy to do
performance optimization like not repeating a LAN or a function called inside loop, but still you need to keep them in mind, so it's not so good. The point is that with debugging, CPy and PyPy is where they have the big advantage
and as we saw, that is the big, big risk. So, now we move into what we learned about in coding competition. The first point is that strategic thinking
the wall clock time is the paramount asset. This is something that was not clear to me at the beginning and then you need to optimize that, manage your time and be sure to know in which phase you are and if you are doing the right thing at the right phase.
At a higher level of strategy you have problem selection usually you should go for the simple problem first this means that you go and track and put the you put aside the points that you have that you can, the lower
hanging through it and then also among the simple problem, usually you should consider the simple solution to the simple problem. Brute force works in a lot of cases in the first rounds of the code jam and once you did the brute force solution, you have a working
solution, then probably to do the large, that would be not enough but at least you can test if your fancier solution gives the same results as the brute force. Then you always need to keep focused and keep an eye on the score board. That is, first you need to check what
other competitors are doing, especially the pros, so that you know if something is actually solvable or not, so you don't lose time in something that is too much out of scope for you. You really need to try to work on problems that can make a difference for you. In one instance I knew
I had problem doing a simpler problem a simpler problem, so I set it aside and tried to do a more complex problem. When I solved the small for the harder problem, I saw that I didn't have a chance, if I went back to the
simpler problem, solve it, that would not have been enough to qualify. So I tried to see, I gave myself 20 minutes to think of how to solve the large of the hard problem that no one was doing, so it was really an hazard, but there was no way
to win otherwise. And after a while I noticed that the problem was really mostly a trick, that the same solution of the small problem would have worked for the large even if it didn't look like. So at the very last I just tried, I was not losing anything because I would have not
qualified anyway, and it worked. So just trying, I have an insight but it was really, this is the only thing that I can do right now to have a chance of winning. So strategy it's a big player in this
in competitions. The other things that you learn is to focus and stress management. Every time you need to have both the round strategy and the problem strategy, that is you are doing the single problem, but you need to qualify for the whole round
and this is something you need to move, go up and down in the strategy level to be sure that you are employing your time as wisely as possible. Then something that is very important is keeping focus in a way so that
you don't make mistakes while coding. Every mistake may cost you debugging time, that is the worst that you can do is to do a mistake both at modelling and at coding. Usually coding mistakes are easier to track. If you do a mistake at modelling, then it's much harder to go back. But one of the points is everything
in modelling your problem and coding should be kept as simple as possible. This is quite strange, you think that you may do fancy stuff, but no most of the time doing the most plain solution is more easily debugable and so
it's the one that wins you, that qualifies you. Then one thing, this is a mistake that I do very often you need to be ready to question all your assumptions. Sometimes you decide that the solution to a certain problem has a greedy solution, so you go with that and
you never question that assumption, which was just an assumption and that is something that you need to learn somehow again and again, always go back and be sure that what you are doing is the... you didn't leave anything back. Then there is stress management
this part somehow I didn't think was so important the fact that, I mean, you need to keep calm in the face of a ticking wall clock, and this is not easy I've been competing since five years and still when
the competition starts I can feel my heart rate going up and feeling sweaty and so keeping this in control, keeping control over this, it's really one of the things that you learn, if you want
during this hobby, and something that is very useful in all kind of situations again, there is the fact that you also need to keep calm in the face of the risk of public shaming or public humiliation, because what you submit
then it will be made public, the solutions in the Google Code Jam are public, so sometimes you know you are doing something really horrible, it should be optimised, but time is what counts, and in the end this is what counts for you and if then other people try to learn and download your code
and see your code and say that, oh god, this is really horrible it's fine, still you need to keep calm in the face of this. Then there is something quite amazing that is the never give up, this happens with all the sports, but with coding competitions, the fact that this stuff is
get very much closer to the way we program, and sometimes if you like in the case that I have, if you have just one way to get out of a situation, you may try it, may not work, but you know that you did the best
and if it works, you actually get out of in my case, I qualified, and you can get out of your problem. Also, you can imagine, be merry coding like crazy, I mean the final code that he submitted six seconds
before the end was something like three pages full of if and everything, and you need to say, ok, I go on doing this, even if I am very tight in time, I almost certainly will not have time to run it and submit it, but if you do it six seconds
before the gong, it means that you really believe that. So how do I start, or how do I get better at competition? You get this advice online, the most important thing is practice, the second most important thing is practice again
and so is the third. There is nothing like that is more important practice. But now for real, so something useful. First, practice, you need to practice real world competition from start to end with a timer. The whole clock, the fact that you feel pressure and keep the stress and focus needs to be real even in
competition. Then, you need to go for volume first. Do a lot of simple problems, even if they are obviously simple, you need to get your muscles, coding muscles going. Then, you go to problems that are more to your limits. You need to understand and try to figure out what are the problems
that are limited and try to go for them. Then, learn from code of other competitors and then learn libraries. There are a lot of libraries these are the ones that I find most amazing in coding competitions, but a lot of libraries just make a lot of things much simpler. Then, you need to learn data
extraction algorithms. This is a course that I followed which is amazing and I invite everybody to use it. So, what do I learn from everyday programming? Basically, the point is modeling, coding, performance tuning and debugging is the same. The point is that performance tuning
and debugging have a much lower time scale. So, this is where you need to optimize your whole clock management time. Also, strategic thinking. Always try to get to the low hanging fruits before doing the big architecture and always keep an eye on the scoreboard. That is what is exactly
that is useful now and what is the most useful thing that I can do now. Finally, focus and stress management is the thing that I really like the most. That is, if you have a bug in production or you are doing a hackathon
you have time boxed, you want to solve something as soon as possible and all the keep calm in the face of the clock and keep calm in the face of people looking at you like in client facing, problem solving situations. This is something that once you know once you do coding competitions looks much simpler
to do. Job interviews as well. I mean, you have someone looking and watching every case truck or if you are trapped in a fire, you need to say, okay keep calm, I need to solve the problem, not to panic. Then again, strategic thinking works exactly
the same also in your life and keep an eye on the scoreboard it is as well one of the most important things. So, I thank you for your attention and I am ready to get questions if you want. Thank you.
This could be a bit specific. Can you hear me good?
I hear very badly. Can you speak? Close up to the microphone. Is it better? Yeah, better. So, this could be a bit specific I am like the Python in me, I mostly use like the CC++ I was curious why Python is better for debugging like what are the advantages over the...
Okay, the first and most important point is stack traces. This is where Python shines. Stack traces are usually very, very useful and you get them for free immediately. The other point is that the print statement which is really the only debugging tool that you use in coding competition
it's much, much powerful so you get a very nice representation of a lot of data types, especially if you use standard data types which is what you do most of the time and in case you are forced to go into the debugger which you really want to avoid
you just do import IPDB IPDB set trace and the introspection of Python helps you really a lot. I did not much C++ in my life so I am probably not an expert in debugging but when I needed to port
my Python libraries to C++ for performance reason even if I already knew what I wanted to do. It was a pain that every small details needed much more time to be debugged. Okay, thank you for your talk and I wanted to ask
because you said that we have the time limit for execution also it was like four minutes for the small data set and how is this measured because you are downloading the input and uploading the output, so how to do it? You have a timer when you download the data set, you have a timer
and you can only upload the result within four minutes. If you go out after you are not able to upload the data, the solution. Okay, so basically if you have more power of your computer then you have kind of a lot of advantage.
Yes, and quite surprisingly this doesn't count most of the time. In my whole career I mean I did a lot of practice and a few code jams, five probably, and I think only once I really had something like a solution that ran in five minutes instead of four. And it was
something like a trivial mistake that I made. So yes, it may happen that a faster computer or a faster language is different but it's quite rare. Alright, I think we've probably got time for one more
question if anybody... Alright, okay please join me in giving Alessandro a hand. Thank you very much. And please remember you can...