-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
467 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package info.jab.aoc.day6; | ||
|
||
import info.jab.aoc.Day; | ||
|
||
/** | ||
* https://adventofcode.com/2015/day/6 | ||
*/ | ||
public class Day6 implements Day<Integer> { | ||
|
||
@Override | ||
public Integer getPart1Result(String fileName) { | ||
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public Integer getPart2Result(String fileName) { | ||
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package info.jab.aoc.day6; | ||
public class LightController { | ||
private LightGrid lightGrid; | ||
|
||
public LightController() { | ||
lightGrid = new LightGrid(); | ||
} | ||
|
||
public void executeCommand(String command, int x1, int y1, int x2, int y2) { | ||
switch (command.toLowerCase().trim()) { | ||
case "turn on": | ||
lightGrid.turnOn(x1, y1, x2, y2); | ||
break; | ||
case "turn off": | ||
lightGrid.turnOff(x1, y1, x2, y2); | ||
break; | ||
case "toggle": | ||
lightGrid.toggle(x1, y1, x2, y2); | ||
break; | ||
default: | ||
throw new IllegalArgumentException("Comando no válido: " + command); | ||
} | ||
} | ||
|
||
public int getTotalLightsOn() { | ||
return lightGrid.getNumberOfLightsOn(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package info.jab.aoc.day6; | ||
|
||
public class LightGrid { | ||
private boolean[][] grid; | ||
private static final int GRID_SIZE = 1000; | ||
|
||
public LightGrid() { | ||
grid = new boolean[GRID_SIZE][GRID_SIZE]; | ||
// Inicialmente todas las luces están apagadas (false) | ||
} | ||
|
||
public void turnOn(int x1, int y1, int x2, int y2) { | ||
for (int i = x1; i <= x2; i++) { | ||
for (int j = y1; j <= y2; j++) { | ||
grid[i][j] = true; | ||
} | ||
} | ||
} | ||
|
||
public void turnOff(int x1, int y1, int x2, int y2) { | ||
for (int i = x1; i <= x2; i++) { | ||
for (int j = y1; j <= y2; j++) { | ||
grid[i][j] = false; | ||
} | ||
} | ||
} | ||
|
||
public void toggle(int x1, int y1, int x2, int y2) { | ||
for (int i = x1; i <= x2; i++) { | ||
for (int j = y1; j <= y2; j++) { | ||
grid[i][j] = !grid[i][j]; | ||
} | ||
} | ||
} | ||
|
||
public int getNumberOfLightsOn() { | ||
int count = 0; | ||
for (int i = 0; i < GRID_SIZE; i++) { | ||
for (int j = 0; j < GRID_SIZE; j++) { | ||
if (grid[i][j]) count++; | ||
} | ||
} | ||
return count; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Feature: Christmas Light Configuration | ||
As a competitive resident | ||
I want to follow Santa's light instructions | ||
In order to win the holiday decoration contest | ||
|
||
Background: | ||
Given I have a 1000x1000 grid of lights | ||
And all lights are initially turned off | ||
|
||
Scenario Outline: Execute different lighting commands | ||
When I execute the command "<command>" from <x1>,<y1> through <x2>,<y2> | ||
Then I should see <result> lights turned on | ||
|
||
Examples: | ||
| command | x1 | y1 | x2 | y2 | result | | ||
| turn on | 0 | 0 | 999 | 999 | 1000000 | | ||
| toggle | 0 | 0 | 999 | 0 | 1000 | | ||
| turn off | 499 | 499 | 500 | 500 | 0 | | ||
|
||
Scenario: Process multiple instructions | ||
When I execute the following commands: | ||
| command | x1 | y1 | x2 | y2 | | ||
| turn on | 0 | 0 | 999 | 999 | | ||
| toggle | 0 | 0 | 999 | 0 | | ||
| turn off | 499 | 499 | 500 | 500 | | ||
Then the total number of lights turned on should be correct | ||
|
||
Rules: | ||
- Coordinates range from 0 to 999 in each direction | ||
- Coordinates are inclusive | ||
- "turn on" turns on all lights in the specified range | ||
- "turn off" turns off all lights in the specified range | ||
- "toggle" switches the state of all lights in the specified range |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package info.jab.aoc.day6; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.putoet.utils.Timer; | ||
|
||
class Day6Test { | ||
|
||
@Test | ||
void should_solve_day6_part1() { | ||
Timer.run(() -> { | ||
//Given | ||
String fileName = "/day6/day6-input.txt"; | ||
|
||
//When | ||
var day = new Day6(); | ||
var result = day.getPart1Result(fileName); | ||
|
||
//Then | ||
then(result).isEqualTo(238); | ||
}); | ||
} | ||
|
||
@Test | ||
void should_solve_day6_part2() { | ||
Timer.run(() -> { | ||
//Given | ||
String fileName = "/day6/day6-input.txt"; | ||
|
||
//When | ||
var day = new Day6(); | ||
var result = day.getPart2Result(fileName); | ||
|
||
//Then | ||
then(result).isEqualTo(69); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.