Saturday, July 8, 2017

BUSYMAN SPOJ Greedy C

Algorithm:

1. Sort on end times.
2. Iterate over sorted list
        2.1 If the current activity overlaps, skip it
        2.2 If it doesn't increase count of answer. Set new time to end time of this activity.

Code: 

Friday, July 7, 2017

Friday, January 20, 2017

Minimal Perl code to generate 32 characters alphanumeric random string.

This code generates a random 32 characters string.

use v5.22;
print join '', map {state $c = ['a'..'z', 'A'..'Z', '0'..'9']; $$c[rand @$c]} 0..31;

Output (6 runs):

NUPtwWIRTDOTmoBZ2xgDtceHjvjUloAi
7rKd8024tNZdgCUJJjlrQlBqKh53lpUV
dSPKG8uODbriqmbtEFDvrypbrx22BhuO
A5ozpCeKTCY322otKSlhiAcOV4E8LwZS
DTKcTiUJ7xGFO3kR6Tmh29J5rT88jBoJ
y7Q7VeCY7q83P7c2D2JK9C8svy59efXw

Tuesday, January 3, 2017

Printing column data one by one - awk

Suppose you have a file like this:



You need to get this output:


, you can use this awk code: