Monday, April 28, 2025

My ranking during algorithm contest

My Coding Contests

My TopCoder Contests

Slime harvester

This one have cool GUI, cool multi-agent problem. It creates a distributed environment where the **thread affinity** is a thing. Here is my code in github.

My HackerRank Contests

Contest Solved Rank
Week of Code 37 5/6 181

My LeetCode Contests

2025

Contest Solved Rank
Weekly Contest 432 3/4 413
Biweekly Contest 152 3/4 536

2024

Contest Solved Rank
Weekly Contest 385 3/4 925
Weekly Contest 390 4/4 866
Weekly Contest 402 4/4 753
Biweekly Contest 146 3/4 823
Weekly Contest 429 4/4 567

2023

Contest Solved Rank
Weekly Contest 343 3/4 546
Biweekly Contest 105 4/4 752
Weekly Contest 347 4/4 630
Weekly Contest 368 4/4 316
Weekly Contest 369 3/4 992

2022

Contest Solved Rank
Weekly Contest 296 4/4 826
Biweekly Contest 81 4/4 738
Weekly Contest 322 4/4 287
Weekly Contest 326 4/4 886
Weekly Contest 329 4/4 868
Weekly Contest 333 3/4 583

2021

Contest Solved Rank
Weekly Contest 229 4/4 529
Biweekly Contest 49 3/4 829
Weekly Contest 235 3/4 741
Weekly Contest 237 4/4 902
Biweekly Contest 59 3/4 343
Weekly Contest 255 3/4 434
Weekly Contest 256 3/4 793
Weekly Contest 259 3/4 729
Weekly Contest 267 4/4 556
Weekly Contest 269 4/4 211
Weekly Contest 273 4/4 730
Weekly Contest 283 4/4 1090

2020

Contest Solved Rank
Weekly Contest 221 3/4 900
Weekly Contest 227 3/4 877

Monday, March 10, 2025

Min Treap on top of a Segment tree

As we know treap is the combination of Tree and Heap. It is a tree like structure that has a rigid order when traversed. We can find the lowest value or the lower value than K near a given position.

Treap

Tree Structure
  • As heap it contains the smallest item near the root.
  • As tree, when traversed in-order, it gives the items in sequential order we inserted them. That means that we can insert an item at certain position.
Benefits
We can find the lowest value or the lower value than `K` **near** a given position.
Drawbacks
Treap is not a balanced tree. So the cost of lookup is not always logN.

Treap on top of a Segment Tree

Segment tree structure
  • It has all the values in the leaves.
  • All internal nodes that are not leaves contains the minimum value in the subtree.
Benefits
The query is logN.
Drawbacks
My implementation is fixed size.

My treap

The full implementation is here in this project. You are welcome to try this for example in this problem,

Sunday, March 27, 2016

Summary of Algorithms

This page is moved to [github](https://github.com/kamanashisroy/algosnippet/blob/master/algorithms_summary.md). There I am doing bug-fixes and adding with new things that I learn.

Sunday, February 14, 2016

JavaScript will evolve faster as a language than a compile target

Author:Kamanashis Roy
Note: I wrote this blog on request

JavaScript survived and thrived to be one of the most popular language for web development. There was concern over the best-practice and performance issue in JavaScript. Some people went further to say JavaScript language is Buggy. But it served it’s purpose as client-side scripting.

The main criticisms against JavaScript were,
- JavaScript has fragmented implementation( because of the lack of standardization and the browser-war.)
- Standardization that resulted JavaScript to be compiler target rather than a language itself.
- JavaScript is slow.

The criticism against the JavaScript gave rise to compilers that target it. These source-to-source compilers generate acceptable JavaScript code. One of them being Google Web Toolkit. It generates JavaScript from Java. The idea is to impose the best practices. Again after standardization and wide-spread acceptance of JavaScript there have been development in source-to-source compilers that target JavaScript. But JavaScript eventually is more popular for web-development than those compiled language. Let’s see how JavaScript got away with the criticisms.

Fragmented implementation and lack of standardization

The browser-war gave rise to reversed-engineered implementations of JavaScript. And individual programmers could not effort time to write JavaScript for each browser. So some people preferred to generate automated code for different browsers using compilers.

To solve the problem Netscape allowed it to be standardized as ECMAScript. Now there are multiple open-source implementations of JavaScript. And the most popular of them uses Just-in-time compilation. So it provides better opportunity to write uniform code for the developers. Again there are frameworks like jquery that wrap the platform depended code to give an uniform API. Finally the fragmentation is not a problem anymore.

Standardization that resulted javaScript to be compiler target

Again the cross-browser compatibility of javaScript gave the rise of source-to-source compilers (such as Emscripten) that target asm.js and NaCl. The asm.js is precompiled(ahead-of-time compilation) javaScript that allow the browser to run asm.js based application much faster.

JavaScript is slow

JavaScript performance is affected for varied reason. One of them being the support for dynamic type. Another being the dynamic binding. There are ways to get away with this things. The V8 engine actually uses JIT compiler that compiles the javaScript into native code on runtime, instead of interpreting. And the V8 developers compare the JavaScript performance with C/C++. They have some best practice suggestions about JavaScript. The idea boil down to ,

  • not to use undefined rather use static types,
  • to avoid arrays of varying types,
  • finally to use less constructors and initialize all the variables in the constructors.

The poor coding can be identified by some static analysis. And these tools can be integrated in the IDE and browser. This way the programmers get notified of the performance issues.

Frameworks are the right way

Now there are some emerging trends of development regarding JavaScript. It is done by some frameworks and runtimes. Some of them are,

  • jquery(It is more like library than a framework with easy-to-use API with a lot of open-source modules),
  • prototypejs,
  • threeJS,
  • reactJS,
  • backboneJS
  • nodeJS(Not a framework but a runtime for server-side-javascript and desktop application, it features a lot of packages/modules as npm),

Some of them are domain specific and some are for general use. These frameworks feature popular programming patterns for object based language. They allow us to use those well-written patterns. It makes the user code small. It is like “write less do more”. Less code gives less bugs and may be less performance hazards. In that sense less is good. Again these frameworks allow us to write browser independent code. These frameworks also take advantage of the ahead of time compilation. This is why they are immensely popular.

A note on nodeJS

NodeJS is the JavaScript runtime that works on the vast range of platforms. It uses event-driven approach of concurrent programming which is closely relates to observer-pattern that is popular in Object-Oriented paradigm. There were a lot of issue dealing the concurrency and scalalibity in server-side scripting. NodeJS was keen to solve the problem in event-driven way. And as JavaScript is already popular in the web-development arena, NodeJS got huge success. It is supported by big companies. And there is an package-ecosystem, npm, based on nodeJS.

Again there are a lot of frameworks that work on top of NodeJS. Some of them being Express.js, Socket.io and Koa.js. And there is popular Atom IDE(runs over ioJS/(nodeJS variant) runtime) that support development based on NodeJS and JavasCript.

Future

As a C developer, I want to share that I like C so much. But I also knew that it contains a lot of blotted code. It makes things harder because it does not have a memory manager. But one intriguing thing about C is the portability as the ability to compile it in wide range of platforms, in the same way JavaScript has portability in the browser.

I worked on those things and I wrote a compiler that eventually generates C code out of Object-Oriented garbage collected code. And I grew some framework to support server-side development. I targeted C the same way that the source-to-source compilers target JavaScript.

But sometimes I get back to C for some reason. I discovered that my framework written in C also support doing cool things with small dependable code. I think my compiled-framework gave me greater understanding of cool stuff in C.

I think the compilers targeting the JavaScript are also giving new directions for JavaScript based development. JavaScript is now getting developer attractions by featuring runtimes, frameworks and IDEs. In fact there are a lot of packages available on these frameworks. Now they are also being used as desktop tools(GUI), command-line application and server-side scripting.

Wednesday, February 3, 2016

Memory profiler for shotodol framework

C programming language does not come up with garbage collector. It is not object oriented. But C is inevitable. C programs are portable into different platform. A lot of libraries and server applications are written in C. The Aroop compiler gives the developer flexibility to write object oriented Vala code that can generate C code. Likewise it is also possible to use existing C library in Vala code.

So Aroop is the source-to-source compiler. It compiles Vala code into C. The Aroop compiler is a fork of original Vala compiler. The Vala compiler generates code that uses the GObject library to represent the Object data. On the contrary the Aroop uses object pools.

Shotodol is an application framework based on Aroop compiler. It has instrumentations for memory profiling, dependency injection and more. In this blog we will disect the memory profiling feature.

The profiler can give the memory usage of specific module, it can dump existing string allocations and more.

help prof
Executing:help prof
<            help> -----------------------------------------------------------------
SYNOPSIS:
    profiler
         -heap          <none>  Show all the memory allocated in all the factories
       -string          <none>  Dump the string buffers
       -object          <none>  Show the objects
       -module          <text>  Select/filter out a module
<      Successful> -----------------------------------------------------------------

For example, if we investigate the memory usage of “core/console” module, we get the following.

prof -module core/console
Executing:prof -module core/console
<        profiler> -----------------------------------------------------------------
Source               Line  Module     -- pools      allocated  used       objects    slots      bitstring  pool size 
vsrc/ConsoleCommand.  2116 core/conso --          0          0          0          0          0         56         16
vsrc/ConsoleCommand.   954 core/conso --          0          0          0          0          0         56         16
vsrc/ConsoleCommand.   804 core/conso --          1      13792       8560         10         10         56         16
13792 bytes total, 8560 bytes used
<      Successful> -----------------------------------------------------------------

The table above says the line number where the memory pools are created. “vsrc/ConsoleCommand.c” is the generated C source. The pool allocates 16(it is set when the pool is created) slots at a time. Each slot size is assigned when the pool is created. The first two rows say that the pool is empty. The last row says that it contains 10 objects taking total 8KB space while the pool has 13KB(16 slots) allocated. And it says there is only one pool.

The profiling helps to set the optimal pool size. In optimal condition the pool does not waste too much unused memory and there is less system-call for malloc for pool creation.

It also identifies the memory leak or circular refernce that can invalidate garbage collection. This feature is particularly useful in the server application. In that scenario memory-leak is not desirable at all.

I hope to describe other shotodol features in the future. I just like to explain what the cool things it does.

Monday, February 1, 2016

Line of code

It is nice to have some numbers associated with my identity. I like the numbers and I like to define myself. As a part of that I did a project of know “which language you are”.

I admire the cloc application. It calculates the line of code out of an archive. Line of code gives a number that measure the amount of work. In that sense my work summary is as below.

File files blank comment code
libsync.txt 241 8649 9998 56467
aroop.txt 256 3561 2506 22042
miniim.txt 88 1757 3824 8572
shotodol.txt 134 574 867 6564
roopkotha.txt 66 737 990 4903
opp_factory.txt 23 517 308 3875
roopkotha_vela.txt 56 302 638 2689
hciplus.txt 29 207 141 2089
barrel.txt 47 270 135 1864
shotodol_net.txt 20 115 161 1454
shotodol_web.txt 20 116 189 1151
shotodol_db.txt 12 74 122 689
shotodol_script.txt 8 34 39 354
shotodol_media.txt 2 12 20 100
SUM: 1002 16925 19938 112813

That is glorious. 112K lines of code is big work. Needless to say, it only calculates major works.

Language files blank comment code
C 127 8070 7770 58476
Vala 424 3483 3279 27305
C/C++ Header 171 1662 3710 6752
Java 30 830 2867 3868
Vala Header 19 283 245 3387
C++ 16 448 589 2959
PHP 46 272 173 1907
CSS 19 372 138 1789
XHTML 26 325 62 1463
JavaScript 13 238 727 1438
make 66 571 50 1423
Lua 25 198 110 1252
Bourne Shell 7 51 93 221
Ant 2 22 28 155
m4 2 28 17 110
Perl 1 32 36 107
Assembly 2 14 41 84
HTML 2 6 0 41
XML 1 0 3 27
Bourne Again Shell 1 9 0 24
NAnt script 1 9 0 23
DOS Batch 1 2 0 2
SUM: 1002 16925 19938 112813

I also wrote small script to generate pie chart out of this data.

pie

Saturday, January 3, 2015

The dart experiment

Something to measure, the objective study

The darts game is very simple. But it takes a lot of attention or sagacity or something to perform better. Additionally it has a way to get numbers for measuring. I was trying to measure the something in effect of some activity.

Our world is a chaos

The relation of cause and effect is very hard to associate when our practical world is full of chaos. For example, eating something or doing something may or may not affect the something straight-forward. There are so many things interacting each other.

But there are measurements

I did the experiment for fun. Though I have a vogue intention to find the causality. I kept the records of the events and how they affect the performance of the darts game. The events are given below,

  1. Eating rice, cauliflower, soya nugget, olive oil, spinach, orange dish.
  2. Eating areca nut.
  3. Cognitive task and swimming.
  4. Meditation.
  5. Rosemary tea.
  6. Tea.
  7. Super-food.
  8. Coding.
  9. Song and dance.
  10. Late night. (The idea was to find if I am night owl or morning person.)

The result

The result shows that my performance peaked after song and dance. I do not know if the result is something to do with song and dance. I do not know if the effect is reproducible. But I know that there is an effect called the mozart-effect. I assume that did the trick.

Life is not darts game but a guided missile

The something we measure here may or may not have great effect in life. One important thing to note that life is more like guided missile than a simple dart. Once born we have inner power to change our path. And there are a lot more skills than just throwing the dart.

More

The results are affected by the causes that have immediate effects. But the things that take hours, months or more cannot be traced in this way of experiment. It may or may not demonstrate the effects of stimulants like tea or coffee or songs in short-term. I hope to come with more experiments on darts game, especially with the reproducibility of the effects. It is very interesting.