these are some of the problems that I have tackled on Topcoder.These maybe helpful for verification.
Created
November 22, 2014 17:51
-
-
Save rihenperry/7d58b9ae25a1be37ce5d to your computer and use it in GitHub Desktop.
topcoders problems
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package topCoderAlgos; | |
/** | |
* This program generates topCoderAlgos.Fibonacii series till | |
* the target number | |
*/ | |
import java.util.ArrayList; | |
public class Fibonacii { | |
private ArrayList<Integer> fibSeries; | |
public ArrayList<Integer> generateFibonacii(int number) { | |
fibSeries = new ArrayList<>(); | |
int leftNum = 0; | |
int rightNum = 1; | |
for (int num = 0; num <= number; num++) { | |
fibSeries.add(leftNum); | |
leftNum = leftNum + rightNum; | |
rightNum = leftNum - rightNum; | |
} | |
return fibSeries; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package topCoderAlgos;/* | |
* This program is based on a concept of real world Image Dithering which | |
* works by mixing more than one solid unique color elements(pixels) and | |
* generating new color elements from the same. | |
* This program checks for unique dithered elements in the screen and | |
* returns the result*/ | |
public class ImageDithering { | |
private int netCount = 0; | |
public int count(String dithered, String[] screen) { | |
char ditherChar[] = dithered.toCharArray(); | |
for (String element : screen) { | |
char elementToChar[] = element.toCharArray(); | |
for (int eachChar = 0; eachChar < elementToChar.length; eachChar++) | |
for (char eachDither : ditherChar) | |
if (eachDither == elementToChar[eachChar]) netCount++; | |
} | |
return netCount; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package topCoderAlgos; | |
/** | |
* This class performs matrix operations | |
*/ | |
public class Matrix { | |
private int N; | |
private int[][] c; | |
public int[][] computeDotMatrix(int[][] a,int[][] b){ | |
N = a.length; | |
c = new int[N][N]; | |
System.out.println(N); | |
for (int i = 0; i < N; i++) | |
for (int j = 0; j < N; j++) | |
{ // Compute dot product of row i and column j. | |
for (int k = 0; k < N; k++){ | |
System.out.println("c"+"["+i+"]"+"["+j+"]"+"="+"a["+i+"]"+"["+k+"]"+"b"+"["+k+"]"+"["+j+"]"+"N="+N); | |
c[i][j] += a[i][k]*b[k][j]; | |
} | |
} | |
return c; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package topCoderAlgos;/* | |
*Class topCoderAlgos.Time takes CPU time and breaks it into | |
* hours,minutes and seconds.It further presents it | |
* in human readable format | |
*/ | |
public class Time { | |
public String convertMachineTime(int seconds) { | |
short calHr, calMin, calMinSec; | |
calHr = (short) (seconds / (60 * 60)); | |
calMinSec = (short) (seconds / 60); | |
calMin = (short) (calMinSec - (calHr * 60)); | |
seconds = (short) (seconds % 3600); | |
seconds = seconds % 60; | |
return String.format("%d:%d:%d", calHr, calMin, seconds); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment