Age | Commit message (Collapse) | Author |
|
|
|
Not sure how scientific this comparison is, but I've got Max time used:
0.03/10.00, max memory used: 10264576/536870912.), and bytwigorlimerick
got Max time used: 0.04/10.00, max memory used: 10260480/536870912.).
https://courses.edx.org/courses/course-v1:UCSanDiegoX+ALGS200x+2T2017/discussion/forum/course/threads/5a4290cc44a15008b5000768
Looks like we are using different approaches.
Funny that my approach is a bit faster than
|
|
|
|
The only tricky part was to create and populate the 3-d list. The
instructions here was helpful:
https://www.ict.social/python/basics/multidimensional-lists-in-python
|
|
Not too bad, since I worked it out in Java already.
|
|
It turned out my Java test cases didn't cover enough number of cases. I
added one test case for it to fail, and figured out that the range in 2
loops should start with 1.
|
|
This isn't too bad after I worked out the algo in Java first.
|
|
|
|
I thought it wouldn't be this hard after I worked it out in Java first,
but once again it was fun and I learned a lot:
1. in all my previous exercises, my Python code performed better than my
Java code. This is the first time that my Java code significantly
outperforms my Python code: 0.92 seconds versus 7.93 seconds! My Java
code did use more than twice the memory.
2. Good re-enforcement of Python list copying concept, versus aliasing.
Don't forget the [:] (or [l:r]) magic!
3. list of (num, num) sort by first num by default, with proper tie
breaking. To sort on the second num, do list.sort(key=lambda x: x[1].
Cleve use of lambda, and it also does proper tie breaking.
4. I forgot to put this into my Java program comments, that Java code
gave me a good practice of comparator versus comparable interfaces,
which was very nice.
Fun stuff! Curious how much faster C++ program will be. I'll find out!
|
|
It wasn't hard since I worked this out in Java first. Once again, I felt
Python is really well designed and efficient.
|
|
It was easy, since I did the hard work of working it out in Java first.
|
|
Easy after the Java version is finished.
|
|
Easy, after Java version. Note that don't use ++i or i++, use i = i + 1
instead.
|
|
Seems that recursive approach is better.
|
|
|
|
|
|
Got the Java version work first. Then it's easy.
|
|
This is quite tricky. I read the forum and it helped
https://courses.edx.org/courses/course-v1:UCSanDiegoX+ALGS200x+2T2017/discussion/forum/course/threads/5a427c497acf2d0810000713
In particular try_my_best's algorithm worked. But I need to de-dup and
sort the list before feeding it to that algorithm, otherwise it won't
pass all the tests!
|
|
Checking in the code.
|
|
aka maximize online ad revenue.
|
|
|
|
|
|
It was pretty easy, just reimplemting the algorithm I've finished with
Java.
|
|
|
|
Doing the first few in a spreadsheet (and properly label columns and
rows) really helped.
|
|
|
|
I actually started implementing this in Java first, but ran into long
int overflow issues. Decided to get it working in Python first. I'm glad
it worked! Now back to implement it in Java!
|
|
2 things are really interesting:
1. How to find the right test cases. I think I'll probably need to go
back and re-read how to do an exhautisive testing
2. Python 3's floor division versus true division (// and /) operators
are interesting. This exercise discussion helped me:
https://courses.edx.org/courses/course-v1:UCSanDiegoX+ALGS200x+2T2017/discussion/forum/course/threads/5a3d32d644a15008df00062e
and this one:
https://stackoverflow.com/questions/19507808/python3-integer-division
and this one:
https://www.python.org/dev/peps/pep-0238/
|
|
|
|
Bonus: figured PyDev TDD code generation issue. I created "sources" as a source folder, but really should have created as a package, for TDD code generation to work properly. Fixed now!
|
|
|
|
|
|
|
|
|