Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/example/fromalharith/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,4 @@ public Complaint searchComplaintById(int id) {

}
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/example/fromalharith/board.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1111111111
@000000001
1111101111
1001100001
1010101101
1010000101
1011110101
1000010111
111101000E
1111111111
89 changes: 89 additions & 0 deletions src/main/java/org/example/fromalharith/slitheringCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.example.fromalharith;

import java.io.*;
import java.util.*;

public class slitheringCode {
public static void main(String[] args) throws IOException {

String filePath = "src/main/java/org/example/fromalharith/board.txt";

// Read file and remove spaces into logical grid
List<String> lines = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
lines.add(line.replace(" ", "")); // remove spaces for grid
}
}

int rows = lines.size();
int cols = lines.get(0).length();

char[][] grid = new char[rows][cols];

for (int r = 0; r < rows; r++) {
grid[r] = lines.get(r).toCharArray();
}

// Initialize snake queue
Queue<int[]> snake = new LinkedList<>();
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
if (grid[r][c] == 'o') {
snake.offer(new int[]{r, c});
}
}
}

Scanner sc = new Scanner(System.in);

// directions
String[] dirs = {"up", "down", "left", "right"};
int[][] moves = {
{-1, 0}, // up
{1, 0}, // down
{0, -1}, // left
{0, 1} // right
};

while (true) {
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
System.out.print(grid[r][c] + " ");
}
System.out.println();
}

System.out.print("Enter your move!: ");
String direction = sc.next();
int steps = sc.nextInt();

for (int step = 0; step < steps; step++) {
int[] head = ((LinkedList<int[]>) snake).getLast();
int newRow = head[0];
int newCol = head[1];

for (int i = 0; i < dirs.length; i++) {
if (direction.equals(dirs[i])) {
newRow += moves[i][0];
newCol += moves[i][1];
}
}

// check board
if (newRow < 0 || newRow >= rows || newCol < 0 || newCol >= cols) {
System.out.println("Hit the wall!");
break;
}

// move snake
snake.offer(new int[]{newRow, newCol});
grid[newRow][newCol] = 'o';

int[] tail = snake.poll();
grid[tail[0]][tail[1]] = '-';
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example.fromalharith.sprint3;

public class climbingCount {
public static void main(String[] args) {

for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "\t");
}
System.out.println();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.example.fromalharith.sprint3;

public class hollowPyramid {
public static void main(String[] args) {

int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n - i; j++) {
System.out.print(" ");
}

if (i == n){
for (int k = 1; k < n + n; k++) {
System.out.print("*");
}
}
else {
System.out.print("*");
}
if (i != n && i != 1) {

for (int l = 1; l < i + i - 2; l++) {
System.out.print(" ");
}
System.out.print("*");
}
System.out.println();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.example.fromalharith.sprint3;

import java.util.Scanner;

public class loopChallenge {
public static void main(String[] args) {

Scanner inputObjBuffer = new Scanner(System.in);

for (int i = 1 ; i < 5 ; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
for (int m = i-1; m >= 1; m--) {
System.out.print(m + " ");
}
System.out.println();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example.fromalharith.sprint3;

public class starMountain {
public static void main(String[] args) {

int Rows=5;
for (int i = 1 ; i <= Rows ; i++) {
for (int j = i; j <= Rows; j++) {
System.out.print(" ");
}
for (int star = 1; star <= 2 * i - 1; star++) {
System.out.print("*");
}
System.out.println("");
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example.fromalharith.sprint3;

public class theStaircaseChallenge {
public static void main(String[] args) {


for (int i=1 ; i<=5 ; i++){
for (int j=1 ; j<=i ; j++) {
System.out.print("#");
}
System.out.println();
}


}
}

Loading