shrey.haria
BAN USER
public class PermuteRectangle {
public static void main(String args[] {
Point sp = new Point(0, 1);
permuteRectanlge(sp, 30);
}
public static void permuteRectanlge(Point startPoint, int area) {
List<Point> points = listFactors(area);
for (Point p : points) {
// flips for e.g. (1,3) --> (3,1)
if (p.x != p.y) {
Point p2 = new Point(p.y, p.x);
rotateRectangleAndPrint(startPoint, p2);
}
rotateRectangleAndPrint(startPoint, p);
}
}
// lists all the possible combination for that area
public static List<Point> listFactors(int area) {
int j = (int) Math.sqrt(area);
List<Point> points = new LinkedList<Point>();
for (int i = 1; i <= j; i++) {
if (area % i == 0) {
Point p = new Point(i, area / i);
points.add(p);
}
}
return points;
}
// rotates in 4 directions --> (x,y) , (-x, y) (-x, -y), (x, -y)
public static void rotateRectangleAndPrint(Point sp, Point ep) {
Point p = new Point(ep);
printCords(sp, p);
p = new Point(-ep.x, ep.y);
printCords(sp, p);
p = new Point(-ep.x, -ep.y);
printCords(sp, p);
p = new Point(ep.x, -ep.y);
printCords(sp, p);
}
// derives 4 cordinates from start and end points and print them.
public static void printCords(Point sp, Point ep) {
// rebase with start point
ep.x += sp.x;
ep.y += sp.y;
Point p1 = sp;
Point p2 = new Point(sp.x, ep.y);
Point p3 = ep;
Point p4 = new Point(ep.x, sp.y);
System.out.println("" + p1 + " " + p2 + " " + p3 + " " + p4);
}
private static class Point {
int x;
int y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
Point(Point p) {
this.x = p.x;
this.y = p.y;
}
@Override
public String toString() {
return String.format("(%d,%d)", x, y);
}
}
}
String creating is not required.
new String(content)
char array
content
can be used as it is.
- shrey.haria May 16, 2015public class Mingo {
// returns the number of calls to get a Mingo if there is otherwise returns 0
public static int findMingo(List<Integer> numbs) {
final int MINGO_SIZE = 10;
int[] rows = new int[MINGO_SIZE];
int[] columns = new int[MINGO_SIZE];
int diagnol = 0;
int i = 1;
for (int numb : numbs) {
int row = numb / MINGO_SIZE;
int column = numb % MINGO_SIZE;
if ((++rows[row] == MINGO_SIZE)
|| (++columns[column] == MINGO_SIZE)) {
return i;
}
if (row == column && ++diagnol == MINGO_SIZE) {
return i;
}
i++;
}
return 0;
}
}
Repmikebeasley033, Interviewer at Brooks Fashions
Working as an interviewer in Brooks Fashion's best amazing experience . Here I manage individuals which makes me refreshed . With ...
Repha1904536, Android test engineer at ABC TECH SUPPORT
Hello, I am an Executive recruiter. My role is to fill executive, high-level positions at companies. I have been practicing ...
Repmarthajpatton, Data Scientist at AppPerfect
Managed a small team implementing gravy in Prescott, AZ. Developed several new methods for easy break up spells.Had some ...
Repharveyoberion, Analyst at AMD
Hi, I am Harvey, from the USA. I am working as a soil scientist. I study soil as a natural ...
Repkrishamoris, Area Sales Manager at Accolite software
I am Krisha , an organized Cosmetology Instructor with 4 years of experience. Successful at keeping detailed records and personalizing lesson ...
RepRebecaGomes, Amazon Customer Service Number +1-808.800.0449 at ABC TECH SUPPORT
A printmaker designs and creates prints using techniques such as woodcuts or silkscreen, which are usually transferred to surfaces using ...
RepTerryMorales, Accountant at ADP
I assist other social and human service providers in providing client services in a wide variety of fields, such as ...
Repedenwraye, Photographic spotter at Enrich Garden Services
I'm more of a Photographic spotter than an expert at creating beautiful, functional and personalised products for teachers, mentors ...
RepCeliaParker, teacher at Illinoisstate
Experienced teacher with a background in education who is looking to complement graduate studies with the opportunity to teach at ...
- shrey.haria May 17, 2015