Posts

Showing posts from May, 2021

Daily Problem

 ACM ICPC Team Today I finally was able to solve the challenge at Hackerrank:  https://www.hackerrank.com/challenges/acm-icpc-team/problem?isFullScreen=true You have binary strings as input, then you need to OR them and see which ones have the most 1's.  This took some time for me for some reason. I tried to solve it with BitSet but I was not able to parse large strings to integers (got numeric exception) In the end I just wanted to see if the brute force would be able to do the operations under given time constraints and it worked so I went with that.

Daily Problem

I worked on two problems today. One on hacker rank about finding the valid moves for the Queen and the second is the 13th problem at projecteuler.  projecteuler is listed below. Python had support for large integers so not much to do there 

Daily Problem

 Today I solved the 12th problem at ProjectEuler. It was difficult and made me look up prime factorization.  I enjoy this yet I just decided to brute force it again. The code is below. Would be nice to optimize this. 

Daily Problem

 Today I solved the 11th problem at ProjectEuler https://projecteuler.net/problem=11 I thought it would go fast yet it did not and in the end I had to push it to finish it.  They gave you a grid and ask you to find the largest product of 4 adjacent numbers in it. These types of problems (grid iteration) is tedious to me because it is just index handling.  I choose to do it in python and use numpy library. I brute-forced my way through it. Essentially, do the horizonal, vertical and diagonal separately.  Reason it took long was this process, prepare the string (python does not like leading zeros so I had to remove them), then iterate the matrix and do slicing (had to learn it too).  I managed to solve it using this monstrosity of a code, but hey it works :D

The Case Against the Comments

 At work, I have added javadoc comments on top of a public API. I have done this to make sure I understood the problem properly. It also helped the code reviewer to see why I have wrote the things I did.  This however was not helpful to anybody. I have been reflecting on this for a while and wanted to list the things that backfired.  No one Read Them This was the first problem. I noticed that people were not really reading them and they did not had the effect I wanted them to have. It is also fair in my opinion. Why would you read them ? If you have stuff to do and if you have to do them fast, why would you read it through ? We had to Maintain Them  The javadoc comments had components which was linking some classes and if one was changing the method signature, they had to update the javadocs too. This is just creating more maintenance work for everyone else for something that is not mandatory. They started to Lie This is the main reason why comments had to go.  ...

Importance of Reading the Problem Carefully

 I was solving this programming challenge at Hackerrank:  https://www.hackerrank.com/challenges/append-and-delete/problem?h_r=profile It is called "Append and Delete". So, for say you have [a,b,c] and need to make [d,e,f] in 6 moves. You can delete the last element and add a new letter.  So you can simply remove all elements in [a,b,c] and add the three new elements. It is a simple one actually with just lots of edge cases. I implemented the solution, tested and it looked like it was going to work.    Yet it failed. I looked and tried to fix it yet I was failing on a case:  y, yu, 2 -> should print "no" but my program was saying yes. It does not make sense at first glance. It should be enough.  I thought I was going crazy at first. Maybe the answers were wrong ? So I looked again and again and re-read the problem again and again. Then the eureka moment; problem states that one needs to do the " exact " amount of moves and not the maximum number of m...