From 84203d57819fe4622072b83f79ea2c5783078e1a Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Thu, 9 Apr 2026 13:50:45 +0700 Subject: [PATCH 01/10] fix: fix data on elevatorhall problem 1 --- .../data/java/elevatorhall/problems.json | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/scripts/data/java/elevatorhall/problems.json b/src/scripts/data/java/elevatorhall/problems.json index 94be9ac..4335552 100644 --- a/src/scripts/data/java/elevatorhall/problems.json +++ b/src/scripts/data/java/elevatorhall/problems.json @@ -1,25 +1,25 @@ [ { "title": "ELV-P1-PROB-001", - "description": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n\npublic class AuthDaemon {\n\n public static int hashPassword(String s) {\n // Recursively sum the ASCII value of each character.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(hashPassword(\"DOOR\"));\n System.out.println(hashPassword(\"KEY\"));\n System.out.println(hashPassword(\"\"));\n }\n}", + "description": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n\npublic class AuthDaemon {\n\n public static int hashPassword(String s) {\n // Recursively sum the ASCII value of each character.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(hashPassword(\"DOOR\"));\n System.out.println(hashPassword(\"KEY\"));\n System.out.println(hashPassword(\"\"));\n }\n}" + "java": "public class AuthDaemon {\npublic static int hashPassword(String s) {\n// Recursively sum the ASCII value of each character.\n//Player code goes here\n}\n\n public static void main(String[] args) {\n\t Scanner sc = new Scanner(System.in);\n\t String str = sc.nextLine();\n System.out.println(hashPassword(str));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "\"DOOR\"", - "output": "289", + "input": "DOOR", + "output": "308", "is_hidden": false }, { - "input": "\"KEY\"", - "output": "236", + "input": "KEY", + "output": "233", "is_hidden": true }, { - "input": "\"\"", + "input": "", "output": "0", "is_hidden": true } @@ -27,63 +27,68 @@ }, { "title": "ELV-P1-PROB-002", - "description": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\npublic class AuthDaemon {\n\n public static int countChar(String s, char target) {\n // Recursively count how many times target appears in s.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(countChar(\"ESCALATE\", 'E'));\n System.out.println(countChar(\"ACCESS\", 'S'));\n System.out.println(countChar(\"DOOR\", 'Z'));\n }\n}", + "description": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\n", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\npublic class AuthDaemon {\n\n public static int countChar(String s, char target) {\n // Recursively count how many times target appears in s.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(countChar(\"ESCALATE\", 'E'));\n System.out.println(countChar(\"ACCESS\", 'S'));\n System.out.println(countChar(\"DOOR\", 'Z'));\n }\n}" + "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static int countChar(String s, char target) {\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n char c = sc.next().charAt(0);\n System.out.println(countChar(str,c));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "\"ESCALATE\", 'E'", + "input": "ESCALATE\nE", "output": "2", "is_hidden": false }, { - "input": "\"ACCESS\", 'S'", + "input": "ACCESS\nS", "output": "2", "is_hidden": true }, { - "input": "\"DOOR\", 'Z'", + "input": "DOOR\nZ", "output": "0", "is_hidden": true + }, + { + "input": "AAAA\nA", + "output": "4", + "is_hidden": true } ] }, { "title": "ELV-P1-PROB-003", - "description": "// [NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n\npublic class AuthDaemon {\n\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(reverseCode(\"TIXE\"));\n System.out.println(reverseCode(\"EDOC\"));\n System.out.println(reverseCode(\"\"));\n }\n}", + "description": "[NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// [NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n\npublic class AuthDaemon {\n\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(reverseCode(\"TIXE\"));\n System.out.println(reverseCode(\"EDOC\"));\n System.out.println(reverseCode(\"\"));\n }\n}" + "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n // player code goes here\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n System.out.println(reverseCode(str));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "\"TIXE\"", + "input": "TIXE", "output": "EXIT", "is_hidden": false }, { - "input": "\"EDOC\"", + "input": "EDOC", "output": "CODE", "is_hidden": true }, { - "input": "\"\"", - "output": "", + "input": "SANDY", + "output": "YDNAS", "is_hidden": true } ] }, { "title": "ELV-P1-PROB-004", - "description": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.\n\npublic class AuthDaemon {\n\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(sumDigits(4821));\n System.out.println(sumDigits(9));\n System.out.println(sumDigits(0));\n }\n}", + "description": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.\n\npublic class AuthDaemon {\n\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(sumDigits(4821));\n System.out.println(sumDigits(9));\n System.out.println(sumDigits(0));\n }\n}" + "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n // player code goes here \n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int num = sc.nextInt();\n System.out.println(sumDigits(num));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -126,11 +131,11 @@ }, { "title": "ELV-P2-PROB-002", - "description": "// [NULL] is hiding in wireless dead zones to avoid detection.\n// The signal map is a grid, find every cell below strength 10.\n// Expose the dead zones and the relay comes back online.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}", + "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.\n", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// [NULL] is hiding in wireless dead zones to avoid detection.\n// The signal map is a grid, find every cell below strength 10.\n// Expose the dead zones and the relay comes back online.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}" }, "test_cases": [ { @@ -147,11 +152,11 @@ }, { "title": "ELV-P2-PROB-003", - "description": "// Security needs a headcount to confirm the building is clear.\n// The attendance grid uses 1 for present, 0 for absent.\n// Count the occupied cells and report the total.\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}", + "description": "Security needs a headcount to confirm the building is clear.\nThe attendance grid uses 1 for present, 0 for absent.\nCount the occupied cells and report the total.\n", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// Security needs a headcount to confirm the building is clear.\n// The attendance grid uses 1 for present, 0 for absent.\n// Count the occupied cells and report the total.\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}" }, "test_cases": [ { @@ -168,11 +173,11 @@ }, { "title": "ELV-P2-PROB-004", - "description": "// One server rack is running [NULL]'s process and overheating the room.\n// Find the single hottest cell in the thermal grid.\n// Return its location and temperature, then we know where to cut power.\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}", + "description": "One server rack is running [NULL]'s process and overheating the room.\nFind the single hottest cell in the thermal grid.\nReturn its location and temperature, then we know where to cut power.\n", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// One server rack is running [NULL]'s process and overheating the room.\n// Find the single hottest cell in the thermal grid.\n// Return its location and temperature, then we know where to cut power.\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}" }, "test_cases": [ { @@ -189,11 +194,11 @@ }, { "title": "ELV-P3-PROB-001", - "description": "// [NULL] wiped both card subclasses from the clearance system.\n// Every card now returns UNKNOWN and every door stays locked.\n// The base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}", + "description": "[NULL] wiped both card subclasses from the clearance system.\nEvery card now returns UNKNOWN and every door stays locked.\nThe base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}", "difficulty": "Hard", "category": "ELV-P3", "templates": { - "java": "// [NULL] wiped both card subclasses from the clearance system.\n// Every card now returns UNKNOWN and every door stays locked.\n// The base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}" }, "test_cases": [ { From 6a2a285600907d7a7ebbd6815641053e4bf3d558 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Thu, 9 Apr 2026 21:47:58 +0700 Subject: [PATCH 02/10] refactor: update problem templates to use Scanner for dynamic input and add comprehensive test cases --- .../data/java/elevatorhall/problems.json | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/scripts/data/java/elevatorhall/problems.json b/src/scripts/data/java/elevatorhall/problems.json index 4335552..3bb04e4 100644 --- a/src/scripts/data/java/elevatorhall/problems.json +++ b/src/scripts/data/java/elevatorhall/problems.json @@ -110,43 +110,63 @@ }, { "title": "ELV-P2-PROB-001", - "description": "// The corridor heat sensor grid feeds into this machine.\n// [NULL] broke the scan function so it never flags anomalies.\n// Restore it, the security relay needs a clean threat report.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] grid = {\n {12, 45, 88, 23},\n {91, 34, 56, 77},\n {10, 82, 19, 95},\n {60, 55, 33, 84}\n };\n System.out.println(findHotCells(grid));\n\n int[][] grid2 = {{10, 20}, {30, 40}};\n System.out.println(findHotCells(grid2));\n }\n}", + "description": "The corridor heat sensor grid feeds into this machine.\n[NULL] broke the scan function so it never flags anomalies.\nRestore it, the security relay needs a clean threat report.", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// The corridor heat sensor grid feeds into this machine.\n// [NULL] broke the scan function so it never flags anomalies.\n// Restore it, the security relay needs a clean threat report.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] grid = {\n {12, 45, 88, 23},\n {91, 34, 56, 77},\n {10, 82, 19, 95},\n {60, 55, 33, 84}\n };\n System.out.println(findHotCells(grid));\n\n int[][] grid2 = {{10, 20}, {30, 40}};\n System.out.println(findHotCells(grid2));\n }\n}" + "java": "import java.util.ArrayList;\nimport java.util.Scanner;\npublic class GridScanner {\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n // player code goes here\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] grid = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n grid[i][j] = sc.nextInt();\n System.out.println(findHotCells(grid));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "4 4\n12 45 88 23\n91 34 56 77\n10 82 19 95\n60 55 33 84", "output": "[0,2]=88, [1,0]=91, [2,1]=82, [2,3]=95, [3,3]=84", "is_hidden": false }, { - "input": "", + "input": "3 3\n10 20 30\n40 50 60\n70 80 90", + "output": "[2,2]=90", + "is_hidden": true + }, + { + "input": "2 2\n10 20\n30 40", "output": "none", "is_hidden": true + }, + { + "input": "1 1\n81", + "output": "[0,0]=81", + "is_hidden": true } ] }, { "title": "ELV-P2-PROB-002", - "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.\n", + "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}" + "java": "import java.util.ArrayList;\nimport java.util.Scanner;\npublic class GridScanner {\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n // player code goes here \n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] signal = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n signal[i][j] = sc.nextInt();\n System.out.println(findDeadZones(signal));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "3 4\n55 3 80 7\n90 42 8 60\n5 70 33 2", "output": "[0,1]=3, [0,3]=7, [1,2]=8, [2,0]=5, [2,3]=2", "is_hidden": false }, { - "input": "", + "input": "2 2\n30 40\n50 60", + "output": "none", + "is_hidden": true + }, + { + "input": "1 1\n10", "output": "none", "is_hidden": true + }, + { + "input": "1 1\n5", + "output": "[0,0]=5", + "is_hidden": true } ] }, From 2fd64d8c717ee542ab4f70f8b663ce46be0e7570 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Mon, 27 Apr 2026 23:11:34 +0700 Subject: [PATCH 03/10] chore: rename Bruno collection to devscape-code-executor --- bruno/bruno.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bruno/bruno.json b/bruno/bruno.json index b271425..5e620a5 100644 --- a/bruno/bruno.json +++ b/bruno/bruno.json @@ -1,6 +1,6 @@ { "version": "1", - "name": "bruno", + "name": "devscape-code-executor", "type": "collection", "ignore": [ "node_modules", From 8aa1e802bfa9a5d200a694c98319a31182643e53 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Thu, 9 Apr 2026 13:50:45 +0700 Subject: [PATCH 04/10] fix: fix data on elevatorhall problem 1 --- .../data/java/elevatorhall/problems.json | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/scripts/data/java/elevatorhall/problems.json b/src/scripts/data/java/elevatorhall/problems.json index 94be9ac..4335552 100644 --- a/src/scripts/data/java/elevatorhall/problems.json +++ b/src/scripts/data/java/elevatorhall/problems.json @@ -1,25 +1,25 @@ [ { "title": "ELV-P1-PROB-001", - "description": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n\npublic class AuthDaemon {\n\n public static int hashPassword(String s) {\n // Recursively sum the ASCII value of each character.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(hashPassword(\"DOOR\"));\n System.out.println(hashPassword(\"KEY\"));\n System.out.println(hashPassword(\"\"));\n }\n}", + "description": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n\npublic class AuthDaemon {\n\n public static int hashPassword(String s) {\n // Recursively sum the ASCII value of each character.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(hashPassword(\"DOOR\"));\n System.out.println(hashPassword(\"KEY\"));\n System.out.println(hashPassword(\"\"));\n }\n}" + "java": "public class AuthDaemon {\npublic static int hashPassword(String s) {\n// Recursively sum the ASCII value of each character.\n//Player code goes here\n}\n\n public static void main(String[] args) {\n\t Scanner sc = new Scanner(System.in);\n\t String str = sc.nextLine();\n System.out.println(hashPassword(str));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "\"DOOR\"", - "output": "289", + "input": "DOOR", + "output": "308", "is_hidden": false }, { - "input": "\"KEY\"", - "output": "236", + "input": "KEY", + "output": "233", "is_hidden": true }, { - "input": "\"\"", + "input": "", "output": "0", "is_hidden": true } @@ -27,63 +27,68 @@ }, { "title": "ELV-P1-PROB-002", - "description": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\npublic class AuthDaemon {\n\n public static int countChar(String s, char target) {\n // Recursively count how many times target appears in s.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(countChar(\"ESCALATE\", 'E'));\n System.out.println(countChar(\"ACCESS\", 'S'));\n System.out.println(countChar(\"DOOR\", 'Z'));\n }\n}", + "description": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\n", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\npublic class AuthDaemon {\n\n public static int countChar(String s, char target) {\n // Recursively count how many times target appears in s.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(countChar(\"ESCALATE\", 'E'));\n System.out.println(countChar(\"ACCESS\", 'S'));\n System.out.println(countChar(\"DOOR\", 'Z'));\n }\n}" + "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static int countChar(String s, char target) {\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n char c = sc.next().charAt(0);\n System.out.println(countChar(str,c));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "\"ESCALATE\", 'E'", + "input": "ESCALATE\nE", "output": "2", "is_hidden": false }, { - "input": "\"ACCESS\", 'S'", + "input": "ACCESS\nS", "output": "2", "is_hidden": true }, { - "input": "\"DOOR\", 'Z'", + "input": "DOOR\nZ", "output": "0", "is_hidden": true + }, + { + "input": "AAAA\nA", + "output": "4", + "is_hidden": true } ] }, { "title": "ELV-P1-PROB-003", - "description": "// [NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n\npublic class AuthDaemon {\n\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(reverseCode(\"TIXE\"));\n System.out.println(reverseCode(\"EDOC\"));\n System.out.println(reverseCode(\"\"));\n }\n}", + "description": "[NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// [NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n\npublic class AuthDaemon {\n\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(reverseCode(\"TIXE\"));\n System.out.println(reverseCode(\"EDOC\"));\n System.out.println(reverseCode(\"\"));\n }\n}" + "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n // player code goes here\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n System.out.println(reverseCode(str));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "\"TIXE\"", + "input": "TIXE", "output": "EXIT", "is_hidden": false }, { - "input": "\"EDOC\"", + "input": "EDOC", "output": "CODE", "is_hidden": true }, { - "input": "\"\"", - "output": "", + "input": "SANDY", + "output": "YDNAS", "is_hidden": true } ] }, { "title": "ELV-P1-PROB-004", - "description": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.\n\npublic class AuthDaemon {\n\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(sumDigits(4821));\n System.out.println(sumDigits(9));\n System.out.println(sumDigits(0));\n }\n}", + "description": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.\n\npublic class AuthDaemon {\n\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(sumDigits(4821));\n System.out.println(sumDigits(9));\n System.out.println(sumDigits(0));\n }\n}" + "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n // player code goes here \n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int num = sc.nextInt();\n System.out.println(sumDigits(num));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -126,11 +131,11 @@ }, { "title": "ELV-P2-PROB-002", - "description": "// [NULL] is hiding in wireless dead zones to avoid detection.\n// The signal map is a grid, find every cell below strength 10.\n// Expose the dead zones and the relay comes back online.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}", + "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.\n", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// [NULL] is hiding in wireless dead zones to avoid detection.\n// The signal map is a grid, find every cell below strength 10.\n// Expose the dead zones and the relay comes back online.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}" }, "test_cases": [ { @@ -147,11 +152,11 @@ }, { "title": "ELV-P2-PROB-003", - "description": "// Security needs a headcount to confirm the building is clear.\n// The attendance grid uses 1 for present, 0 for absent.\n// Count the occupied cells and report the total.\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}", + "description": "Security needs a headcount to confirm the building is clear.\nThe attendance grid uses 1 for present, 0 for absent.\nCount the occupied cells and report the total.\n", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// Security needs a headcount to confirm the building is clear.\n// The attendance grid uses 1 for present, 0 for absent.\n// Count the occupied cells and report the total.\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}" }, "test_cases": [ { @@ -168,11 +173,11 @@ }, { "title": "ELV-P2-PROB-004", - "description": "// One server rack is running [NULL]'s process and overheating the room.\n// Find the single hottest cell in the thermal grid.\n// Return its location and temperature, then we know where to cut power.\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}", + "description": "One server rack is running [NULL]'s process and overheating the room.\nFind the single hottest cell in the thermal grid.\nReturn its location and temperature, then we know where to cut power.\n", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// One server rack is running [NULL]'s process and overheating the room.\n// Find the single hottest cell in the thermal grid.\n// Return its location and temperature, then we know where to cut power.\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}" }, "test_cases": [ { @@ -189,11 +194,11 @@ }, { "title": "ELV-P3-PROB-001", - "description": "// [NULL] wiped both card subclasses from the clearance system.\n// Every card now returns UNKNOWN and every door stays locked.\n// The base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}", + "description": "[NULL] wiped both card subclasses from the clearance system.\nEvery card now returns UNKNOWN and every door stays locked.\nThe base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}", "difficulty": "Hard", "category": "ELV-P3", "templates": { - "java": "// [NULL] wiped both card subclasses from the clearance system.\n// Every card now returns UNKNOWN and every door stays locked.\n// The base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}" + "java": "import java.util.ArrayList;\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}" }, "test_cases": [ { From ee2a1426e5088cea5b971b3fdbd29c64b445dd40 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Thu, 9 Apr 2026 21:47:58 +0700 Subject: [PATCH 05/10] refactor: update problem templates to use Scanner for dynamic input and add comprehensive test cases --- .../data/java/elevatorhall/problems.json | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/scripts/data/java/elevatorhall/problems.json b/src/scripts/data/java/elevatorhall/problems.json index 4335552..3bb04e4 100644 --- a/src/scripts/data/java/elevatorhall/problems.json +++ b/src/scripts/data/java/elevatorhall/problems.json @@ -110,43 +110,63 @@ }, { "title": "ELV-P2-PROB-001", - "description": "// The corridor heat sensor grid feeds into this machine.\n// [NULL] broke the scan function so it never flags anomalies.\n// Restore it, the security relay needs a clean threat report.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] grid = {\n {12, 45, 88, 23},\n {91, 34, 56, 77},\n {10, 82, 19, 95},\n {60, 55, 33, 84}\n };\n System.out.println(findHotCells(grid));\n\n int[][] grid2 = {{10, 20}, {30, 40}};\n System.out.println(findHotCells(grid2));\n }\n}", + "description": "The corridor heat sensor grid feeds into this machine.\n[NULL] broke the scan function so it never flags anomalies.\nRestore it, the security relay needs a clean threat report.", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "// The corridor heat sensor grid feeds into this machine.\n// [NULL] broke the scan function so it never flags anomalies.\n// Restore it, the security relay needs a clean threat report.\n\nimport java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] grid = {\n {12, 45, 88, 23},\n {91, 34, 56, 77},\n {10, 82, 19, 95},\n {60, 55, 33, 84}\n };\n System.out.println(findHotCells(grid));\n\n int[][] grid2 = {{10, 20}, {30, 40}};\n System.out.println(findHotCells(grid2));\n }\n}" + "java": "import java.util.ArrayList;\nimport java.util.Scanner;\npublic class GridScanner {\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n // player code goes here\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] grid = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n grid[i][j] = sc.nextInt();\n System.out.println(findHotCells(grid));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "4 4\n12 45 88 23\n91 34 56 77\n10 82 19 95\n60 55 33 84", "output": "[0,2]=88, [1,0]=91, [2,1]=82, [2,3]=95, [3,3]=84", "is_hidden": false }, { - "input": "", + "input": "3 3\n10 20 30\n40 50 60\n70 80 90", + "output": "[2,2]=90", + "is_hidden": true + }, + { + "input": "2 2\n10 20\n30 40", "output": "none", "is_hidden": true + }, + { + "input": "1 1\n81", + "output": "[0,0]=81", + "is_hidden": true } ] }, { "title": "ELV-P2-PROB-002", - "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.\n", + "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] signal = {\n {55, 3, 80, 7},\n {90, 42, 8, 60},\n { 5, 70, 33, 2}\n };\n System.out.println(findDeadZones(signal));\n\n int[][] signal2 = {{50, 60}, {70, 80}};\n System.out.println(findDeadZones(signal2));\n }\n}" + "java": "import java.util.ArrayList;\nimport java.util.Scanner;\npublic class GridScanner {\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n // player code goes here \n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] signal = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n signal[i][j] = sc.nextInt();\n System.out.println(findDeadZones(signal));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "3 4\n55 3 80 7\n90 42 8 60\n5 70 33 2", "output": "[0,1]=3, [0,3]=7, [1,2]=8, [2,0]=5, [2,3]=2", "is_hidden": false }, { - "input": "", + "input": "2 2\n30 40\n50 60", + "output": "none", + "is_hidden": true + }, + { + "input": "1 1\n10", "output": "none", "is_hidden": true + }, + { + "input": "1 1\n5", + "output": "[0,0]=5", + "is_hidden": true } ] }, From a2ed17888db1e82e57038004ab606efb436f434d Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Mon, 27 Apr 2026 23:40:45 +0700 Subject: [PATCH 06/10] data: update chunks and problem on elevator hall for clarity and make it runnable --- .../data/java/elevatorhall/chunks.json | 90 ++++++++------- .../data/java/elevatorhall/problems.json | 107 ++++++++++-------- 2 files changed, 110 insertions(+), 87 deletions(-) diff --git a/src/scripts/data/java/elevatorhall/chunks.json b/src/scripts/data/java/elevatorhall/chunks.json index c408967..b6298b4 100644 --- a/src/scripts/data/java/elevatorhall/chunks.json +++ b/src/scripts/data/java/elevatorhall/chunks.json @@ -3,160 +3,168 @@ "title": "ELV-P4-CHUNK-001", "difficulty": "Medium", "category": "ELV-P4", + "description": "[NULL] stripped the exception handling from the ID scanner. It now crashes on any non-integer input and floods the audit log with errors. Restore the three blocks — every scan must be logged, pass or fail.\n\nFill in the three snippets inside parseStudentID(String input):\n- snippet_1: Parse input as an integer. Return \"VALID:\" + the value if it is between 10000 and 99999 (inclusive), otherwise return \"INVALID:OUT_OF_RANGE\".\n- snippet_2: Return \"INVALID:NOT_A_NUMBER\" when the input cannot be parsed as an integer.\n- snippet_3: Always print \"scan attempt logged\" — this runs whether parsing succeeded or failed.\n\nInput: a string representing a student ID\nOutput: \"scan attempt logged\" on its own line, then the validation result on the next line", "templates": { "java": { "name": "Java Implementation", - "template_code": "// [NULL] stripped the exception handling from the ID scanner.\n// It now crashes on any non-integer input and floods the audit log with errors.\n// Restore the three blocks. Every scan must be logged, pass or fail.\n\npublic class CheckpointScanner {\n\n public static String parseStudentID(String input) {\n try {\n // TASK 1: Parse input. Return \"VALID:\" + id if 10000\u201399999, else \"INVALID:OUT_OF_RANGE\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:NOT_A_NUMBER\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"scan attempt logged\".\n {{{snippet_3}}}\n }\n }\n}", + "template_code": "import java.util.Scanner;\n\npublic class CheckpointScanner {\n\n public static String parseStudentID(String input) {\n try {\n // TASK 1: Parse input. Return \"VALID:\" + id if 10000–99999, else \"INVALID:OUT_OF_RANGE\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:NOT_A_NUMBER\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"scan attempt logged\".\n {{{snippet_3}}}\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String input = sc.nextLine();\n System.out.println(parseStudentID(input));\n sc.close();\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Parse the input String as an integer. If the value is in range [10000, 99999], return \"VALID:\" + that integer. Otherwise return \"INVALID:OUT_OF_RANGE\".", + "snippet_2": "Return \"INVALID:NOT_A_NUMBER\".", + "snippet_3": "Print \"scan attempt logged\" to standard output." } } }, "expectation": { "input": "12345", - "output": "VALID:12345" + "output": "scan attempt logged\nVALID:12345" } }, { "title": "ELV-P4-CHUNK-002", "difficulty": "Medium", "category": "ELV-P4", + "description": "The room code scanner is throwing unhandled exceptions on every bad input. [NULL] knew exactly which lines to delete to break the audit trail. Restore all three exception blocks.\n\nFill in the three snippets inside parseRoomCode(String input):\n- snippet_1: Parse input as an integer. Return \"ROOM:\" + the value if it is between 100 and 999 (inclusive), otherwise return \"INVALID:NOT_A_ROOM\".\n- snippet_2: Return \"INVALID:FORMAT_ERROR\" when the input cannot be parsed as an integer.\n- snippet_3: Always print \"door scan logged\" — this runs whether parsing succeeded or failed.\n\nInput: a string representing a room code\nOutput: \"door scan logged\" on its own line, then the validation result on the next line", "templates": { "java": { "name": "Java Implementation", - "template_code": "// The room code scanner is throwing unhandled exceptions on every bad input.\n// [NULL] knew exactly which lines to delete to break the audit trail.\n// Restore all three exception blocks.\n\npublic class CheckpointScanner {\n\n public static String parseRoomCode(String input) {\n try {\n // TASK 1: Parse input. Return \"ROOM:\" + code if 100\u2013999, else \"INVALID:NOT_A_ROOM\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:FORMAT_ERROR\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"door scan logged\".\n {{{snippet_3}}}\n }\n }\n}", + "template_code": "import java.util.Scanner;\n\npublic class CheckpointScanner {\n\n public static String parseRoomCode(String input) {\n try {\n // TASK 1: Parse input. Return \"ROOM:\" + code if 100–999, else \"INVALID:NOT_A_ROOM\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:FORMAT_ERROR\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"door scan logged\".\n {{{snippet_3}}}\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String input = sc.nextLine();\n System.out.println(parseRoomCode(input));\n sc.close();\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Parse the input String as an integer. If the value is in range [100, 999], return \"ROOM:\" + that integer. Otherwise return \"INVALID:NOT_A_ROOM\".", + "snippet_2": "Return \"INVALID:FORMAT_ERROR\".", + "snippet_3": "Print \"door scan logged\" to standard output." } } }, "expectation": { "input": "123", - "output": "ROOM:123" + "output": "door scan logged\nROOM:123" } }, { "title": "ELV-P4-CHUNK-003", "difficulty": "Medium", "category": "ELV-P4", + "description": "The port scanner crashes on anything that is not a clean integer. Without proper exception handling the network audit trail is blind. Restore it.\n\nFill in the three snippets inside parsePort(String input):\n- snippet_1: Parse input as an integer. Return \"PORT:\" + the value if it is between 1 and 65535 (inclusive), otherwise return \"INVALID:PORT_OUT_OF_RANGE\".\n- snippet_2: Return \"INVALID:NOT_A_PORT\" when the input cannot be parsed as an integer.\n- snippet_3: Always print \"connection attempt logged\" — this runs whether parsing succeeded or failed.\n\nInput: a string representing a port number\nOutput: \"connection attempt logged\" on its own line, then the validation result on the next line", "templates": { "java": { "name": "Java Implementation", - "template_code": "// The port scanner crashes on anything that is not a clean integer.\n// Without proper exception handling the network audit trail is blind.\n// Restore it.\n\npublic class CheckpointScanner {\n\n public static String parsePort(String input) {\n try {\n // TASK 1: Parse input. Return \"PORT:\" + number if 1\u201365535, else \"INVALID:PORT_OUT_OF_RANGE\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:NOT_A_PORT\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"connection attempt logged\".\n {{{snippet_3}}}\n }\n }\n}", + "template_code": "import java.util.Scanner;\n\npublic class CheckpointScanner {\n\n public static String parsePort(String input) {\n try {\n // TASK 1: Parse input. Return \"PORT:\" + number if 1–65535, else \"INVALID:PORT_OUT_OF_RANGE\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:NOT_A_PORT\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"connection attempt logged\".\n {{{snippet_3}}}\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String input = sc.nextLine();\n System.out.println(parsePort(input));\n sc.close();\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Parse the input String as an integer. If the value is in range [1, 65535], return \"PORT:\" + that integer. Otherwise return \"INVALID:PORT_OUT_OF_RANGE\".", + "snippet_2": "Return \"INVALID:NOT_A_PORT\".", + "snippet_3": "Print \"connection attempt logged\" to standard output." } } }, "expectation": { "input": "80", - "output": "PORT:80" + "output": "connection attempt logged\nPORT:80" } }, { "title": "ELV-P4-CHUNK-004", "difficulty": "Medium", "category": "ELV-P4", + "description": "The elevator rejects every floor request because the parser throws on bad input. [NULL] removed the safety net. Restore the exception blocks — the finally block is not optional, the lift log must always write.\n\nFill in the three snippets inside parseFloor(String input):\n- snippet_1: Parse input as an integer. Return \"FLOOR:\" + the value if it is between 1 and 10 (inclusive), otherwise return \"INVALID:NO_SUCH_FLOOR\".\n- snippet_2: Return \"INVALID:NOT_A_NUMBER\" when the input cannot be parsed as an integer.\n- snippet_3: Always print \"elevator request logged\" — this runs whether parsing succeeded or failed.\n\nInput: a string representing a floor number\nOutput: \"elevator request logged\" on its own line, then the validation result on the next line", "templates": { "java": { "name": "Java Implementation", - "template_code": "// The elevator rejects every floor request because the parser throws on bad input.\n// [NULL] removed the safety net. Restore the exception blocks.\n// The finally block is not optional \u2014 the lift log must always write.\n\npublic class CheckpointScanner {\n\n public static String parseFloor(String input) {\n try {\n // TASK 1: Parse input. Return \"FLOOR:\" + number if 1\u201310, else \"INVALID:NO_SUCH_FLOOR\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:NOT_A_NUMBER\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"elevator request logged\".\n {{{snippet_3}}}\n }\n }\n}", + "template_code": "import java.util.Scanner;\n\npublic class CheckpointScanner {\n\n public static String parseFloor(String input) {\n try {\n // TASK 1: Parse input. Return \"FLOOR:\" + number if 1–10, else \"INVALID:NO_SUCH_FLOOR\".\n {{{snippet_1}}}\n } catch (NumberFormatException e) {\n // TASK 2: Return \"INVALID:NOT_A_NUMBER\".\n {{{snippet_2}}}\n } finally {\n // TASK 3: Always print \"elevator request logged\".\n {{{snippet_3}}}\n }\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String input = sc.nextLine();\n System.out.println(parseFloor(input));\n sc.close();\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Parse the input String as an integer. If the value is in range [1, 10], return \"FLOOR:\" + that integer. Otherwise return \"INVALID:NO_SUCH_FLOOR\".", + "snippet_2": "Return \"INVALID:NOT_A_NUMBER\".", + "snippet_3": "Print \"elevator request logged\" to standard output." } } }, "expectation": { "input": "5", - "output": "FLOOR:5" + "output": "elevator request logged\nFLOOR:5" } }, { "title": "ELV-P5-CHUNK-001", "difficulty": "Medium", "category": "ELV-P5", + "description": "4,847 log entries and the threat filter is gone — [NULL] deleted it first. Without it the emergency system cannot assess severity. Find the threats — the building needs this report before it can act.\n\nFill in the three snippets inside analyzeLogs(ArrayList logs):\n- snippet_1: Declare an int counter starting at 0 and an ArrayList to collect threat descriptions.\n- snippet_2: If the current entry starts with \"THREAT:\", increment the counter and add the substring after the first 8 characters to the description list.\n- snippet_3: Return \"THREATS:0|none\" if the counter is 0, otherwise return \"THREATS:\" + count + \"|\" + descriptions joined by \",\".", "templates": { "java": { "name": "Java Implementation", - "template_code": "// 4,847 log entries. The threat filter is gone \u2014 [NULL] deleted it first.\n// Without it the emergency system cannot assess severity.\n// Find the threats. The building needs this report before it can act.\n\nimport java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String analyzeLogs(ArrayList logs) {\n\n // TASK 1: Declare a counter and an ArrayList for threat descriptions.\n {{{snippet_1}}}\n\n for (String entry : logs) {\n // TASK 2: If entry starts with \"THREAT:\", increment and collect the description (after 8 chars).\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"THREATS:0|none\" if clean, else \"THREATS:\" + count + \"|\" + descriptions joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList logs1 = new ArrayList<>();\n logs1.add(\"INFO: door opened\");\n logs1.add(\"THREAT: brute force\");\n logs1.add(\"INFO: scan ok\");\n logs1.add(\"THREAT: port scan\");\n logs1.add(\"THREAT: login fail\");\n System.out.println(analyzeLogs(logs1));\n\n ArrayList logs2 = new ArrayList<>();\n logs2.add(\"INFO: all clear\");\n System.out.println(analyzeLogs(logs2));\n }\n}", + "template_code": "import java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String analyzeLogs(ArrayList logs) {\n\n // TASK 1: Declare a counter and an ArrayList for threat descriptions.\n {{{snippet_1}}}\n\n for (String entry : logs) {\n // TASK 2: If entry starts with \"THREAT:\", increment and collect the description (after 8 chars).\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"THREATS:0|none\" if clean, else \"THREATS:\" + count + \"|\" + descriptions joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList logs1 = new ArrayList<>();\n logs1.add(\"INFO: door opened\");\n logs1.add(\"THREAT: brute force\");\n logs1.add(\"INFO: scan ok\");\n logs1.add(\"THREAT: port scan\");\n logs1.add(\"THREAT: login fail\");\n System.out.println(analyzeLogs(logs1));\n\n ArrayList logs2 = new ArrayList<>();\n logs2.add(\"INFO: all clear\");\n System.out.println(analyzeLogs(logs2));\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Declare: int count = 0; and ArrayList threats = new ArrayList<>();", + "snippet_2": "Check if entry starts with \"THREAT:\". If so, increment count and add entry.substring(8) to threats.", + "snippet_3": "If count == 0 return \"THREATS:0|none\", else return \"THREATS:\" + count + \"|\" + String.join(\",\", threats)." } } }, "expectation": { "input": "", - "output": "" + "output": "THREATS:3|brute force,port scan,login fail\nTHREATS:0|none" } }, { "title": "ELV-P5-CHUNK-002", "difficulty": "Medium", "category": "ELV-P5", + "description": "The server error filter was wiped along with the intrusion logs. Critical errors are invisible to the monitoring system. Restore the filter — find every ERROR entry and report the count.\n\nFill in the three snippets inside filterErrors(ArrayList logs):\n- snippet_1: Declare an int counter starting at 0 and an ArrayList to collect error messages.\n- snippet_2: If the current entry starts with \"ERROR:\", increment the counter and add the substring after the first 7 characters to the message list.\n- snippet_3: Return \"ERRORS:0|none\" if the counter is 0, otherwise return \"ERRORS:\" + count + \"|\" + messages joined by \",\".", "templates": { "java": { "name": "Java Implementation", - "template_code": "// The server error filter was wiped along with the intrusion logs.\n// Critical errors are invisible to the monitoring system.\n// Restore the filter \u2014 find every ERROR entry and report the count.\n\nimport java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String filterErrors(ArrayList logs) {\n\n // TASK 1: Declare a counter and an ArrayList for error messages.\n {{{snippet_1}}}\n\n for (String entry : logs) {\n // TASK 2: If entry starts with \"ERROR:\", increment and collect the message (after 7 chars).\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"ERRORS:0|none\" if clean, else \"ERRORS:\" + count + \"|\" + messages joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList logs1 = new ArrayList<>();\n logs1.add(\"INFO: server started\");\n logs1.add(\"ERROR: disk full\");\n logs1.add(\"ERROR: null pointer\");\n logs1.add(\"INFO: backup ok\");\n System.out.println(filterErrors(logs1));\n\n ArrayList logs2 = new ArrayList<>();\n logs2.add(\"INFO: running\");\n System.out.println(filterErrors(logs2));\n }\n}", + "template_code": "import java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String filterErrors(ArrayList logs) {\n\n // TASK 1: Declare a counter and an ArrayList for error messages.\n {{{snippet_1}}}\n\n for (String entry : logs) {\n // TASK 2: If entry starts with \"ERROR:\", increment and collect the message (after 7 chars).\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"ERRORS:0|none\" if clean, else \"ERRORS:\" + count + \"|\" + messages joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList logs1 = new ArrayList<>();\n logs1.add(\"INFO: server started\");\n logs1.add(\"ERROR: disk full\");\n logs1.add(\"ERROR: null pointer\");\n logs1.add(\"INFO: backup ok\");\n System.out.println(filterErrors(logs1));\n\n ArrayList logs2 = new ArrayList<>();\n logs2.add(\"INFO: running\");\n System.out.println(filterErrors(logs2));\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Declare: int count = 0; and ArrayList errors = new ArrayList<>();", + "snippet_2": "Check if entry starts with \"ERROR:\". If so, increment count and add entry.substring(7) to errors.", + "snippet_3": "If count == 0 return \"ERRORS:0|none\", else return \"ERRORS:\" + count + \"|\" + String.join(\",\", errors)." } } }, "expectation": { "input": "", - "output": "" + "output": "ERRORS:2|disk full,null pointer\nERRORS:0|none" } }, { "title": "ELV-P5-CHUNK-003", "difficulty": "Medium", "category": "ELV-P5", + "description": "The badge access log is full of denied entries — someone was probing every door. The scanner that should have flagged them is offline. Find every DENIED entry before [NULL] makes another move.\n\nFill in the three snippets inside findDenied(ArrayList entries):\n- snippet_1: Declare an int counter starting at 0 and an ArrayList to collect denied entries.\n- snippet_2: If the current entry contains the word \"DENIED\" anywhere, increment the counter and add the full entry to the list.\n- snippet_3: Return \"DENIED:0|none\" if the counter is 0, otherwise return \"DENIED:\" + count + \"|\" + entries joined by \",\".", "templates": { "java": { "name": "Java Implementation", - "template_code": "// The badge access log is full of denied entries \u2014 someone was probing every door.\n// The scanner that should have flagged them is offline.\n// Find every DENIED entry before [NULL] makes another move.\n\nimport java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String findDenied(ArrayList entries) {\n\n // TASK 1: Declare a counter and an ArrayList for denied entries.\n {{{snippet_1}}}\n\n for (String entry : entries) {\n // TASK 2: If entry contains \"DENIED\" anywhere, increment and collect the full entry.\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"DENIED:0|none\" if none, else \"DENIED:\" + count + \"|\" + entries joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList e1 = new ArrayList<>();\n e1.add(\"Student 001: GRANTED\");\n e1.add(\"Student 002: DENIED low clearance\");\n e1.add(\"Student 003: GRANTED\");\n e1.add(\"Visitor 01: DENIED no badge\");\n System.out.println(findDenied(e1));\n\n ArrayList e2 = new ArrayList<>();\n e2.add(\"Staff 001: GRANTED\");\n System.out.println(findDenied(e2));\n }\n}", + "template_code": "import java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String findDenied(ArrayList entries) {\n\n // TASK 1: Declare a counter and an ArrayList for denied entries.\n {{{snippet_1}}}\n\n for (String entry : entries) {\n // TASK 2: If entry contains \"DENIED\" anywhere, increment and collect the full entry.\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"DENIED:0|none\" if none, else \"DENIED:\" + count + \"|\" + entries joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList e1 = new ArrayList<>();\n e1.add(\"Student 001: GRANTED\");\n e1.add(\"Student 002: DENIED low clearance\");\n e1.add(\"Student 003: GRANTED\");\n e1.add(\"Visitor 01: DENIED no badge\");\n System.out.println(findDenied(e1));\n\n ArrayList e2 = new ArrayList<>();\n e2.add(\"Staff 001: GRANTED\");\n System.out.println(findDenied(e2));\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Declare: int count = 0; and ArrayList denied = new ArrayList<>();", + "snippet_2": "Check if entry contains \"DENIED\". If so, increment count and add the full entry to denied.", + "snippet_3": "If count == 0 return \"DENIED:0|none\", else return \"DENIED:\" + count + \"|\" + String.join(\",\", denied)." } } }, "expectation": { "input": "", - "output": "" + "output": "DENIED:2|Student 002: DENIED low clearance,Visitor 01: DENIED no badge\nDENIED:0|none" } }, { "title": "ELV-P5-CHUNK-004", "difficulty": "Medium", "category": "ELV-P5", + "description": "Elevator requests are piling up but the floor filter is down. Security needs to know exactly how many calls are going to each floor. Restore the filter — match by floor number and report the count.\n\nFill in the three snippets inside findFloorRequests(ArrayList logs, int floor):\n- snippet_1: Declare an int counter starting at 0 and an ArrayList to collect matching requests.\n- snippet_2: If the current entry ends with \":\" + floor, increment the counter and add the full entry to the list.\n- snippet_3: Return \"FLOOR\" + floor + \":0|none\" if the counter is 0, otherwise return \"FLOOR\" + floor + \":\" + count + \"|\" + entries joined by \",\".", "templates": { "java": { "name": "Java Implementation", - "template_code": "// Elevator requests are piling up but the floor filter is down.\n// Security needs to know exactly how many calls are going to each floor.\n// Restore the filter \u2014 match by floor number, report the count.\n\nimport java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String findFloorRequests(ArrayList logs, int floor) {\n\n // TASK 1: Declare a counter and an ArrayList for matching requests.\n {{{snippet_1}}}\n\n for (String entry : logs) {\n // TASK 2: If entry ends with \":\" + floor, increment and collect the full entry.\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"FLOOR\" + floor + \":0|none\" if none,\n // else \"FLOOR\" + floor + \":\" + count + \"|\" + entries joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList logs = new ArrayList<>();\n logs.add(\"User A requested floor:2\");\n logs.add(\"User B requested floor:3\");\n logs.add(\"User C requested floor:2\");\n logs.add(\"User D requested floor:1\");\n System.out.println(findFloorRequests(logs, 2));\n System.out.println(findFloorRequests(logs, 5));\n }\n}", + "template_code": "import java.util.ArrayList;\n\npublic class ThreatAnalyser {\n\n public static String findFloorRequests(ArrayList logs, int floor) {\n\n // TASK 1: Declare a counter and an ArrayList for matching requests.\n {{{snippet_1}}}\n\n for (String entry : logs) {\n // TASK 2: If entry ends with \":\" + floor, increment and collect the full entry.\n {{{snippet_2}}}\n }\n\n // TASK 3: Return \"FLOOR\" + floor + \":0|none\" if none,\n // else \"FLOOR\" + floor + \":\" + count + \"|\" + entries joined by \",\".\n {{{snippet_3}}}\n }\n\n public static void main(String[] args) {\n ArrayList logs = new ArrayList<>();\n logs.add(\"User A requested floor:2\");\n logs.add(\"User B requested floor:3\");\n logs.add(\"User C requested floor:2\");\n logs.add(\"User D requested floor:1\");\n System.out.println(findFloorRequests(logs, 2));\n System.out.println(findFloorRequests(logs, 5));\n }\n}", "snippets": { - "snippet_1": "None to be shown here", - "snippet_2": "None to be shown here", - "snippet_3": "None to be shown here" + "snippet_1": "Declare: int count = 0; and ArrayList matches = new ArrayList<>();", + "snippet_2": "Check if entry ends with \":\" + floor. If so, increment count and add the full entry to matches.", + "snippet_3": "If count == 0 return \"FLOOR\" + floor + \":0|none\", else return \"FLOOR\" + floor + \":\" + count + \"|\" + String.join(\",\", matches)." } } }, "expectation": { "input": "", - "output": "" + "output": "FLOOR2:2|User A requested floor:2,User C requested floor:2\nFLOOR5:0|none" } } -] \ No newline at end of file +] diff --git a/src/scripts/data/java/elevatorhall/problems.json b/src/scripts/data/java/elevatorhall/problems.json index 3bb04e4..14ad83a 100644 --- a/src/scripts/data/java/elevatorhall/problems.json +++ b/src/scripts/data/java/elevatorhall/problems.json @@ -1,11 +1,11 @@ [ { "title": "ELV-P1-PROB-001", - "description": "// [NULL] destroyed the auth daemon's recursive checksum.\n// Without a base case, every badge scan crashes the stack.\n// Restore it. The first fragment unlocks when it runs clean.\n", + "description": "[NULL] destroyed the auth daemon's recursive checksum. Without a base case, every badge scan crashes the stack. Restore it before the first fragment is lost.\n\nImplement hashPassword(String s) that recursively sums the ASCII value of every character in s. An empty string must return 0.\n\nInput: a single string\nOutput: the sum of ASCII values of all characters", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "public class AuthDaemon {\npublic static int hashPassword(String s) {\n// Recursively sum the ASCII value of each character.\n//Player code goes here\n}\n\n public static void main(String[] args) {\n\t Scanner sc = new Scanner(System.in);\n\t String str = sc.nextLine();\n System.out.println(hashPassword(str));\n sc.close();\n }\n}" + "java": "import java.util.Scanner;\n\npublic class AuthDaemon {\n public static int hashPassword(String s) {\n // Recursively sum the ASCII value of each character.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n System.out.println(hashPassword(str));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -27,11 +27,11 @@ }, { "title": "ELV-P1-PROB-002", - "description": "// The badge scanner counts security characters in access codes recursively.\n// [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\n", + "description": "The badge scanner counts security characters in access codes recursively. [NULL] gutted the logic. Restore it before the auth layer rejects every card.\n\nImplement countChar(String s, char target) that recursively counts how many times target appears in s. Return 0 if s is empty or target is not found.\n\nInput: first line is a string, second line is a single character\nOutput: the number of times the character appears in the string", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static int countChar(String s, char target) {\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n char c = sc.next().charAt(0);\n System.out.println(countChar(str,c));\n sc.close();\n }\n}" + "java": "import java.util.Scanner;\n\npublic class AuthDaemon {\n public static int countChar(String s, char target) {\n // Recursively count how many times target appears in s.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n char c = sc.next().charAt(0);\n System.out.println(countChar(str, c));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -58,11 +58,11 @@ }, { "title": "ELV-P1-PROB-003", - "description": "[NULL] reversed every exit label in the CCTV registry to cover their tracks.\n// This recursive function reverses them back. It is broken. Fix it.\n", + "description": "[NULL] reversed every exit label in the CCTV registry to cover their tracks. This recursive function reverses them back. It is broken. Fix it.\n\nImplement reverseCode(String s) that recursively reverses the given string. An empty string should return an empty string.\n\nInput: a single string\nOutput: the string with all characters in reverse order", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n // player code goes here\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n System.out.println(reverseCode(str));\n sc.close();\n }\n}" + "java": "import java.util.Scanner;\n\npublic class AuthDaemon {\n public static String reverseCode(String s) {\n // Recursively reverse the string.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String str = sc.nextLine();\n System.out.println(reverseCode(str));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -84,11 +84,11 @@ }, { "title": "ELV-P1-PROB-004", - "description": "// Floor access codes are validated by a recursive digit checksum.\n// The module is down. Restore it before the elevator rejects every request.", + "description": "Floor access codes are validated by a recursive digit checksum. The module is down. Restore it before the elevator rejects every request.\n\nImplement sumDigits(int n) that recursively sums each digit of n. For example, sumDigits(4821) returns 4+8+2+1 = 15. Handle n = 0 by returning 0.\n\nInput: a non-negative integer\nOutput: the sum of its digits", "difficulty": "Hard", "category": "ELV-P1", "templates": { - "java": "import java.util.Scanner;\npublic class AuthDaemon {\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n // player code goes here \n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int num = sc.nextInt();\n System.out.println(sumDigits(num));\n sc.close();\n }\n}" + "java": "import java.util.Scanner;\n\npublic class AuthDaemon {\n public static int sumDigits(int n) {\n // Recursively sum each digit of n.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int num = sc.nextInt();\n System.out.println(sumDigits(num));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -110,11 +110,11 @@ }, { "title": "ELV-P2-PROB-001", - "description": "The corridor heat sensor grid feeds into this machine.\n[NULL] broke the scan function so it never flags anomalies.\nRestore it, the security relay needs a clean threat report.", + "description": "The corridor heat sensor grid feeds into this machine. [NULL] broke the scan function so it never flags anomalies. Restore it — the security relay needs a clean threat report.\n\nImplement findHotCells(int[][] grid) that scans every cell and returns a comma-separated list of \"[row,col]=value\" for every cell with a value strictly greater than 80. Return \"none\" if no cell exceeds the threshold.\n\nInput: first line contains rows and cols, followed by grid values row by row\nOutput: flagged cells as \"[row,col]=value\" joined by \", \", or \"none\"", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "import java.util.ArrayList;\nimport java.util.Scanner;\npublic class GridScanner {\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n // player code goes here\n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] grid = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n grid[i][j] = sc.nextInt();\n System.out.println(findHotCells(grid));\n sc.close();\n }\n}" + "java": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class GridScanner {\n public static String findHotCells(int[][] grid) {\n ArrayList hits = new ArrayList<>();\n // Scan every cell. Flag readings above 80 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if the grid is clean.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] grid = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n grid[i][j] = sc.nextInt();\n System.out.println(findHotCells(grid));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -141,11 +141,11 @@ }, { "title": "ELV-P2-PROB-002", - "description": "[NULL] is hiding in wireless dead zones to avoid detection.\nThe signal map is a grid, find every cell below strength 10.\nExpose the dead zones and the relay comes back online.", + "description": "[NULL] is hiding in wireless dead zones to avoid detection. The signal map is a grid — find every cell with signal strength strictly below 10. Expose the dead zones and the relay comes back online.\n\nImplement findDeadZones(int[][] signal) that returns a comma-separated list of \"[row,col]=value\" for every cell with signal strength strictly less than 10. Return \"none\" if coverage is full.\n\nInput: first line contains rows and cols, followed by signal strength values row by row\nOutput: dead zone cells as \"[row,col]=value\" joined by \", \", or \"none\"", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "import java.util.ArrayList;\nimport java.util.Scanner;\npublic class GridScanner {\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n // player code goes here \n }\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] signal = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n signal[i][j] = sc.nextInt();\n System.out.println(findDeadZones(signal));\n sc.close();\n }\n}" + "java": "import java.util.ArrayList;\nimport java.util.Scanner;\n\npublic class GridScanner {\n public static String findDeadZones(int[][] signal) {\n ArrayList hits = new ArrayList<>();\n // Flag every cell where signal strength is strictly below 10 as \"[row,col]=value\".\n // Return hits joined by \", \" or \"none\" if coverage is full.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] signal = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n signal[i][j] = sc.nextInt();\n System.out.println(findDeadZones(signal));\n sc.close();\n }\n}" }, "test_cases": [ { @@ -172,53 +172,68 @@ }, { "title": "ELV-P2-PROB-003", - "description": "Security needs a headcount to confirm the building is clear.\nThe attendance grid uses 1 for present, 0 for absent.\nCount the occupied cells and report the total.\n", + "description": "Security needs a headcount to confirm the building is clear. The attendance grid uses 1 for present and 0 for absent. Count the occupied cells and report the total.\n\nImplement countPresent(int[][] attendance) that counts every cell equal to 1 and returns the total count.\n\nInput: first line contains rows and cols, followed by attendance values (0 or 1) row by row\nOutput: total number of cells with value 1", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] a = {\n {1, 0, 1, 1},\n {0, 0, 1, 0},\n {1, 1, 0, 1}\n };\n System.out.println(countPresent(a));\n\n int[][] b = {{0, 0}, {0, 0}};\n System.out.println(countPresent(b));\n }\n}" + "java": "import java.util.Scanner;\n\npublic class GridScanner {\n public static int countPresent(int[][] attendance) {\n // Count every cell equal to 1 and return the total.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] attendance = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n attendance[i][j] = sc.nextInt();\n System.out.println(countPresent(attendance));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "3 4\n1 0 1 1\n0 0 1 0\n1 1 0 1", "output": "6", "is_hidden": false }, { - "input": "", + "input": "2 2\n0 0\n0 0", "output": "0", "is_hidden": true + }, + { + "input": "1 1\n1", + "output": "1", + "is_hidden": true + }, + { + "input": "2 3\n1 1 1\n1 1 1", + "output": "6", + "is_hidden": true } ] }, { "title": "ELV-P2-PROB-004", - "description": "One server rack is running [NULL]'s process and overheating the room.\nFind the single hottest cell in the thermal grid.\nReturn its location and temperature, then we know where to cut power.\n", + "description": "One server rack is running [NULL]'s process and overheating the room. Find the single hottest cell in the thermal grid. Return its location and temperature so we know where to cut power.\n\nImplement findHotspot(int[][] temps) that finds the cell with the maximum value and returns it as \"[row,col]=value\". If multiple cells share the maximum, return the first one found (scanning top to bottom, left to right).\n\nInput: first line contains rows and cols, followed by temperature values row by row\nOutput: hottest cell in format \"[row,col]=value\"", "difficulty": "Hard", "category": "ELV-P2", "templates": { - "java": "import java.util.ArrayList;\n\npublic class GridScanner {\n\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[][] t = {\n {40, 72, 55},\n {88, 61, 47},\n {33, 95, 70}\n };\n System.out.println(findHotspot(t));\n\n int[][] t2 = {{10, 20}, {30, 25}};\n System.out.println(findHotspot(t2));\n }\n}" + "java": "import java.util.Scanner;\n\npublic class GridScanner {\n public static String findHotspot(int[][] temps) {\n // Find the cell with the maximum value. Return \"[row,col]=value\".\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int rows = sc.nextInt();\n int cols = sc.nextInt();\n int[][] temps = new int[rows][cols];\n for (int i = 0; i < rows; i++)\n for (int j = 0; j < cols; j++)\n temps[i][j] = sc.nextInt();\n System.out.println(findHotspot(temps));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "3 3\n40 72 55\n88 61 47\n33 95 70", "output": "[2,1]=95", "is_hidden": false }, { - "input": "", + "input": "2 2\n10 20\n30 25", "output": "[1,0]=30", "is_hidden": true + }, + { + "input": "1 1\n42", + "output": "[0,0]=42", + "is_hidden": true } ] }, { "title": "ELV-P3-PROB-001", - "description": "[NULL] wiped both card subclasses from the clearance system.\nEvery card now returns UNKNOWN and every door stays locked.\nThe base class survived. Restore both card types from scratch.\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}", + "description": "[NULL] wiped both card subclasses from the clearance system. Every card now returns UNKNOWN and every door stays locked. The base class AccessCard survived — restore both card types from scratch.\n\nWrite two inner static classes inside ClearanceManager:\n- StudentCard extends AccessCard. Its constructor takes only a name. Access level is always 1. Its identify() returns the parent result with \" [STUDENT]\" appended.\n- StaffCard extends AccessCard. Its constructor takes only a name. Access level is always 5. Its identify() returns the parent result with \" [STAFF]\" appended.", "difficulty": "Hard", "category": "ELV-P3", "templates": { - "java": "import java.util.ArrayList;\n\npublic class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}" + "java": "public class ClearanceManager {\n\n static class AccessCard {\n protected String ownerName;\n protected int accessLevel;\n public AccessCard(String name, int level) {\n this.ownerName = name;\n this.accessLevel = level;\n }\n public String identify() {\n return \"CARD[\" + ownerName + \"] Level:\" + accessLevel;\n }\n }\n\n // TASK 1: StudentCard extends AccessCard. Level always 1. Appends \" [STUDENT]\".\n {TASK 1: STUDENT CARD}\n\n // TASK 2: StaffCard extends AccessCard. Level always 5. Appends \" [STAFF]\".\n {TASK 2: STAFF CARD}\n\n public static void main(String[] args) {\n AccessCard s = new StudentCard(\"Azri\");\n AccessCard t = new StaffCard(\"Dr.Lim\");\n System.out.println(s.identify());\n System.out.println(t.identify());\n System.out.println(s.accessLevel);\n System.out.println(t.accessLevel);\n }\n}" }, "test_cases": [ { @@ -245,11 +260,11 @@ }, { "title": "ELV-P3-PROB-002", - "description": "// The alert system cannot classify severity anymore \u2014 [NULL] deleted the subclasses.\n// Minor and critical alerts both come back blank. Restore both types.\n\npublic class ClearanceManager {\n\n static class SystemAlert {\n protected String message;\n protected int severity;\n public SystemAlert(String message, int severity) {\n this.message = message;\n this.severity = severity;\n }\n public String describe() {\n return \"ALERT[\" + message + \"] Sev:\" + severity;\n }\n }\n\n // TASK 1: MinorAlert extends SystemAlert. Severity always 1. Appends \" [MINOR]\".\n {TASK 1: MINOR ALERT}\n\n // TASK 2: CriticalAlert extends SystemAlert. Severity always 9. Appends \" [CRITICAL]\".\n {TASK 2: CRITICAL ALERT}\n\n public static void main(String[] args) {\n SystemAlert a = new MinorAlert(\"door left open\");\n SystemAlert b = new CriticalAlert(\"server breach\");\n System.out.println(a.describe());\n System.out.println(b.describe());\n System.out.println(a.severity);\n System.out.println(b.severity);\n }\n}", + "description": "The alert system cannot classify severity anymore — [NULL] deleted the subclasses. Minor and critical alerts both come back blank. Restore both types.\n\nWrite two inner static classes inside ClearanceManager:\n- MinorAlert extends SystemAlert. Its constructor takes only a message. Severity is always 1. Its describe() returns the parent result with \" [MINOR]\" appended.\n- CriticalAlert extends SystemAlert. Its constructor takes only a message. Severity is always 9. Its describe() returns the parent result with \" [CRITICAL]\" appended.", "difficulty": "Hard", "category": "ELV-P3", "templates": { - "java": "// The alert system cannot classify severity anymore \u2014 [NULL] deleted the subclasses.\n// Minor and critical alerts both come back blank. Restore both types.\n\npublic class ClearanceManager {\n\n static class SystemAlert {\n protected String message;\n protected int severity;\n public SystemAlert(String message, int severity) {\n this.message = message;\n this.severity = severity;\n }\n public String describe() {\n return \"ALERT[\" + message + \"] Sev:\" + severity;\n }\n }\n\n // TASK 1: MinorAlert extends SystemAlert. Severity always 1. Appends \" [MINOR]\".\n {TASK 1: MINOR ALERT}\n\n // TASK 2: CriticalAlert extends SystemAlert. Severity always 9. Appends \" [CRITICAL]\".\n {TASK 2: CRITICAL ALERT}\n\n public static void main(String[] args) {\n SystemAlert a = new MinorAlert(\"door left open\");\n SystemAlert b = new CriticalAlert(\"server breach\");\n System.out.println(a.describe());\n System.out.println(b.describe());\n System.out.println(a.severity);\n System.out.println(b.severity);\n }\n}" + "java": "public class ClearanceManager {\n\n static class SystemAlert {\n protected String message;\n protected int severity;\n public SystemAlert(String message, int severity) {\n this.message = message;\n this.severity = severity;\n }\n public String describe() {\n return \"ALERT[\" + message + \"] Sev:\" + severity;\n }\n }\n\n // TASK 1: MinorAlert extends SystemAlert. Severity always 1. Appends \" [MINOR]\".\n {TASK 1: MINOR ALERT}\n\n // TASK 2: CriticalAlert extends SystemAlert. Severity always 9. Appends \" [CRITICAL]\".\n {TASK 2: CRITICAL ALERT}\n\n public static void main(String[] args) {\n SystemAlert a = new MinorAlert(\"door left open\");\n SystemAlert b = new CriticalAlert(\"server breach\");\n System.out.println(a.describe());\n System.out.println(b.describe());\n System.out.println(a.severity);\n System.out.println(b.severity);\n }\n}" }, "test_cases": [ { @@ -276,11 +291,11 @@ }, { "title": "ELV-P3-PROB-003", - "description": "// The network device registry lost both its concrete types.\n// Wired and wireless devices both report as unknown hardware.\n// Restore them so the building network can come back online.\n\npublic class ClearanceManager {\n\n static class NetworkDevice {\n protected String id;\n protected int bandwidth;\n public NetworkDevice(String id, int bandwidth) {\n this.id = id;\n this.bandwidth = bandwidth;\n }\n public String report() {\n return \"DEV[\" + id + \"] BW:\" + bandwidth;\n }\n }\n\n // TASK 1: WiredDevice extends NetworkDevice. Bandwidth always 1000. Appends \" [WIRED]\".\n {TASK 1: WIRED DEVICE}\n\n // TASK 2: WirelessDevice extends NetworkDevice. Bandwidth always 300. Appends \" [WIRELESS]\".\n {TASK 2: WIRELESS DEVICE}\n\n public static void main(String[] args) {\n NetworkDevice w = new WiredDevice(\"ETH-01\");\n NetworkDevice x = new WirelessDevice(\"WIFI-02\");\n System.out.println(w.report());\n System.out.println(x.report());\n System.out.println(w.bandwidth);\n System.out.println(x.bandwidth);\n }\n}", + "description": "The network device registry lost both its concrete types. Wired and wireless devices both report as unknown hardware. Restore them so the building network can come back online.\n\nWrite two inner static classes inside ClearanceManager:\n- WiredDevice extends NetworkDevice. Its constructor takes only an id. Bandwidth is always 1000. Its report() returns the parent result with \" [WIRED]\" appended.\n- WirelessDevice extends NetworkDevice. Its constructor takes only an id. Bandwidth is always 300. Its report() returns the parent result with \" [WIRELESS]\" appended.", "difficulty": "Hard", "category": "ELV-P3", "templates": { - "java": "// The network device registry lost both its concrete types.\n// Wired and wireless devices both report as unknown hardware.\n// Restore them so the building network can come back online.\n\npublic class ClearanceManager {\n\n static class NetworkDevice {\n protected String id;\n protected int bandwidth;\n public NetworkDevice(String id, int bandwidth) {\n this.id = id;\n this.bandwidth = bandwidth;\n }\n public String report() {\n return \"DEV[\" + id + \"] BW:\" + bandwidth;\n }\n }\n\n // TASK 1: WiredDevice extends NetworkDevice. Bandwidth always 1000. Appends \" [WIRED]\".\n {TASK 1: WIRED DEVICE}\n\n // TASK 2: WirelessDevice extends NetworkDevice. Bandwidth always 300. Appends \" [WIRELESS]\".\n {TASK 2: WIRELESS DEVICE}\n\n public static void main(String[] args) {\n NetworkDevice w = new WiredDevice(\"ETH-01\");\n NetworkDevice x = new WirelessDevice(\"WIFI-02\");\n System.out.println(w.report());\n System.out.println(x.report());\n System.out.println(w.bandwidth);\n System.out.println(x.bandwidth);\n }\n}" + "java": "public class ClearanceManager {\n\n static class NetworkDevice {\n protected String id;\n protected int bandwidth;\n public NetworkDevice(String id, int bandwidth) {\n this.id = id;\n this.bandwidth = bandwidth;\n }\n public String report() {\n return \"DEV[\" + id + \"] BW:\" + bandwidth;\n }\n }\n\n // TASK 1: WiredDevice extends NetworkDevice. Bandwidth always 1000. Appends \" [WIRED]\".\n {TASK 1: WIRED DEVICE}\n\n // TASK 2: WirelessDevice extends NetworkDevice. Bandwidth always 300. Appends \" [WIRELESS]\".\n {TASK 2: WIRELESS DEVICE}\n\n public static void main(String[] args) {\n NetworkDevice w = new WiredDevice(\"ETH-01\");\n NetworkDevice x = new WirelessDevice(\"WIFI-02\");\n System.out.println(w.report());\n System.out.println(x.report());\n System.out.println(w.bandwidth);\n System.out.println(x.bandwidth);\n }\n}" }, "test_cases": [ { @@ -307,11 +322,11 @@ }, { "title": "ELV-P3-PROB-004", - "description": "// Lab equipment tagging is broken \u2014 safe and hazardous items look identical.\n// [NULL] deleted both subclasses. One wrong label and the evacuation fails.\n// Restore them.\n\npublic class ClearanceManager {\n\n static class LabItem {\n protected String code;\n protected int riskLevel;\n public LabItem(String code, int riskLevel) {\n this.code = code;\n this.riskLevel = riskLevel;\n }\n public String label() {\n return \"ITEM[\" + code + \"] Risk:\" + riskLevel;\n }\n }\n\n // TASK 1: SafeEquipment extends LabItem. RiskLevel always 1. Appends \" [SAFE]\".\n {TASK 1: SAFE EQUIPMENT}\n\n // TASK 2: HazardEquipment extends LabItem. RiskLevel always 5. Appends \" [HAZARD]\".\n {TASK 2: HAZARD EQUIPMENT}\n\n public static void main(String[] args) {\n LabItem s = new SafeEquipment(\"CHAIR-04\");\n LabItem h = new HazardEquipment(\"LASER-09\");\n System.out.println(s.label());\n System.out.println(h.label());\n System.out.println(s.riskLevel);\n System.out.println(h.riskLevel);\n }\n}", + "description": "Lab equipment tagging is broken — safe and hazardous items look identical. [NULL] deleted both subclasses. One wrong label and the evacuation fails. Restore them.\n\nWrite two inner static classes inside ClearanceManager:\n- SafeEquipment extends LabItem. Its constructor takes only a code. Risk level is always 1. Its label() returns the parent result with \" [SAFE]\" appended.\n- HazardEquipment extends LabItem. Its constructor takes only a code. Risk level is always 5. Its label() returns the parent result with \" [HAZARD]\" appended.", "difficulty": "Hard", "category": "ELV-P3", "templates": { - "java": "// Lab equipment tagging is broken \u2014 safe and hazardous items look identical.\n// [NULL] deleted both subclasses. One wrong label and the evacuation fails.\n// Restore them.\n\npublic class ClearanceManager {\n\n static class LabItem {\n protected String code;\n protected int riskLevel;\n public LabItem(String code, int riskLevel) {\n this.code = code;\n this.riskLevel = riskLevel;\n }\n public String label() {\n return \"ITEM[\" + code + \"] Risk:\" + riskLevel;\n }\n }\n\n // TASK 1: SafeEquipment extends LabItem. RiskLevel always 1. Appends \" [SAFE]\".\n {TASK 1: SAFE EQUIPMENT}\n\n // TASK 2: HazardEquipment extends LabItem. RiskLevel always 5. Appends \" [HAZARD]\".\n {TASK 2: HAZARD EQUIPMENT}\n\n public static void main(String[] args) {\n LabItem s = new SafeEquipment(\"CHAIR-04\");\n LabItem h = new HazardEquipment(\"LASER-09\");\n System.out.println(s.label());\n System.out.println(h.label());\n System.out.println(s.riskLevel);\n System.out.println(h.riskLevel);\n }\n}" + "java": "public class ClearanceManager {\n\n static class LabItem {\n protected String code;\n protected int riskLevel;\n public LabItem(String code, int riskLevel) {\n this.code = code;\n this.riskLevel = riskLevel;\n }\n public String label() {\n return \"ITEM[\" + code + \"] Risk:\" + riskLevel;\n }\n }\n\n // TASK 1: SafeEquipment extends LabItem. RiskLevel always 1. Appends \" [SAFE]\".\n {TASK 1: SAFE EQUIPMENT}\n\n // TASK 2: HazardEquipment extends LabItem. RiskLevel always 5. Appends \" [HAZARD]\".\n {TASK 2: HAZARD EQUIPMENT}\n\n public static void main(String[] args) {\n LabItem s = new SafeEquipment(\"CHAIR-04\");\n LabItem h = new HazardEquipment(\"LASER-09\");\n System.out.println(s.label());\n System.out.println(h.label());\n System.out.println(s.riskLevel);\n System.out.println(h.riskLevel);\n }\n}" }, "test_cases": [ { @@ -338,25 +353,25 @@ }, { "title": "ELV-P6-PROB-001", - "description": "// The elevator queue manager is down \u2014 [NULL] wiped the sort logic.\n// The lift now skips floors at random. You are one floor from the exit.\n// Sort the queue manually. Get it moving in the right order.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static void sortFloors(int[] floors) {\n int n = floors.length;\n // Sort floors ascending in place. No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[] a = {4, 1, 3, 2, 5};\n sortFloors(a);\n System.out.println(Arrays.toString(a));\n\n int[] b = {9, 2, 7, 1};\n sortFloors(b);\n System.out.println(Arrays.toString(b));\n\n int[] c = {3, 3, 1};\n sortFloors(c);\n System.out.println(Arrays.toString(c));\n }\n}", + "description": "The elevator queue manager is down — [NULL] wiped the sort logic. The lift now skips floors at random. You are one floor from the exit. Sort the queue manually and get it moving in the right order.\n\nImplement sortFloors(int[] floors) that sorts the array in ascending order in place. You may NOT use Arrays.sort() or any library sort method — write the sorting algorithm yourself.\n\nInput: first line is n (number of floors), second line is n space-separated floor numbers\nOutput: sorted array in Arrays.toString() format, e.g. [1, 2, 3, 4, 5]", "difficulty": "Hard", "category": "ELV-P6", "templates": { - "java": "// The elevator queue manager is down \u2014 [NULL] wiped the sort logic.\n// The lift now skips floors at random. You are one floor from the exit.\n// Sort the queue manually. Get it moving in the right order.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static void sortFloors(int[] floors) {\n int n = floors.length;\n // Sort floors ascending in place. No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[] a = {4, 1, 3, 2, 5};\n sortFloors(a);\n System.out.println(Arrays.toString(a));\n\n int[] b = {9, 2, 7, 1};\n sortFloors(b);\n System.out.println(Arrays.toString(b));\n\n int[] c = {3, 3, 1};\n sortFloors(c);\n System.out.println(Arrays.toString(c));\n }\n}" + "java": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ElevatorQueue {\n\n public static void sortFloors(int[] floors) {\n int n = floors.length;\n // Sort floors ascending in place. No Arrays.sort() or library sort allowed.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] floors = new int[n];\n for (int i = 0; i < n; i++) floors[i] = sc.nextInt();\n sortFloors(floors);\n System.out.println(Arrays.toString(floors));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "5\n4 1 3 2 5", "output": "[1, 2, 3, 4, 5]", "is_hidden": false }, { - "input": "", + "input": "4\n9 2 7 1", "output": "[1, 2, 7, 9]", "is_hidden": true }, { - "input": "", + "input": "3\n3 3 1", "output": "[1, 3, 3]", "is_hidden": true } @@ -364,20 +379,20 @@ }, { "title": "ELV-P6-PROB-002", - "description": "// Critical floors need service first \u2014 highest priority number wins.\n// The priority sorter is gone. The lift is serving the wrong floors first.\n// Restore the sort. Descending order. No library methods.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static void sortByPriority(int[] priorities) {\n int n = priorities.length;\n // Sort priorities descending in place. No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[] a = {3, 1, 4, 2};\n sortByPriority(a);\n System.out.println(Arrays.toString(a));\n\n int[] b = {5, 5, 2, 8};\n sortByPriority(b);\n System.out.println(Arrays.toString(b));\n }\n}", + "description": "Critical floors need service first — the highest priority number wins. The priority sorter is gone and the lift is serving the wrong floors first. Restore the sort in descending order.\n\nImplement sortByPriority(int[] priorities) that sorts the array in descending order in place. You may NOT use Arrays.sort() or any library sort method — write the sorting algorithm yourself.\n\nInput: first line is n (number of priorities), second line is n space-separated priority values\nOutput: sorted array in descending order in Arrays.toString() format", "difficulty": "Hard", "category": "ELV-P6", "templates": { - "java": "// Critical floors need service first \u2014 highest priority number wins.\n// The priority sorter is gone. The lift is serving the wrong floors first.\n// Restore the sort. Descending order. No library methods.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static void sortByPriority(int[] priorities) {\n int n = priorities.length;\n // Sort priorities descending in place. No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[] a = {3, 1, 4, 2};\n sortByPriority(a);\n System.out.println(Arrays.toString(a));\n\n int[] b = {5, 5, 2, 8};\n sortByPriority(b);\n System.out.println(Arrays.toString(b));\n }\n}" + "java": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ElevatorQueue {\n\n public static void sortByPriority(int[] priorities) {\n int n = priorities.length;\n // Sort priorities descending in place. No Arrays.sort() or library sort allowed.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] priorities = new int[n];\n for (int i = 0; i < n; i++) priorities[i] = sc.nextInt();\n sortByPriority(priorities);\n System.out.println(Arrays.toString(priorities));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "4\n3 1 4 2", "output": "[4, 3, 2, 1]", "is_hidden": false }, { - "input": "", + "input": "4\n5 5 2 8", "output": "[8, 5, 5, 2]", "is_hidden": true } @@ -385,20 +400,20 @@ }, { "title": "ELV-P6-PROB-003", - "description": "// Lab booking slots include duplicates \u2014 multiple people queued for the same floor.\n// The sorter has to handle that cleanly. [NULL] knew it wouldn't.\n// Fix it. Handle the duplicates. Get the queue sorted.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static void sortSlots(int[] slots) {\n int n = slots.length;\n // Sort slots ascending in place. Duplicates must be handled correctly.\n // No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[] a = {3, 1, 3, 2, 1};\n sortSlots(a);\n System.out.println(Arrays.toString(a));\n\n int[] b = {7, 7, 7};\n sortSlots(b);\n System.out.println(Arrays.toString(b));\n }\n}", + "description": "Lab booking slots include duplicates — multiple people queued for the same floor. The sorter has to handle that cleanly. [NULL] knew it wouldn't. Fix it and get the queue sorted correctly.\n\nImplement sortSlots(int[] slots) that sorts the array in ascending order in place, correctly preserving duplicate values. You may NOT use Arrays.sort() or any library sort method.\n\nInput: first line is n (number of slots), second line is n space-separated slot numbers\nOutput: sorted array in Arrays.toString() format with duplicates preserved", "difficulty": "Hard", "category": "ELV-P6", "templates": { - "java": "// Lab booking slots include duplicates \u2014 multiple people queued for the same floor.\n// The sorter has to handle that cleanly. [NULL] knew it wouldn't.\n// Fix it. Handle the duplicates. Get the queue sorted.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static void sortSlots(int[] slots) {\n int n = slots.length;\n // Sort slots ascending in place. Duplicates must be handled correctly.\n // No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n int[] a = {3, 1, 3, 2, 1};\n sortSlots(a);\n System.out.println(Arrays.toString(a));\n\n int[] b = {7, 7, 7};\n sortSlots(b);\n System.out.println(Arrays.toString(b));\n }\n}" + "java": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ElevatorQueue {\n\n public static void sortSlots(int[] slots) {\n int n = slots.length;\n // Sort slots ascending in place. Duplicates must be handled correctly.\n // No Arrays.sort() or library sort allowed.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] slots = new int[n];\n for (int i = 0; i < n; i++) slots[i] = sc.nextInt();\n sortSlots(slots);\n System.out.println(Arrays.toString(slots));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "5\n3 1 3 2 1", "output": "[1, 1, 2, 3, 3]", "is_hidden": false }, { - "input": "", + "input": "3\n7 7 7", "output": "[7, 7, 7]", "is_hidden": true } @@ -406,23 +421,23 @@ }, { "title": "ELV-P6-PROB-004", - "description": "// The emergency system needs the three highest-risk floor scores to prioritise response.\n// Sort the scores yourself, then return the top three in a new array.\n// No shortcuts. Write the algorithm from scratch.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static int[] topThreeScores(int[] scores) {\n int n = scores.length;\n // Sort scores, then return a new int[] containing only the top 3 values.\n // No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(Arrays.toString(topThreeScores(new int[]{88, 55, 72, 91, 60})));\n System.out.println(Arrays.toString(topThreeScores(new int[]{100, 50, 75})));\n }\n}", + "description": "The emergency system needs the three highest-risk floor scores to prioritise response. Sort the scores yourself, then return only the top three — no shortcuts, write the algorithm from scratch.\n\nImplement topThreeScores(int[] scores) that sorts all scores in descending order and returns a new int[] containing only the top 3 values. You may NOT use Arrays.sort() or any library sort method. Input will always have at least 3 elements.\n\nInput: first line is n (number of scores), second line is n space-separated scores\nOutput: top 3 scores in descending order in Arrays.toString() format, e.g. [91, 88, 72]", "difficulty": "Hard", "category": "ELV-P6", "templates": { - "java": "// The emergency system needs the three highest-risk floor scores to prioritise response.\n// Sort the scores yourself, then return the top three in a new array.\n// No shortcuts. Write the algorithm from scratch.\n\nimport java.util.Arrays;\n\npublic class ElevatorQueue {\n\n public static int[] topThreeScores(int[] scores) {\n int n = scores.length;\n // Sort scores, then return a new int[] containing only the top 3 values.\n // No Arrays.sort() or library sort allowed.\n {PLAYER CODE}\n }\n\n public static void main(String[] args) {\n System.out.println(Arrays.toString(topThreeScores(new int[]{88, 55, 72, 91, 60})));\n System.out.println(Arrays.toString(topThreeScores(new int[]{100, 50, 75})));\n }\n}" + "java": "import java.util.Arrays;\nimport java.util.Scanner;\n\npublic class ElevatorQueue {\n\n public static int[] topThreeScores(int[] scores) {\n int n = scores.length;\n // Sort scores descending, then return a new int[] containing only the top 3 values.\n // No Arrays.sort() or library sort allowed.\n // player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] scores = new int[n];\n for (int i = 0; i < n; i++) scores[i] = sc.nextInt();\n System.out.println(Arrays.toString(topThreeScores(scores)));\n sc.close();\n }\n}" }, "test_cases": [ { - "input": "", + "input": "5\n88 55 72 91 60", "output": "[91, 88, 72]", "is_hidden": false }, { - "input": "", + "input": "3\n100 50 75", "output": "[100, 75, 50]", "is_hidden": true } ] } -] \ No newline at end of file +] From 71ce2dc8cb139dd7b2dfdab4356c28d532d3170a Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Tue, 14 Apr 2026 13:14:23 +0700 Subject: [PATCH 07/10] refactor: update Java problem templates to use stdin/stdout and add remote seeding commands to README --- README.md | 4 + src/scripts/data/java/hallway/problems.json | 240 +++++++++---------- src/scripts/data/java/restroom/problems.json | 2 +- 3 files changed, 125 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index 39d3c94..cf9de3b 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,10 @@ Seed the database with Java MCQs, riddles, and problems tagged as `JAV_RESTROOM` # Running via Docker (Must rebuild if scripts are modified) docker compose --profile local up -d --build docker compose --profile local exec local-code-api python3 -m scripts.seeders.seed_restroom_java +docker compose --profile remote exec code-api python3 -m scripts.seeders.seed_restroom_java +docker compose --profile remote exec code-api python3 -m scripts.seeders.seed_lockerroom_java +docker compose --profile remote exec code-api python3 -m scripts.seeders.seed_hallway_java +docker compose --profile remote exec code-api python3 -m scripts.seeders.seed_elevatorhall_java # Running Locally (Ensure .env is configured or set DATABASE_URL) export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/code_executor diff --git a/src/scripts/data/java/hallway/problems.json b/src/scripts/data/java/hallway/problems.json index 04f348c..5c98455 100644 --- a/src/scripts/data/java/hallway/problems.json +++ b/src/scripts/data/java/hallway/problems.json @@ -1,71 +1,71 @@ [ { "title": "HLW-001: Bad news", - "description": "AUTHOR: Anonymous\n\nBad news. The security daemon doesn't just use a static shelf number anymore. It rotates the physical bypass tunnel every 24 hours based on the server's daily diagnostic logs.\n\nI intercepted the interface architecture. You need to write a class named ShelfOverride that implements the ShelfController interface.\n\nThe system will pass an array of integers into your method. The correct shelf number is the total count of diagnostic codes in that array that are BOTH strictly greater than 100 AND a multiple of 3.\n\nYOUR TARGET:\n\nImplement: ShelfController\n\nRequired Method: public int getTargetShelf(int[] diagnostics)\n\nWrite the loop. Filter the array. Return the final count.\n\nWarning: Do not write an infinite loop. The server will time out, flag this terminal, and lock us out forever.", + "description": "Write ShelfOverride implementing ShelfController. Read the count, then diagnostics values from stdin. Print how many values are greater than 100 and divisible by 3.", "difficulty": "Hard", "category": "HLW_P004", "templates": { - "java": "class ShelfOverride {\n public int getTargetShelf(int[] diagnostics) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface ShelfController {\n int getTargetShelf(int[] diagnostics);\n}\n\nclass ShelfOverride implements ShelfController {\n public int getTargetShelf(int[] diagnostics) {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] diagnostics = new int[n];\n for (int i = 0; i < n; i++) {\n diagnostics[i] = sc.nextInt();\n }\n ShelfController controller = new ShelfOverride();\n System.out.println(controller.getTargetShelf(diagnostics));\n }\n}" }, "test_cases": [ { - "input": "[102, 105, 108]", + "input": "3\n102 105 108", "output": "3", "is_hidden": false }, { - "input": "[99, 100, 101]", - "output": "0", + "input": "3\n105 108 111", + "output": "3", "is_hidden": true }, { - "input": "[300, 200, 102]", - "output": "2", + "input": "3\n103 106 102", + "output": "1", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "0", "is_hidden": true }, { - "input": "[103, 106, 110, 111]", - "output": "2", + "input": "1\n102", + "output": "0", "is_hidden": true } ] }, { "title": "HLW-002: The encrypted gatekeeper is monitoring heat sig...", - "description": "AUTHOR: Ghost_Protocol\n\nThe encrypted gatekeeper is monitoring heat signatures. To bypass the thermal lock, you need to identify \"critical spikes.\"\n\nWrite a class ThermalBypass that implements SensorArray. Iterate through the input array and count how many values are negative OR above 500.\n\nTARGET:\n\nImplement: SensorArray\n\nMethod: public int countSpikes(int[] heat)", + "description": "Write ThermalBypass implementing SensorArray. Read the count, then heat readings. Print how many readings are negative or above 500.", "difficulty": "Hard", "category": "HLW_P004", "templates": { - "java": "class ThermalBypass {\n public int countSpikes(int[] heat) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface SensorArray {\n int countSpikes(int[] heat);\n}\n\nclass ThermalBypass implements SensorArray {\n public int countSpikes(int[] heat) {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] heat = new int[n];\n for (int i = 0; i < n; i++) {\n heat[i] = sc.nextInt();\n }\n SensorArray sensor = new ThermalBypass();\n System.out.println(sensor.countSpikes(heat));\n }\n}" }, "test_cases": [ { - "input": "[-1, 501, 100]", + "input": "2\n-1 501", "output": "2", "is_hidden": false }, { - "input": "[0, 500, 499]", + "input": "2\n0 500", "output": "0", "is_hidden": true }, { - "input": "[-10, -20, 600, 700]", - "output": "4", + "input": "2\n-10 600", + "output": "2", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "0", "is_hidden": true }, { - "input": "[1, 2, 3]", + "input": "1\n250", "output": "0", "is_hidden": true } @@ -73,71 +73,71 @@ }, { "title": "HLW-003: We\u2019re intercepting a packet stream", - "description": "AUTHOR: NullPointer\n\n\n\nWe\u2019re intercepting a packet stream. The bridge will only open if we provide the sum of all \"parity-aligned\" IDs.\n\n\n\nImplement BridgeProtocol. Your method must sum all even numbers in the array. If the array is empty, return 0.\n\n\n\nTARGET:\n\n\nImplement: BridgeProtocol\n\n\nMethod: public int getParitySum(int[] ids)", + "description": "Write BridgeProtocol implementing BridgeProtocol. Read the count, then IDs. Print the sum of even IDs.", "difficulty": "Hard", "category": "HLW_P004", "templates": { - "java": "class BridgeProtocol {\n public int getParitySum(int[] ids) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface BridgeProtocol {\n int getParitySum(int[] ids);\n}\n\nclass BridgeProtocolImpl implements BridgeProtocol {\n public int getParitySum(int[] ids) {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] ids = new int[n];\n for (int i = 0; i < n; i++) {\n ids[i] = sc.nextInt();\n }\n BridgeProtocol bridge = new BridgeProtocolImpl();\n System.out.println(bridge.getParitySum(ids));\n }\n}" }, "test_cases": [ { - "input": "[2, 4, 6]", + "input": "3\n2 4 6", "output": "12", "is_hidden": false }, { - "input": "[1, 3, 5]", - "output": "0", + "input": "2\n4 6", + "output": "10", "is_hidden": true }, { - "input": "[10, 11, 12]", + "input": "2\n10 12", "output": "22", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "0", "is_hidden": true }, { - "input": "[-2, 2, 0]", - "output": "0", + "input": "2\n2 2", + "output": "4", "is_hidden": true } ] }, { "title": "HLW-004: The vault uses a \"Range-Lock\" mechanism", - "description": "AUTHOR: Anonymous\n\n\n\nThe vault uses a \"Range-Lock\" mechanism. We need to verify if the server's sequence contains at least three values within the \"Safe Zone\" (between 10 and 20 inclusive).\n\n\n\nImplement VaultUnlocker. Return true if the count of valid numbers is 3 or more, otherwise return false.\n\n\n\nTARGET:\n\n\nImplement: VaultUnlocker\n\n\nMethod: public boolean isSafe(int[] seq)", + "description": "Write VaultUnlocker implementing VaultUnlocker. Read the count, then sequence values. Print true if at least three values are between 10 and 20 inclusive.", "difficulty": "Hard", "category": "HLW_P004", "templates": { - "java": "class VaultUnlocker {\n public boolean isSafe(int[] seq) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface VaultUnlocker {\n boolean isSafe(int[] seq);\n}\n\nclass VaultUnlockerImpl implements VaultUnlocker {\n public boolean isSafe(int[] seq) {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] seq = new int[n];\n for (int i = 0; i < n; i++) {\n seq[i] = sc.nextInt();\n }\n VaultUnlocker unlocker = new VaultUnlockerImpl();\n System.out.println(unlocker.isSafe(seq));\n }\n}" }, "test_cases": [ { - "input": "[10, 15, 20]", + "input": "3\n10 15 20", "output": "true", "is_hidden": false }, { - "input": "[10, 15, 9]", + "input": "2\n15 18", "output": "false", "is_hidden": true }, { - "input": "[10, 20, 11, 12]", + "input": "3\n10 20 11", "output": "true", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "false", "is_hidden": true }, { - "input": "[21, 22, 23, 24, 25]", + "input": "2\n9 21", "output": "false", "is_hidden": true } @@ -145,35 +145,35 @@ }, { "title": "HLW-005: The watchdog timer is scanning for anomalies", - "description": "AUTHOR: Root_Access\n\n\n\nThe watchdog timer is scanning for anomalies. An anomaly is any value that is exactly double the value of the number immediately preceding it in the array.\n\n\n\nImplement WatchdogBypass. Return the total count of these anomalies. Start your check from the second element.\n\n\n\nTARGET:\n\n\nImplement: WatchdogBypass\n\n\nMethod: public int findAnomalies(int[] stream)", + "description": "Write WatchdogBypass implementing WatchdogBypass. Read the count, then stream values. Print the number of anomalies where a value is exactly double the previous value.", "difficulty": "Hard", "category": "HLW_P004", "templates": { - "java": "class WatchdogBypass {\n public int findAnomalies(int[] stream) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface WatchdogBypass {\n int findAnomalies(int[] stream);\n}\n\nclass WatchdogBypassImpl implements WatchdogBypass {\n public int findAnomalies(int[] stream) {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] stream = new int[n];\n for (int i = 0; i < n; i++) {\n stream[i] = sc.nextInt();\n }\n WatchdogBypass watcher = new WatchdogBypassImpl();\n System.out.println(watcher.findAnomalies(stream));\n }\n}" }, "test_cases": [ { - "input": "[1, 2, 4]", + "input": "3\n1 2 4", "output": "2", "is_hidden": false }, { - "input": "[1, 3, 6]", + "input": "2\n5 10", "output": "1", "is_hidden": true }, { - "input": "[10, 20, 30, 60]", + "input": "3\n10 20 40", "output": "2", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "0", "is_hidden": true }, { - "input": "[100]", + "input": "1\n2", "output": "0", "is_hidden": true } @@ -181,179 +181,179 @@ }, { "title": "HLW-006: Security Protocol is failing to compile", - "description": "Security Protocol is failing to compile. The security protocol uses the Decryptor interface, but the Clue class is missing the required method to unlock it.\n\nTARGET: Write the missing method. The interface requires getShiftKey() to return an integer of the bypass shift key. The bypass shift key for this node is the amount of bookshelves added to the amount of student's desk.", + "description": "Write Clue implementing Decryptor. Read a single integer placeholder from stdin and print the bypass shift key computed from bookshelf and student desk values.", "difficulty": "Hard", "category": "HLW_P005", "templates": { - "java": "class Clue {\n public int getShiftKey() {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Decryptor {\n int getShiftKey();\n}\n\nclass Clue implements Decryptor {\n private static final int BOOKSHELVES = 4;\n private static final int STUDENT_DESK = 2;\n\n public int getShiftKey() {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n if (sc.hasNextInt()) { sc.nextInt(); }\n Clue clue = new Clue();\n System.out.println(clue.getShiftKey());\n }\n}" }, "test_cases": [ { - "input": "dummy_0", - "output": "STATUS: PASSED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "0", + "output": "6", "is_hidden": false }, { - "input": "dummy_1", - "output": "STATUS: PASSED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "1", + "output": "6", "is_hidden": true }, { - "input": "dummy_2", - "output": "STATUS: PASSED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "2", + "output": "6", "is_hidden": true }, { - "input": "dummy_3", - "output": "STATUS: PASSED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "3", + "output": "6", "is_hidden": true }, { - "input": "dummy_4", - "output": "STATUS: PASSED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "4", + "output": "6", "is_hidden": true } ] }, { "title": "HLW-007: The server room is overheating", - "description": "The server room is overheating. The CoolantSystem interface requires a getTemperatureThreshold() method to initiate the purge.\n\n\n\nTARGET: Calculate the threshold by adding the roomCount (12) to the serverDensity (14).", + "description": "Write PurgeUnit implementing CoolantSystem. Read a single numeric placeholder from stdin and print the temperature threshold calculated from roomCount plus serverDensity.", "difficulty": "Hard", "category": "HLW_P005", "templates": { - "java": "class PurgeUnit {\n public int getTemperatureThreshold() {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface CoolantSystem {\n int getTemperatureThreshold();\n}\n\nclass PurgeUnit implements CoolantSystem {\n private static final int ROOM_COUNT = 12;\n private static final int SERVER_DENSITY = 14;\n\n public int getTemperatureThreshold() {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n if (sc.hasNextInt()) { sc.nextInt(); }\n PurgeUnit unit = new PurgeUnit();\n System.out.println(unit.getTemperatureThreshold());\n }\n}" }, "test_cases": [ { - "input": "dummy_0", - "output": "STATUS: PURGING\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "0", + "output": "26", "is_hidden": false }, { - "input": "dummy_1", - "output": "STATUS: PURGING\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "1", + "output": "26", "is_hidden": true }, { - "input": "dummy_2", - "output": "STATUS: PURGING\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "2", + "output": "26", "is_hidden": true }, { - "input": "dummy_3", - "output": "STATUS: PURGING\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "3", + "output": "26", "is_hidden": true }, { - "input": "dummy_4", - "output": "STATUS: PURGING\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "4", + "output": "26", "is_hidden": true } ] }, { "title": "HLW-008: The satellite dish is misaligned", - "description": "The satellite dish is misaligned. The Uplink interface requires a getSignalFrequency() method to lock onto the DevScape core.\n\n\n\nTARGET: Calculate the frequency by multiplying the dishRotation (45) by the amplifierGain (2).", + "description": "Write SatelliteDish implementing Uplink. Read a single numeric placeholder from stdin and print the signal frequency calculated by multiplying dishRotation by amplifierGain.", "difficulty": "Hard", "category": "HLW_P005", "templates": { - "java": "class SatelliteDish {\n public int getSignalFrequency() {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Uplink {\n int getSignalFrequency();\n}\n\nclass SatelliteDish implements Uplink {\n private static final int DISH_ROTATION = 45;\n private static final int AMPLIFIER_GAIN = 2;\n\n public int getSignalFrequency() {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n if (sc.hasNextInt()) { sc.nextInt(); }\n SatelliteDish dish = new SatelliteDish();\n System.out.println(dish.getSignalFrequency());\n }\n}" }, "test_cases": [ { - "input": "dummy_0", - "output": "STATUS: CONNECTED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "0", + "output": "90", "is_hidden": false }, { - "input": "dummy_1", - "output": "STATUS: CONNECTED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "1", + "output": "90", "is_hidden": true }, { - "input": "dummy_2", - "output": "STATUS: CONNECTED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "2", + "output": "90", "is_hidden": true }, { - "input": "dummy_3", - "output": "STATUS: CONNECTED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "3", + "output": "90", "is_hidden": true }, { - "input": "dummy_4", - "output": "STATUS: CONNECTED\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "4", + "output": "90", "is_hidden": true } ] }, { "title": "HLW-009: The archive vault is locked behind a syntax error", - "description": "The archive vault is locked behind a syntax error. The Vault interface requires getAccessKey() to verify the user.\n\n\n\nTARGET: The access key is the vaultID (1024) minus the securityDelay (24).", + "description": "Write ArchiveVault implementing Vault. Read a single numeric placeholder from stdin and print the access key calculated as vaultID minus securityDelay.", "difficulty": "Hard", "category": "HLW_P005", "templates": { - "java": "class ArchiveVault {\n public int getAccessKey() {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Vault {\n int getAccessKey();\n}\n\nclass ArchiveVault implements Vault {\n private static final int VAULT_ID = 1024;\n private static final int SECURITY_DELAY = 24;\n\n public int getAccessKey() {\n // code here\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n if (sc.hasNextInt()) { sc.nextInt(); }\n ArchiveVault vault = new ArchiveVault();\n System.out.println(vault.getAccessKey());\n }\n}" }, "test_cases": [ { - "input": "dummy_0", - "output": "STATUS: UNLOCKED\n\n\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "0", + "output": "1000", "is_hidden": false }, { - "input": "dummy_1", - "output": "STATUS: UNLOCKED\n\n\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "1", + "output": "1000", "is_hidden": true }, { - "input": "dummy_2", - "output": "STATUS: UNLOCKED\n\n\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "2", + "output": "1000", "is_hidden": true }, { - "input": "dummy_3", - "output": "STATUS: UNLOCKED\n\n\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "3", + "output": "1000", "is_hidden": true }, { - "input": "dummy_4", - "output": "STATUS: UNLOCKED\n\n\nRIDDLE ACQUIRED: \"RIDDLE\"", + "input": "4", + "output": "1000", "is_hidden": true } ] }, { "title": "HLW-010: Don't bother running straight to the lobby", - "description": "AUTHOR: Anonymous\n\nDon't bother running straight to the lobby. The final exit keypad is completely powered down. The system won't supply power to the keypad until all five auxiliary security nodes in this hallway are decrypted.\n\nThe lockdown AI completely wiped the Firewall class from the server memory to stop us from getting the last clue. It only left the Mainframe interface intact.\n\nTARGET: \nRebuild the missing class from scratch.\n\nCreate a class named Firewall that implements Mainframe.\n\nImplement the missing decrypt() method.\n\nThe method must scan the data array. If it finds the exact integer 404, it must return: getPasskeyRiddle()\n\nIf it doesn't find it, return \"LOCKED\".", + "description": "Write Firewall implementing Mainframe. Read the count, then data values. Print the passkey riddle if the array contains 404; otherwise print LOCKED.", "difficulty": "Hard", "category": "HLW_P006", "templates": { - "java": "class Firewall {\n public String decrypt(int[] data) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Mainframe {\n String decrypt(int[] data);\n String getPasskeyRiddle();\n}\n\nclass Firewall implements Mainframe {\n public String decrypt(int[] data) {\n // code here\n }\n\n public String getPasskeyRiddle() {\n return \"RIDDLE_CONTENT\";\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = sc.nextInt();\n }\n Mainframe firewall = new Firewall();\n System.out.println(firewall.decrypt(data));\n }\n}" }, "test_cases": [ { - "input": "[101, 404, 202]", + "input": "3\n101 404 202", "output": "RIDDLE_CONTENT", "is_hidden": false }, { - "input": "[1, 2, 3]", + "input": "3\n1 2 3", "output": "LOCKED", "is_hidden": true }, { - "input": "[404]", + "input": "1\n404", "output": "RIDDLE_CONTENT", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "LOCKED", "is_hidden": true }, { - "input": "[405, 403]", + "input": "2\n405 403", "output": "LOCKED", "is_hidden": true } @@ -361,71 +361,71 @@ }, { "title": "HLW-011: The biometric scanner for the armory is offline", - "description": "AUTHOR: Cipher\n\nThe biometric scanner for the armory is offline. The auxiliary power routing needs a massive surge to bypass the mechanical breaker. We need to channel all available data packets and check if the total voltage is high enough.\n\nTARGET:\nRebuild the missing routing class.\n\nCreate a class named PowerRouter that implements Mainframe.\n\nImplement the missing decrypt() method.\n\nThe method must calculate the total sum of all integers in the data array. If the total is greater than 9000, it must return: getPasskeyRiddle()\n\nIf it isn't, return \"LOCKED\".", + "description": "Write PowerRouter implementing Mainframe. Read the count, then data values. Print the passkey riddle if the sum is greater than 9000; otherwise print LOCKED.", "difficulty": "Hard", "category": "HLW_P006", "templates": { - "java": "class PowerRouter {\n public String decrypt(int[] data) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Mainframe {\n String decrypt(int[] data);\n String getPasskeyRiddle();\n}\n\nclass PowerRouter implements Mainframe {\n public String decrypt(int[] data) {\n // code here\n }\n\n public String getPasskeyRiddle() {\n return \"RIDDLE_CONTENT\";\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = sc.nextInt();\n }\n Mainframe router = new PowerRouter();\n System.out.println(router.decrypt(data));\n }\n}" }, "test_cases": [ { - "input": "[5000, 4001]", + "input": "2\n5000 4001", "output": "RIDDLE_CONTENT", "is_hidden": false }, { - "input": "[9000]", - "output": "LOCKED", + "input": "2\n4501 4500", + "output": "RIDDLE_CONTENT", "is_hidden": true }, { - "input": "[4500, 4500]", + "input": "1\n9000", "output": "LOCKED", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "LOCKED", "is_hidden": true }, { - "input": "[10000]", - "output": "RIDDLE_CONTENT", + "input": "1\n5000", + "output": "LOCKED", "is_hidden": true } ] }, { "title": "HLW-012: A logic bomb has been planted in the ventilatio...", - "description": "AUTHOR: Ghost\n\n\n\nA logic bomb has been planted in the ventilation control subnet. We don't have time to sanitize the whole thing. We just need to find the trigger sequence before it executes. The bomb's signature is two consecutive negative integers.\n\n\n\nTARGET:\n\n\nConstruct the scanner class.\n\n\n\nCreate a class named LogicScanner that implements Mainframe.\n\n\n\nImplement the missing decrypt() method.\n\n\n\nThe method must scan the data array for two negative numbers in a row (e.g., -5 immediately followed by -1). If it finds this signature, return: getPasskeyRiddle()\n\n\n\nIf it reaches the end without finding the signature, return \"LOCKED\".", + "description": "Write LogicScanner implementing Mainframe. Read the count, then data values. Print the passkey riddle if two consecutive negative values appear; otherwise print LOCKED.", "difficulty": "Hard", "category": "HLW_P006", "templates": { - "java": "class LogicScanner {\n public String decrypt(int[] data) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Mainframe {\n String decrypt(int[] data);\n String getPasskeyRiddle();\n}\n\nclass LogicScanner implements Mainframe {\n public String decrypt(int[] data) {\n // code here\n }\n\n public String getPasskeyRiddle() {\n return \"RIDDLE_CONTENT\";\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = sc.nextInt();\n }\n Mainframe scanner = new LogicScanner();\n System.out.println(scanner.decrypt(data));\n }\n}" }, "test_cases": [ { - "input": "[-1, -2]", + "input": "2\n-1 -2", "output": "RIDDLE_CONTENT", "is_hidden": false }, { - "input": "[-1, 0, -2]", + "input": "3\n-1 0 -2", "output": "LOCKED", "is_hidden": true }, { - "input": "[1, 2, -3, -4, 5]", + "input": "5\n1 2 -3 -4 5", "output": "RIDDLE_CONTENT", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "LOCKED", "is_hidden": true }, { - "input": "[-1]", + "input": "1\n-1", "output": "LOCKED", "is_hidden": true } @@ -433,35 +433,35 @@ }, { "title": "HLW-013: The main elevator requires a secure handshake t...", - "description": "AUTHOR: Overwatch\n\nThe main elevator requires a secure handshake to descend to the lab level. The encryption parity is strict: every single packet in the handshake sequence must be an even number. One odd packet means the connection is compromised.\n\nTARGET:\n\nBuild the verification class.\n\nCreate a class named ParityCheck that implements Mainframe.\n\nImplement the missing decrypt() method.\n\nThe method must evaluate the data array. If it detects ANY odd integer, immediately return: \"LOCKED\"\n\nIf it successfully scans the entire array and all numbers are even, return: getPasskeyRiddle()", + "description": "Write ParityCheck implementing Mainframe. Read the count, then handshake packet values. Print the passkey riddle if every number is even; otherwise print LOCKED.", "difficulty": "Hard", "category": "HLW_P006", "templates": { - "java": "class ParityCheck {\n public String decrypt(int[] data) {\n // Your code here\n }\n}" + "java": "import java.util.Scanner;\n\ninterface Mainframe {\n String decrypt(int[] data);\n String getPasskeyRiddle();\n}\n\nclass ParityCheck implements Mainframe {\n public String decrypt(int[] data) {\n // code here\n }\n\n public String getPasskeyRiddle() {\n return \"RIDDLE_CONTENT\";\n }\n}\n\npublic class Solution {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] data = new int[n];\n for (int i = 0; i < n; i++) {\n data[i] = sc.nextInt();\n }\n Mainframe parity = new ParityCheck();\n System.out.println(parity.decrypt(data));\n }\n}" }, "test_cases": [ { - "input": "[2, 4, 6]", + "input": "3\n2 4 6", "output": "RIDDLE_CONTENT", "is_hidden": false }, { - "input": "[2, 4, 5]", - "output": "LOCKED", + "input": "2\n2 4", + "output": "RIDDLE_CONTENT", "is_hidden": true }, { - "input": "[1, 3, 5]", + "input": "3\n2 4 5", "output": "LOCKED", "is_hidden": true }, { - "input": "[]", + "input": "0", "output": "RIDDLE_CONTENT", "is_hidden": true }, { - "input": "[0, 2, 4]", + "input": "1\n0", "output": "RIDDLE_CONTENT", "is_hidden": true } diff --git a/src/scripts/data/java/restroom/problems.json b/src/scripts/data/java/restroom/problems.json index e20f86f..0ada328 100644 --- a/src/scripts/data/java/restroom/problems.json +++ b/src/scripts/data/java/restroom/problems.json @@ -37,7 +37,7 @@ }, { "title": "RST-002: Database Connection String Update", - "description": "// The database moved to a secure port, but our connection string stubbornly refuses to update.\nString dbUrl = \"jdbc:mysql://localhost:80/data\";\ndbUrl.replace(\"80\", \"443\");\nSystem.out.println(dbUrl);", + "description": "The database moved to a secure port, but our connection string stubbornly refuses to update.\nThe secure port will be receive as input string\nString dbUrl = \"jdbc:mysql://localhost:80/data\";\ndbUrl.replace(\"80\", \"443\");\nSystem.out.println(dbUrl);\nThis code should not work", "difficulty": "Easy", "category": "Strings", "templates": { From 75d576b4b7ebde7d9d774b2b68a2707570acda79 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Mon, 27 Apr 2026 18:35:27 +0700 Subject: [PATCH 08/10] feat: add seeder and data files for THEICT Java practice content --- src/scripts/data/java/theict/chunks.json | 130 ++++++++++++ src/scripts/data/java/theict/problems.json | 194 ++++++++++++++++++ src/scripts/data/java/theict/questions.json | 1 + src/scripts/data/java/theict/riddles.json | 1 + src/scripts/seeders/seed_theict_java.py | 215 ++++++++++++++++++++ 5 files changed, 541 insertions(+) create mode 100644 src/scripts/data/java/theict/chunks.json create mode 100644 src/scripts/data/java/theict/problems.json create mode 100644 src/scripts/data/java/theict/questions.json create mode 100644 src/scripts/data/java/theict/riddles.json create mode 100644 src/scripts/seeders/seed_theict_java.py diff --git a/src/scripts/data/java/theict/chunks.json b/src/scripts/data/java/theict/chunks.json new file mode 100644 index 0000000..bcb0da1 --- /dev/null +++ b/src/scripts/data/java/theict/chunks.json @@ -0,0 +1,130 @@ +[ + { + "title": "L5_P4 (Chunk) Chunk 1", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] jumbled the intrusion log timestamps.\n// Events are scattered across time. Without ordering, the forensic trail is useless.\n// Implement the comparator, sort the log, format the report.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by timestamp ascending.\n // If timestamps are equal, sort by event alphabetically.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "snippets": { + "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n if (this.timestamp != other.timestamp) {\n return this.timestamp - other.timestamp;\n }\n return this.event.compareTo(other.event);\n}", + "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int ts = Integer.parseInt(parts[0]);\n String ev = parts[1];\n list.add(new LogEntry(ts, ev));\n}\nreturn list;", + "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"[\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" + } + } + } + }, + { + "title": "L5_P4 (Chunk) Chunk 2", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] scrambled the alert priority queue.\n// Critical events are buried under noise. Severity must come first.\n// Rebuild the sorter. Severity descending, then time ascending.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int severity;\n int timestamp;\n String event;\n\n LogEntry(int severity, int timestamp, String event) {\n this.severity = severity;\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by severity DESCENDING (highest first).\n // If severity is equal, sort by timestamp ASCENDING.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"severity:timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[severity|timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "snippets": { + "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n if (this.severity != other.severity) {\n return other.severity - this.severity;\n }\n return this.timestamp - other.timestamp;\n}", + "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int sev = Integer.parseInt(parts[0]);\n int ts = Integer.parseInt(parts[1]);\n String ev = parts[2];\n list.add(new LogEntry(sev, ts, ev));\n}\nreturn list;", + "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"[\").append(e.severity).append(\"|\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" + } + } + } + }, + { + "title": "L5_P4 (Chunk) Chunk 3", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] shuffled the incident categories.\n// Events with the same name are split across the timeline. Grouping is destroyed.\n// Rebuild the sorter. Group by name, latest first within each group.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by event name alphabetically.\n // If event names are equal, sort by timestamp DESCENDING (latest first).\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "snippets": { + "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n int cmp = this.event.compareTo(other.event);\n if (cmp != 0) return cmp;\n return other.timestamp - this.timestamp;\n}", + "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int ts = Integer.parseInt(parts[0]);\n String ev = parts[1];\n list.add(new LogEntry(ts, ev));\n}\nreturn list;", + "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"[\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" + } + } + } + }, + { + "title": "L5_P4 (Chunk) Chunk 4", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] erased the log sequence numbers.\n// Events exist but have no position. Without indexing, replay is impossible.\n// Rebuild the sorter and assign sequential indexes after sorting.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by timestamp ascending.\n // If timestamps are equal, sort by event alphabetically.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"#index [timestamp] event\"\n // where index starts at 1.\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "snippets": { + "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n if (this.timestamp != other.timestamp) {\n return this.timestamp - other.timestamp;\n }\n return this.event.compareTo(other.event);\n}", + "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int ts = Integer.parseInt(parts[0]);\n String ev = parts[1];\n list.add(new LogEntry(ts, ev));\n}\nreturn list;", + "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"#\").append(i + 1).append(\" [\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" + } + } + } + }, + { + "title": "L5_P6 (Chunk) Chunk 1", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] overloaded the traffic shaper's queue.\n// Packets flood in with no limit, no order, no rejection.\n// Restore the bounded queue. Capacity is law. Overflow means dropped.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int dropped = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end and return \"QUEUED\".\n // Otherwise, increment dropped counter and return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet.\n // If queue is empty, return \"IDLE\".\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|DROPPED:count\"\n {TASK 3: STATUS}\n }\n}", + "snippets": { + "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n queue.addLast(packet);\n return \"QUEUED\";\n} else {\n dropped++;\n return \"DROPPED\";\n}", + "TASK 2: DEQUEUE": "if (queue.isEmpty()) return \"IDLE\";\nreturn queue.removeFirst();", + "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|DROPPED:\" + dropped;" + } + } + } + }, + { + "title": "L5_P6 (Chunk) Chunk 2", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] disabled the traffic meter.\n// Packets flow but nothing tracks throughput. Processed count is zero.\n// Restore the queue and track every successful dequeue.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int processed = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end and return \"QUEUED\".\n // Otherwise, return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet, and increment processed counter.\n // If queue is empty, return \"IDLE\" (do NOT increment processed).\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|PROCESSED:count\"\n {TASK 3: STATUS}\n }\n}", + "snippets": { + "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n queue.addLast(packet);\n return \"QUEUED\";\n} else {\n return \"DROPPED\";\n}", + "TASK 2: DEQUEUE": "if (queue.isEmpty()) return \"IDLE\";\nprocessed++;\nreturn queue.removeFirst();", + "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|PROCESSED:\" + processed;" + } + } + } + }, + { + "title": "L5_P6 (Chunk) Chunk 3", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] broke the priority lane in the traffic shaper.\n// VIP packets wait in line like everyone else. The fast lane is dead.\n// Restore priority enqueue. VIP goes to the front, normal to the back.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int dropped = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet, boolean priority) {\n // TASK 1: If queue size < capacity:\n // - If priority is true, add packet to the FRONT and return \"PRIORITY_QUEUED\".\n // - If priority is false, add packet to the END and return \"QUEUED\".\n // If queue is full, increment dropped and return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet.\n // If queue is empty, return \"IDLE\".\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|DROPPED:count\"\n {TASK 3: STATUS}\n }\n}", + "snippets": { + "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n if (priority) {\n queue.addFirst(packet);\n return \"PRIORITY_QUEUED\";\n } else {\n queue.addLast(packet);\n return \"QUEUED\";\n }\n} else {\n dropped++;\n return \"DROPPED\";\n}", + "TASK 2: DEQUEUE": "if (queue.isEmpty()) return \"IDLE\";\nreturn queue.removeFirst();", + "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|DROPPED:\" + dropped;" + } + } + } + }, + { + "title": "L5_P6 (Chunk) Chunk 4", + "difficulty": "Hard", + "category": "Java Architecture", + "templates": { + "java": { + "name": "Java Template", + "template_code": "// [NULL] wiped the traffic shaper's inspection tools.\n// Packets enter the queue but there is no way to inspect without consuming.\n// Restore the queue with peek and lifetime tracking.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int totalEnqueued = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end,\n // increment totalEnqueued, and return \"QUEUED\".\n // Otherwise, return \"DROPPED\" (do NOT increment totalEnqueued).\n {TASK 1: ENQUEUE}\n }\n\n public static String peek() {\n // TASK 2: Return the front packet WITHOUT removing it.\n // If queue is empty, return \"IDLE\".\n {TASK 2: PEEK}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|TOTAL:totalEnqueued\"\n {TASK 3: STATUS}\n }\n}", + "snippets": { + "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n queue.addLast(packet);\n totalEnqueued++;\n return \"QUEUED\";\n} else {\n return \"DROPPED\";\n}", + "TASK 2: PEEK": "if (queue.isEmpty()) return \"IDLE\";\nreturn queue.getFirst();", + "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|TOTAL:\" + totalEnqueued;" + } + } + } + } +] \ No newline at end of file diff --git a/src/scripts/data/java/theict/problems.json b/src/scripts/data/java/theict/problems.json new file mode 100644 index 0000000..ed0901b --- /dev/null +++ b/src/scripts/data/java/theict/problems.json @@ -0,0 +1,194 @@ +[ + { + "title": "FIREWALL RULE ENGINE v3.1", + "description": " == FIREWALL RULE ENGINE v3.1 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the firewall's rule engine.\nPackets flow unchecked. Every rule was a single encoded string.\nParse the format, enforce the logic. One misread and the breach widens.\n\nRULE FORMAT:\n \"ACTION|port_min-port_max|protocol\"\n ACTION is either \"ALLOW\" or \"DENY\"\n port_min and port_max define an inclusive range\n protocol is a string like \"TCP\" or \"UDP\"\n\nPACKET FORMAT:\n \"port|protocol\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's port as an integer and its protocol as a string.\n 2. Parse the rule's action, port range, and protocol.\n 3. If the packet's port falls within the range (inclusive)\n AND the protocol matches (case-insensitive), return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class FirewallRules {\n\n public static String evaluate(String rule, String packet) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String rule = sc.nextLine().trim();\n int q = Integer.parseInt(sc.nextLine().trim());\n for (int i = 0; i < q; i++) {\n String packet = sc.nextLine().trim();\n System.out.println(evaluate(rule, packet));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "ALLOW|80-443|TCP\n4\n80|TCP\n443|tcp\n8080|TCP\n80|UDP", + "output": "ALLOW\nALLOW\nNO_MATCH\nNO_MATCH", + "is_hidden": false + } + ] + }, + { + "title": "FIREWALL RULE ENGINE v3.2", + "description": " == FIREWALL RULE ENGINE v3.2 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the firewall's IP-based rule engine.\nTraffic flows unfiltered. Every rule was a single encoded string.\nParse the format, enforce the logic. One wrong IP and the whole floor is exposed.\n\nRULE FORMAT:\n \"ACTION|ip_prefix|port\"\n ACTION is either \"ALLOW\" or \"DENY\"\n ip_prefix is a partial IP like \"192.168\" (match if packet IP starts with this)\n port is an exact port number\n\nPACKET FORMAT:\n \"ip_address|port\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's IP address (string) and port (integer).\n 2. Parse the rule's action, IP prefix, and port.\n 3. If the packet's IP starts with the rule's ip_prefix\n AND the port matches exactly, return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class FirewallRules {\n\n public static String evaluate(String rule, String packet) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String rule = sc.nextLine().trim();\n int q = Integer.parseInt(sc.nextLine().trim());\n for (int i = 0; i < q; i++) {\n String packet = sc.nextLine().trim();\n System.out.println(evaluate(rule, packet));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "ALLOW|192.168|8080\n3\n192.168.1.5|8080\n192.168.0.1|3000\n10.0.0.1|8080", + "output": "ALLOW\nNO_MATCH\nNO_MATCH", + "is_hidden": false + } + ] + }, + { + "title": "FIREWALL RULE ENGINE v3.3", + "description": " == FIREWALL RULE ENGINE v3.3 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the outbound traffic filter.\nEvery packet escapes unchecked. Rules encoded as single strings are all that remain.\nParse the format, enforce the logic. The building leaks data with every second.\n\nRULE FORMAT:\n \"ACTION|protocol|min_port\"\n ACTION is either \"ALLOW\" or \"DENY\"\n protocol is a string like \"TCP\", \"UDP\", \"ICMP\"\n min_port is a threshold: rule applies to packets with port >= min_port\n\nPACKET FORMAT:\n \"protocol|port\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's protocol (string) and port (integer).\n 2. Parse the rule's action, protocol, and minimum port.\n 3. If the protocol matches (case-insensitive)\n AND the packet's port >= min_port, return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class FirewallRules {\n\n public static String evaluate(String rule, String packet) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String rule = sc.nextLine().trim();\n int q = Integer.parseInt(sc.nextLine().trim());\n for (int i = 0; i < q; i++) {\n String packet = sc.nextLine().trim();\n System.out.println(evaluate(rule, packet));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "DENY|TCP|1024\n3\nTCP|2000\nTCP|80\nUDP|2000", + "output": "DENY\nNO_MATCH\nNO_MATCH", + "is_hidden": false + } + ] + }, + { + "title": "FIREWALL RULE ENGINE v3.4", + "description": " == FIREWALL RULE ENGINE v3.4 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the zone-based packet filter.\nInternal zones bleed into external. Every rule was a single encoded string.\nParse the format, enforce the logic. One wrong zone and the core is exposed.\n\nRULE FORMAT:\n \"ACTION|zone|port_min-port_max\"\n ACTION is either \"ALLOW\" or \"DENY\"\n zone is a string like \"INTERNAL\", \"EXTERNAL\", \"DMZ\"\n port_min and port_max define an inclusive range\n\nPACKET FORMAT:\n \"zone|port\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's zone (string) and port (integer).\n 2. Parse the rule's action, zone, and port range.\n 3. If the zone matches (case-insensitive)\n AND the port falls within the range (inclusive), return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class FirewallRules {\n\n public static String evaluate(String rule, String packet) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String rule = sc.nextLine().trim();\n int q = Integer.parseInt(sc.nextLine().trim());\n for (int i = 0; i < q; i++) {\n String packet = sc.nextLine().trim();\n System.out.println(evaluate(rule, packet));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "ALLOW|INTERNAL|80-443\n4\nINTERNAL|80\ninternal|443\nEXTERNAL|80\nINTERNAL|8080\n", + "output": "ALLOW\nALLOW\nNO_MATCH\nNO_MATCH", + "is_hidden": false + } + ] + }, + { + "title": "DYNAMIC MEMORY ALLOCATOR v2.0", + "description": " == DYNAMIC MEMORY ALLOCATOR v2.0 ==\nSTATUS: CHAIN SEVERED BY [NULL]\n\n[NULL] corrupted the dynamic memory allocator's linked structure.\nNodes point nowhere. The chain is severed at every link.\nRebuild the node definition and the reversal engine.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndReverse(int[] values)\n\n This method must:\n 1. Build a singly linked list from the array (first element = head).\n 2. Reverse the entire linked list in-place using pointer manipulation.\n 3. Return the reversed list as a string: \"data1 -> data2 -> data3\"\n 4. Return \"EMPTY\" if the input array has no elements.", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class MemoryAllocator {\n\n // Player code goes here\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String line = sc.nextLine().trim();\n if (line.equals(\"EMPTY\")) {\n System.out.println(buildAndReverse(new int[0]));\n } else {\n String[] parts = line.split(\" \");\n int[] vals = new int[parts.length];\n for (int i = 0; i < parts.length; i++) {\n vals[i] = Integer.parseInt(parts[i]);\n }\n System.out.println(buildAndReverse(vals));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "10 20 30 40", + "output": "40 -> 30 -> 20 -> 10", + "is_hidden": false + } + ] + }, + { + "title": "DYNAMIC MEMORY ALLOCATOR v2.1", + "description": " == DYNAMIC MEMORY ALLOCATOR v2.1 ==\nSTATUS: CORRUPTED BY [NULL]\n\n[NULL] destroyed the memory chain analyzer.\nLength is unknown. The midpoint is lost.\nRebuild the node structure, count the chain, and locate the center.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndFindMiddle(int[] values)\n\n This method must:\n 1. Build a singly linked list from the array (first element = head).\n 2. Find the middle node using slow/fast pointer technique.\n For even-length lists, return the second of the two middle nodes.\n 3. Return \"LENGTH:n|MIDDLE:data\" where n is total nodes.\n 4. Return \"EMPTY\" if the input array has no elements.", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class MemoryAllocator {\n\n // Player code goes here\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String line = sc.nextLine().trim();\n if (line.equals(\"EMPTY\")) {\n System.out.println(buildAndFindMiddle(new int[0]));\n } else {\n String[] parts = line.split(\" \");\n int[] vals = new int[parts.length];\n for (int i = 0; i < parts.length; i++) {\n vals[i] = Integer.parseInt(parts[i]);\n }\n System.out.println(buildAndFindMiddle(vals));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "1 2 3 4 5", + "output": "LENGTH:5|MIDDLE:3", + "is_hidden": false + } + ] + }, + { + "title": "DYNAMIC MEMORY ALLOCATOR v2.2", + "description": " == DYNAMIC MEMORY ALLOCATOR v2.2 ==\nSTATUS: POLLUTED BY [NULL]\n\n[NULL] injected duplicate entries into the memory chain.\nRepeated allocations corrupt the heap. Duplicates must be purged.\nRebuild the chain and strip all duplicate values, keeping only first occurrences.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndDeduplicate(int[] values)\n\n This method must:\n 1. Build a singly linked list from the array.\n 2. Remove all duplicate values, keeping only the FIRST occurrence.\n 3. Return the deduplicated list as \"data1 -> data2 -> data3\".\n 4. Return \"EMPTY\" if the input array has no elements.", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class MemoryAllocator {\n\n // Player code goes here\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String line = sc.nextLine().trim();\n if (line.equals(\"EMPTY\")) {\n System.out.println(buildAndDeduplicate(new int[0]));\n } else {\n String[] parts = line.split(\" \");\n int[] vals = new int[parts.length];\n for (int i = 0; i < parts.length; i++) {\n vals[i] = Integer.parseInt(parts[i]);\n }\n System.out.println(buildAndDeduplicate(vals));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "3 1 3 2 1", + "output": "3 -> 1 -> 2", + "is_hidden": false + } + ] + }, + { + "title": "DYNAMIC MEMORY ALLOCATOR v2.3", + "description": " == DYNAMIC MEMORY ALLOCATOR v2.3 ==\nSTATUS: INFECTED BY [NULL]\n\n[NULL] planted rogue entries in the memory chain.\nA known malicious value is embedded at random positions.\nRebuild the chain and surgically remove every occurrence of the target.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndPurge(int[] values, int target)\n\n This method must:\n 1. Build a singly linked list from the array.\n 2. Remove ALL nodes whose data equals target.\n 3. Return the cleaned list as \"data1 -> data2 -> data3\".\n 4. Return \"EMPTY\" if the list is empty after purging\n (or if the input array was empty).\n", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.Scanner;\n\npublic class MemoryAllocator {\n\n // Player code goes here\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String line = sc.nextLine().trim();\n int target = Integer.parseInt(sc.nextLine().trim());\n if (line.equals(\"EMPTY\")) {\n System.out.println(buildAndPurge(new int[0], target));\n } else {\n String[] parts = line.split(\" \");\n int[] vals = new int[parts.length];\n for (int i = 0; i < parts.length; i++) {\n vals[i] = Integer.parseInt(parts[i]);\n }\n System.out.println(buildAndPurge(vals, target));\n }\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "values=[1, 9, 2, 9, 3], target=9", + "output": "1 -> 2 -> 3", + "is_hidden": false + } + ] + }, + { + "title": "SYSTEM BOOT SEQUENCER v1.0", + "description": " == SYSTEM BOOT SEQUENCER v1.0 ==\nSTATUS: SCRAMBLED BY [NULL]\n\n[NULL] scrambled the boot sequence.\nServices start before their dependencies, causing cascade failures.\nReconstruct the topological order. Every dependency must load first.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n (b must boot before a)\n\nOUTPUT:\n A single line of space-separated service numbers in valid boot order.\n When multiple services have no pending dependencies,\n boot the lowest-numbered service first.\n If a cycle makes ordering impossible, output \"CYCLE_DETECTED\".\n\nALGORITHM HINT:\n Track how many dependencies each service has (in-degree).\n Repeatedly pick the service with zero remaining dependencies,\n boot it, then reduce the count for everything that depends on it.\n If you finish and not all services were booted, there is a cycle.", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.*;\n\npublic class SystemRestore {\n\n public static String bootOrder(int numServices, int[][] deps) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numServices = Integer.parseInt(sc.nextLine().trim());\n int numDeps = Integer.parseInt(sc.nextLine().trim());\n int[][] deps = new int[numDeps][2];\n for (int i = 0; i < numDeps; i++) {\n String[] parts = sc.nextLine().trim().split(\" \");\n deps[i][0] = Integer.parseInt(parts[0]);\n deps[i][1] = Integer.parseInt(parts[1]);\n }\n System.out.println(bootOrder(numServices, deps));\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "4 services, deps 1 0 / 2 0 / 3 2", + "output": "0 1 2 3", + "is_hidden": false + } + ] + }, + { + "title": "SYSTEM BOOT SEQUENCER v1.1", + "description": " == SYSTEM BOOT SEQUENCER v1.1 ==\nSTATUS: INVERTED BY [NULL]\n\n[NULL] reversed the boot priority.\nThe system now demands highest-numbered services boot first when tied.\nReconstruct the topological order with inverted priority.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n (b must boot before a)\n\nOUTPUT:\n A single line of space-separated service numbers in valid boot order.\n When multiple services have no pending dependencies,\n boot the HIGHEST-numbered service first.\n If a cycle makes ordering impossible, output \"CYCLE_DETECTED\".\n\nEXAMPLES:\n 4 services, deps: 1->0, 2->0, 3->2\n Valid: 0 is required first (only zero-indeg node initially).\n Then 1 and 2 are free: pick 2 first (higher). Then 1, then 3.\n Boot order: 0 2 3 1\n\n 3 services, deps: 0->1, 1->2, 2->0\n Output: CYCLE_DETECTED", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.*;\n\npublic class SystemRestore {\n\n public static String bootOrder(int numServices, int[][] deps) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numServices = Integer.parseInt(sc.nextLine().trim());\n int numDeps = Integer.parseInt(sc.nextLine().trim());\n int[][] deps = new int[numDeps][2];\n for (int i = 0; i < numDeps; i++) {\n String[] parts = sc.nextLine().trim().split(\" \");\n deps[i][0] = Integer.parseInt(parts[0]);\n deps[i][1] = Integer.parseInt(parts[1]);\n }\n System.out.println(bootOrder(numServices, deps));\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "4 services, deps 1 0 / 2 0 / 3 2", + "output": "0 2 3 1", + "is_hidden": false + } + ] + }, + { + "title": "SYSTEM BOOT SEQUENCER v1.2", + "description": " == SYSTEM BOOT SEQUENCER v1.2 ==\nSTATUS: DEPTH UNKNOWN BY [NULL]\n\n[NULL] scrambled the boot sequence and erased the layer count.\nWithout knowing how deep the dependency chain goes, staged rollout is impossible.\nReconstruct the boot order AND report the number of boot layers.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n\nOUTPUT:\n Line 1: Boot order (space-separated, lowest-first tiebreak).\n Line 2: \"LAYERS:X\" where X is the number of rounds needed.\n (A round processes all currently available zero-indeg services.)\n If a cycle, output only \"CYCLE_DETECTED\".\n\nEXAMPLES:\n 4 services, deps: 1->0, 2->0, 3->2\n Round 1: boot 0. Round 2: boot 1, 2. Round 3: boot 3.\n Output:\n 0 1 2 3\n LAYERS:3\n\n 3 services, deps: 0->1, 1->2, 2->0\n Output: CYCLE_DETECTED", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.*;\n\npublic class SystemRestore {\n\n public static String bootOrder(int numServices, int[][] deps) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numServices = Integer.parseInt(sc.nextLine().trim());\n int numDeps = Integer.parseInt(sc.nextLine().trim());\n int[][] deps = new int[numDeps][2];\n for (int i = 0; i < numDeps; i++) {\n String[] parts = sc.nextLine().trim().split(\" \");\n deps[i][0] = Integer.parseInt(parts[0]);\n deps[i][1] = Integer.parseInt(parts[1]);\n }\n System.out.println(bootOrder(numServices, deps));\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "4 services, deps 1 0 / 2 0 / 3 2", + "output": "0 1 2 3\nLAYERS:3", + "is_hidden": false + } + ] + }, + { + "title": "SYSTEM SHUTDOWN SEQUENCER v1.0", + "description": " == SYSTEM SHUTDOWN SEQUENCER v1.0 ==\nSTATUS: CORRUPTED BY [NULL]\n\n[NULL] scrambled the shutdown sequence.\nServices that others depend on are killed first, crashing everything downstream.\nReconstruct the REVERSE topological order: shut down dependents first,\nthen their dependencies.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n (b must boot before a, meaning a must SHUT DOWN before b)\n\nOUTPUT:\n A single line of space-separated service numbers in valid SHUTDOWN order\n (reverse of boot order).\n When multiple services can shut down, pick the LOWEST-numbered first.\n If a cycle, output \"CYCLE_DETECTED\".\n\nEXAMPLES:\n 4 services, deps: 1->0, 2->0, 3->2\n Boot order would be: 0 1 2 3\n Shutdown order (reverse): 3 1 2 0\n (3 and 1 have no dependents; pick 1 first? No: 3 depends on 2 depends on 0,\n 1 depends on 0. Shutdown: nodes with no dependents first.\n Out-degree 0: 1, 3. Pick 1 first (lowest). Then 3. Then 2. Then 0.)\n Output: 1 3 2 0\n\n 3 services, deps: 0->1, 1->2, 2->0\n Output: CYCLE_DETECTED", + "difficulty": "Hard", + "category": "Java Systems", + "templates": { + "java": "import java.util.*;\n\npublic class SystemRestore {\n\n public static String shutdownOrder(int numServices, int[][] deps) {\n // Player code goes here\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int numServices = Integer.parseInt(sc.nextLine().trim());\n int numDeps = Integer.parseInt(sc.nextLine().trim());\n int[][] deps = new int[numDeps][2];\n for (int i = 0; i < numDeps; i++) {\n String[] parts = sc.nextLine().trim().split(\" \");\n deps[i][0] = Integer.parseInt(parts[0]);\n deps[i][1] = Integer.parseInt(parts[1]);\n }\n System.out.println(shutdownOrder(numServices, deps));\n sc.close();\n }\n}" + }, + "test_cases": [ + { + "input": "4 services, deps 1 0 / 2 0 / 3 2", + "output": "1 3 2 0", + "is_hidden": false + } + ] + } +] \ No newline at end of file diff --git a/src/scripts/data/java/theict/questions.json b/src/scripts/data/java/theict/questions.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/src/scripts/data/java/theict/questions.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/src/scripts/data/java/theict/riddles.json b/src/scripts/data/java/theict/riddles.json new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/src/scripts/data/java/theict/riddles.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/src/scripts/seeders/seed_theict_java.py b/src/scripts/seeders/seed_theict_java.py new file mode 100644 index 0000000..51eeb40 --- /dev/null +++ b/src/scripts/seeders/seed_theict_java.py @@ -0,0 +1,215 @@ +import logging +import uuid +import random +import json +import os +from datetime import datetime, timezone +from sqlalchemy import text +from sqlalchemy.orm.attributes import flag_modified +from sqlmodel import Session, select +from tqdm import tqdm +from infrastructure import engine +from models import ( + Category, Tag, Riddle, Question, Choice, Chunk, ChunkTemplate, Snippet, Expectation, Problem, TestCase +) + +logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') + +NAMESPACE = uuid.NAMESPACE_DNS + +def get_uuid(name: str) -> uuid.UUID: + """Generate a deterministic UUID based on a string name.""" + return uuid.uuid5(NAMESPACE, name) + +def load_json(filename): + # Base directory for seeding data (one level up from seeders/) + base_path = os.path.join(os.path.dirname(__file__), "..", "data", "java", "theict") + filepath = os.path.join(base_path, filename) + if not os.path.exists(filepath): + logging.warning(f"File not found: {filepath}") + return [] + with open(filepath, "r") as f: + return json.load(f) + +def seed_theict_java(): + if not engine: + logging.error("No database engine found. Skipping seeding.") + return + + # Load data from JSON files + QUESTIONS = load_json("questions.json") + RIDDLES = load_json("riddles.json") + CHUNKS = load_json("chunks.json") + PROBLEMS = load_json("problems.json") + + with Session(engine) as session: + logging.info("Starting JAV_THEICT JSON-based seeding process...") + + def get_or_create_category(name): + cat_id = get_uuid(f"cat_{name}") + cat = session.exec(select(Category).where(Category.id == cat_id)).first() + if not cat: + cat = session.exec(select(Category).where(Category.name == name)).first() + if not cat: + cat = Category(id=cat_id, name=name) + session.add(cat) + session.commit() + session.refresh(cat) + return cat + + def get_or_create_tag(name): + tag_id = get_uuid(f"tag_{name}") + tag = session.exec(select(Tag).where(Tag.id == tag_id)).first() + if not tag: + tag = session.exec(select(Tag).where(Tag.name == name)).first() + if not tag: + tag = Tag(id=tag_id, name=name) + session.add(tag) + session.commit() + session.refresh(tag) + return tag + + jav_theict_tag = get_or_create_tag("JAV_THEICT") + java_cat = get_or_create_category("Java") + + logging.info(f"Seeding {len(QUESTIONS)} Java questions...") + for q_data in tqdm(QUESTIONS, desc="Seeding Questions"): + q_id = get_uuid(f"jav_ict_q_{q_data['title']}") + if session.exec(select(Question).where(Question.id == q_id)).first(): + continue + + question = Question( + id=q_id, + title=q_data["title"], + question_text=q_data["text"], + created_at=datetime.now(timezone.utc) + ) + question.tags = [jav_theict_tag] + question.categories = [java_cat] + session.add(question) + session.flush() + + for i, (choice_text, is_correct) in enumerate(q_data["choices"]): + c_id = get_uuid(f"jav_ict_c_{q_data['title']}_{i}") + choice = Choice( + id=c_id, + question_id=question.id, + choice_text=choice_text, + is_correct=is_correct + ) + session.add(choice) + + logging.info(f"Seeding {len(RIDDLES)} Java riddles...") + for i, r_data in enumerate(tqdm(RIDDLES, desc="Seeding Riddles")): + r_id = get_uuid(f"jav_ict_r_{i}") + if session.exec(select(Riddle).where(Riddle.id == r_id)).first(): + continue + + riddle = Riddle( + id=r_id, + riddle_text=r_data["text"], + refer_char=r_data["char"], + refer_index=r_data["index"], + difficulty=r_data["difficulty"] or "Medium", + created_at=datetime.now(timezone.utc) + ) + riddle.tags = [jav_theict_tag] + session.add(riddle) + + logging.info(f"Seeding {len(CHUNKS)} Java chunks...") + for c_data in tqdm(CHUNKS, desc="Seeding Chunks"): + c_id = get_uuid(f"jav_ict_chunk_{c_data['title']}") + chunk = session.exec(select(Chunk).where(Chunk.id == c_id)).first() + if not chunk: + chunk = Chunk( + id=c_id, + title=c_data["title"], + difficulty=c_data["difficulty"], + created_at=datetime.now(timezone.utc) + ) + chunk.categories = [get_or_create_category(c_data.get("category", "Java Basics"))] + chunk.tags = [jav_theict_tag] + session.add(chunk) + session.flush() + else: + chunk.difficulty = c_data["difficulty"] + for t in chunk.templates: + session.delete(t) + session.flush() + + for lang, t_data in c_data["templates"].items(): + template = ChunkTemplate( + chunk_id=chunk.id, + language=lang, + name=t_data["name"], + template_code=t_data["template_code"], + description=t_data.get("description", f"Standard {lang} boilerplate") + ) + session.add(template) + session.flush() + + for key, content in t_data.get("snippets", {}).items(): + s = Snippet(template_id=template.id, placeholder_key=key, code_content=content) + session.add(s) + + if "expectation" in c_data: + for ex in chunk.expectations: + session.delete(ex) + session.flush() + + ex = Expectation( + chunk_id=chunk.id, + input=c_data["expectation"]["input"], + output=c_data["expectation"]["output"] + ) + session.add(ex) + + logging.info(f"Seeding {len(PROBLEMS)} Java problems...") + for p_data in tqdm(PROBLEMS, desc="Seeding Problems"): + p_id = get_uuid(f"jav_ict_prob_{p_data['title']}") + problem = session.exec(select(Problem).where(Problem.id == p_id)).first() + + if not problem: + problem = Problem( + id=p_id, + title=p_data["title"], + description=p_data["description"], + difficulty=p_data["difficulty"], + config={"templates": p_data.get("templates", {})} + ) + problem.categories = [get_or_create_category(p_data.get("category", "Java Algorithms"))] + problem.tags = [jav_theict_tag] + session.add(problem) + else: + problem.description = p_data["description"] + problem.difficulty = p_data["difficulty"] + config = problem.config or {} + config["templates"] = p_data.get("templates", {}) + problem.config = config + flag_modified(problem, "config") + session.add(problem) + + session.flush() + + if "test_cases" in p_data: + for tc in problem.test_cases: + session.delete(tc) + session.flush() + + for i, tc_data in enumerate(p_data["test_cases"]): + tc_id = get_uuid(f"jav_ict_tc_{p_data['title']}_{i}") + tc = TestCase( + id=tc_id, + problem_id=p_id, + input=str(tc_data["input"]), + output=str(tc_data["output"]), + is_hidden=tc_data.get("is_hidden", True), + sort_order=i + 1 + ) + session.add(tc) + + session.commit() + logging.info("JAV_THEICT JSON-based seeding completed successfully.") + +if __name__ == "__main__": + seed_theict_java() From c7aaada13b24b7d58ef27610ffcab26fcf96c8c2 Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Mon, 27 Apr 2026 23:53:09 +0700 Subject: [PATCH 09/10] data: refactor firewall rule engine descriptions and logic; add hidden test cases for dynamic memory allocator and system boot/shutdown sequencer --- src/scripts/data/java/theict/chunks.json | 58 ++++- src/scripts/data/java/theict/problems.json | 238 +++++++++++++++++++-- 2 files changed, 268 insertions(+), 28 deletions(-) diff --git a/src/scripts/data/java/theict/chunks.json b/src/scripts/data/java/theict/chunks.json index bcb0da1..2db9a79 100644 --- a/src/scripts/data/java/theict/chunks.json +++ b/src/scripts/data/java/theict/chunks.json @@ -3,128 +3,168 @@ "title": "L5_P4 (Chunk) Chunk 1", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] jumbled the intrusion log timestamps. Events are scattered across time. Without ordering, the forensic trail is useless. Implement the comparator, parse the entries, and format the sorted report.\n\nFill in the three tasks inside IntrusionLogger:\n- TASK 1 (compareTo): Sort LogEntry by timestamp ascending. If timestamps are equal, sort by event name alphabetically.\n- TASK 2 (buildLog): Parse each line as \"timestamp:event\" (split on \":\"). Create a LogEntry for each and return the ArrayList.\n- TASK 3 (formatReport): Sort the list with Collections.sort, then build a string where each entry is on its own line as \"[timestamp] event\". No trailing newline.\n\nInput: first line is n (number of log entries), next n lines are \"timestamp:event\" strings\nOutput: all entries sorted by timestamp (then event name for ties), one per line as \"[timestamp] event\"", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] jumbled the intrusion log timestamps.\n// Events are scattered across time. Without ordering, the forensic trail is useless.\n// Implement the comparator, sort the log, format the report.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by timestamp ascending.\n // If timestamps are equal, sort by event alphabetically.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "template_code": "import java.util.*;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by timestamp ascending.\n // If timestamps are equal, sort by event alphabetically.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.nextLine().trim());\n String[] lines = new String[n];\n for (int i = 0; i < n; i++) lines[i] = sc.nextLine().trim();\n ArrayList log = buildLog(lines);\n System.out.println(formatReport(log));\n sc.close();\n }\n}", "snippets": { "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n if (this.timestamp != other.timestamp) {\n return this.timestamp - other.timestamp;\n }\n return this.event.compareTo(other.event);\n}", "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int ts = Integer.parseInt(parts[0]);\n String ev = parts[1];\n list.add(new LogEntry(ts, ev));\n}\nreturn list;", "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"[\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" } } + }, + "expectation": { + "input": "4\n300:login\n100:scan\n200:breach\n100:alert", + "output": "[100] alert\n[100] scan\n[200] breach\n[300] login" } }, { "title": "L5_P4 (Chunk) Chunk 2", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] scrambled the alert priority queue. Critical events are buried under noise. Severity must come first. Rebuild the comparator and sorter — severity descending, then timestamp ascending for ties.\n\nFill in the three tasks inside IntrusionLogger:\n- TASK 1 (compareTo): Sort by severity DESCENDING (highest first). If severity is equal, sort by timestamp ASCENDING.\n- TASK 2 (buildLog): Parse each line as \"severity:timestamp:event\" (split on \":\"). Create a LogEntry for each.\n- TASK 3 (formatReport): Sort with Collections.sort, then format each entry as \"[severity|timestamp] event\", one per line. No trailing newline.\n\nInput: first line is n, next n lines are \"severity:timestamp:event\" strings\nOutput: entries sorted by severity descending (then timestamp ascending for ties), each as \"[severity|timestamp] event\"", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] scrambled the alert priority queue.\n// Critical events are buried under noise. Severity must come first.\n// Rebuild the sorter. Severity descending, then time ascending.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int severity;\n int timestamp;\n String event;\n\n LogEntry(int severity, int timestamp, String event) {\n this.severity = severity;\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by severity DESCENDING (highest first).\n // If severity is equal, sort by timestamp ASCENDING.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"severity:timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[severity|timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "template_code": "import java.util.*;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int severity;\n int timestamp;\n String event;\n\n LogEntry(int severity, int timestamp, String event) {\n this.severity = severity;\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by severity DESCENDING (highest first).\n // If severity is equal, sort by timestamp ASCENDING.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"severity:timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[severity|timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.nextLine().trim());\n String[] lines = new String[n];\n for (int i = 0; i < n; i++) lines[i] = sc.nextLine().trim();\n ArrayList log = buildLog(lines);\n System.out.println(formatReport(log));\n sc.close();\n }\n}", "snippets": { "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n if (this.severity != other.severity) {\n return other.severity - this.severity;\n }\n return this.timestamp - other.timestamp;\n}", "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int sev = Integer.parseInt(parts[0]);\n int ts = Integer.parseInt(parts[1]);\n String ev = parts[2];\n list.add(new LogEntry(sev, ts, ev));\n}\nreturn list;", "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"[\").append(e.severity).append(\"|\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" } } + }, + "expectation": { + "input": "4\n1:300:login\n3:100:scan\n2:200:breach\n3:150:alert", + "output": "[3|100] scan\n[3|150] alert\n[2|200] breach\n[1|300] login" } }, { "title": "L5_P4 (Chunk) Chunk 3", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] shuffled the incident categories. Events with the same name are split across the timeline. Grouping is destroyed. Rebuild the sorter — group by event name alphabetically, then show the latest events first within each group.\n\nFill in the three tasks inside IntrusionLogger:\n- TASK 1 (compareTo): Sort by event name alphabetically. If event names are equal, sort by timestamp DESCENDING (latest first).\n- TASK 2 (buildLog): Parse each line as \"timestamp:event\" (split on \":\"). Create a LogEntry for each.\n- TASK 3 (formatReport): Sort with Collections.sort, then format each entry as \"[timestamp] event\", one per line. No trailing newline.\n\nInput: first line is n, next n lines are \"timestamp:event\" strings\nOutput: entries sorted by event name alphabetically (then timestamp descending for ties), each as \"[timestamp] event\"", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] shuffled the incident categories.\n// Events with the same name are split across the timeline. Grouping is destroyed.\n// Rebuild the sorter. Group by name, latest first within each group.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by event name alphabetically.\n // If event names are equal, sort by timestamp DESCENDING (latest first).\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "template_code": "import java.util.*;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by event name alphabetically.\n // If event names are equal, sort by timestamp DESCENDING (latest first).\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"[timestamp] event\".\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.nextLine().trim());\n String[] lines = new String[n];\n for (int i = 0; i < n; i++) lines[i] = sc.nextLine().trim();\n ArrayList log = buildLog(lines);\n System.out.println(formatReport(log));\n sc.close();\n }\n}", "snippets": { "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n int cmp = this.event.compareTo(other.event);\n if (cmp != 0) return cmp;\n return other.timestamp - this.timestamp;\n}", "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int ts = Integer.parseInt(parts[0]);\n String ev = parts[1];\n list.add(new LogEntry(ts, ev));\n}\nreturn list;", "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"[\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" } } + }, + "expectation": { + "input": "4\n300:breach\n100:scan\n200:breach\n150:scan", + "output": "[300] breach\n[200] breach\n[150] scan\n[100] scan" } }, { "title": "L5_P4 (Chunk) Chunk 4", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] erased the log sequence numbers. Events exist but have no position. Without indexing, replay is impossible. Rebuild the sorter and assign sequential indexes after sorting.\n\nFill in the three tasks inside IntrusionLogger:\n- TASK 1 (compareTo): Sort by timestamp ascending. If timestamps are equal, sort by event name alphabetically.\n- TASK 2 (buildLog): Parse each line as \"timestamp:event\" (split on \":\"). Create a LogEntry for each.\n- TASK 3 (formatReport): Sort with Collections.sort, then format each entry as \"#index [timestamp] event\" where index starts at 1. One entry per line. No trailing newline.\n\nInput: first line is n, next n lines are \"timestamp:event\" strings\nOutput: entries sorted by timestamp (then event alphabetically), each prefixed with a 1-based index as \"#1 [timestamp] event\"", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] erased the log sequence numbers.\n// Events exist but have no position. Without indexing, replay is impossible.\n// Rebuild the sorter and assign sequential indexes after sorting.\n\nimport java.util.ArrayList;\nimport java.util.Collections;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by timestamp ascending.\n // If timestamps are equal, sort by event alphabetically.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"#index [timestamp] event\"\n // where index starts at 1.\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n}", + "template_code": "import java.util.*;\n\npublic class IntrusionLogger {\n\n static class LogEntry implements Comparable {\n int timestamp;\n String event;\n\n LogEntry(int timestamp, String event) {\n this.timestamp = timestamp;\n this.event = event;\n }\n\n // TASK 1: Implement compareTo.\n // Sort by timestamp ascending.\n // If timestamps are equal, sort by event alphabetically.\n {TASK 1: COMPARE TO}\n }\n\n public static ArrayList buildLog(String[] lines) {\n // TASK 2: Parse each line formatted as \"timestamp:event\".\n // Create a LogEntry for each and return the list.\n {TASK 2: PARSE ENTRIES}\n }\n\n public static String formatReport(ArrayList log) {\n // TASK 3: Sort the log using Collections.sort, then build a string.\n // Each entry on its own line as \"#index [timestamp] event\"\n // where index starts at 1.\n // Return the full string (no trailing newline).\n {TASK 3: SORT AND FORMAT}\n }\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = Integer.parseInt(sc.nextLine().trim());\n String[] lines = new String[n];\n for (int i = 0; i < n; i++) lines[i] = sc.nextLine().trim();\n ArrayList log = buildLog(lines);\n System.out.println(formatReport(log));\n sc.close();\n }\n}", "snippets": { "TASK 1: COMPARE TO": "public int compareTo(LogEntry other) {\n if (this.timestamp != other.timestamp) {\n return this.timestamp - other.timestamp;\n }\n return this.event.compareTo(other.event);\n}", "TASK 2: PARSE ENTRIES": "ArrayList list = new ArrayList<>();\nfor (String line : lines) {\n String[] parts = line.split(\":\");\n int ts = Integer.parseInt(parts[0]);\n String ev = parts[1];\n list.add(new LogEntry(ts, ev));\n}\nreturn list;", "TASK 3: SORT AND FORMAT": "Collections.sort(log);\nStringBuilder sb = new StringBuilder();\nfor (int i = 0; i < log.size(); i++) {\n LogEntry e = log.get(i);\n sb.append(\"#\").append(i + 1).append(\" [\").append(e.timestamp).append(\"] \").append(e.event);\n if (i < log.size() - 1) sb.append(\"\\n\");\n}\nreturn sb.toString();" } } + }, + "expectation": { + "input": "4\n300:login\n100:scan\n200:breach\n100:alert", + "output": "#1 [100] alert\n#2 [100] scan\n#3 [200] breach\n#4 [300] login" } }, { "title": "L5_P6 (Chunk) Chunk 1", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] overloaded the traffic shaper's queue. Packets flood in with no limit, no order, no rejection. Restore the bounded queue — capacity is law, overflow means dropped.\n\nFill in the three tasks inside TrafficShaper:\n- TASK 1 (enqueue): If queue size < capacity, add the packet to the END of the queue and return \"QUEUED\". Otherwise, increment the dropped counter and return \"DROPPED\".\n- TASK 2 (dequeue): Remove and return the packet at the FRONT of the queue. If the queue is empty, return \"IDLE\".\n- TASK 3 (status): Return the string \"SIZE:current/capacity|DROPPED:count\".", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] overloaded the traffic shaper's queue.\n// Packets flood in with no limit, no order, no rejection.\n// Restore the bounded queue. Capacity is law. Overflow means dropped.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int dropped = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end and return \"QUEUED\".\n // Otherwise, increment dropped counter and return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet.\n // If queue is empty, return \"IDLE\".\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|DROPPED:count\"\n {TASK 3: STATUS}\n }\n}", + "template_code": "import java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int dropped = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end and return \"QUEUED\".\n // Otherwise, increment dropped counter and return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet.\n // If queue is empty, return \"IDLE\".\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|DROPPED:count\"\n {TASK 3: STATUS}\n }\n\n public static void main(String[] args) {\n init(3);\n System.out.println(enqueue(\"PKT-A\"));\n System.out.println(enqueue(\"PKT-B\"));\n System.out.println(enqueue(\"PKT-C\"));\n System.out.println(enqueue(\"PKT-D\"));\n System.out.println(status());\n System.out.println(dequeue());\n System.out.println(status());\n }\n}", "snippets": { "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n queue.addLast(packet);\n return \"QUEUED\";\n} else {\n dropped++;\n return \"DROPPED\";\n}", "TASK 2: DEQUEUE": "if (queue.isEmpty()) return \"IDLE\";\nreturn queue.removeFirst();", "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|DROPPED:\" + dropped;" } } + }, + "expectation": { + "input": "", + "output": "QUEUED\nQUEUED\nQUEUED\nDROPPED\nSIZE:3/3|DROPPED:1\nPKT-A\nSIZE:2/3|DROPPED:1" } }, { "title": "L5_P6 (Chunk) Chunk 2", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] disabled the traffic meter. Packets flow but nothing tracks throughput. The processed count is always zero. Restore the queue and track every successful dequeue.\n\nFill in the three tasks inside TrafficShaper:\n- TASK 1 (enqueue): If queue size < capacity, add packet to the END and return \"QUEUED\". Otherwise return \"DROPPED\" (do NOT increment anything).\n- TASK 2 (dequeue): Remove and return the front packet, and increment the processed counter. If queue is empty, return \"IDLE\" (do NOT increment processed).\n- TASK 3 (status): Return the string \"SIZE:current/capacity|PROCESSED:count\".", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] disabled the traffic meter.\n// Packets flow but nothing tracks throughput. Processed count is zero.\n// Restore the queue and track every successful dequeue.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int processed = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end and return \"QUEUED\".\n // Otherwise, return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet, and increment processed counter.\n // If queue is empty, return \"IDLE\" (do NOT increment processed).\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|PROCESSED:count\"\n {TASK 3: STATUS}\n }\n}", + "template_code": "import java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int processed = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end and return \"QUEUED\".\n // Otherwise, return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet, and increment processed counter.\n // If queue is empty, return \"IDLE\" (do NOT increment processed).\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|PROCESSED:count\"\n {TASK 3: STATUS}\n }\n\n public static void main(String[] args) {\n init(3);\n System.out.println(enqueue(\"PKT-A\"));\n System.out.println(enqueue(\"PKT-B\"));\n System.out.println(enqueue(\"PKT-C\"));\n System.out.println(dequeue());\n System.out.println(dequeue());\n System.out.println(status());\n }\n}", "snippets": { "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n queue.addLast(packet);\n return \"QUEUED\";\n} else {\n return \"DROPPED\";\n}", "TASK 2: DEQUEUE": "if (queue.isEmpty()) return \"IDLE\";\nprocessed++;\nreturn queue.removeFirst();", "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|PROCESSED:\" + processed;" } } + }, + "expectation": { + "input": "", + "output": "QUEUED\nQUEUED\nQUEUED\nPKT-A\nPKT-B\nSIZE:1/3|PROCESSED:2" } }, { "title": "L5_P6 (Chunk) Chunk 3", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] broke the priority lane in the traffic shaper. VIP packets wait in line like everyone else. The fast lane is dead. Restore priority enqueue — VIP goes to the front, normal to the back.\n\nFill in the three tasks inside TrafficShaper:\n- TASK 1 (enqueue with priority flag): If queue size < capacity, add the packet to the FRONT if priority is true (return \"PRIORITY_QUEUED\") or to the END if priority is false (return \"QUEUED\"). If full, increment dropped and return \"DROPPED\".\n- TASK 2 (dequeue): Remove and return the front packet. Return \"IDLE\" if empty.\n- TASK 3 (status): Return \"SIZE:current/capacity|DROPPED:count\".", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] broke the priority lane in the traffic shaper.\n// VIP packets wait in line like everyone else. The fast lane is dead.\n// Restore priority enqueue. VIP goes to the front, normal to the back.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int dropped = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet, boolean priority) {\n // TASK 1: If queue size < capacity:\n // - If priority is true, add packet to the FRONT and return \"PRIORITY_QUEUED\".\n // - If priority is false, add packet to the END and return \"QUEUED\".\n // If queue is full, increment dropped and return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet.\n // If queue is empty, return \"IDLE\".\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|DROPPED:count\"\n {TASK 3: STATUS}\n }\n}", + "template_code": "import java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int dropped = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet, boolean priority) {\n // TASK 1: If queue size < capacity:\n // - If priority is true, add packet to the FRONT and return \"PRIORITY_QUEUED\".\n // - If priority is false, add packet to the END and return \"QUEUED\".\n // If queue is full, increment dropped and return \"DROPPED\".\n {TASK 1: ENQUEUE}\n }\n\n public static String dequeue() {\n // TASK 2: Remove and return the front packet.\n // If queue is empty, return \"IDLE\".\n {TASK 2: DEQUEUE}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|DROPPED:count\"\n {TASK 3: STATUS}\n }\n\n public static void main(String[] args) {\n init(4);\n System.out.println(enqueue(\"PKT-A\", false));\n System.out.println(enqueue(\"PKT-B\", false));\n System.out.println(enqueue(\"VIP-1\", true));\n System.out.println(dequeue());\n System.out.println(status());\n }\n}", "snippets": { "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n if (priority) {\n queue.addFirst(packet);\n return \"PRIORITY_QUEUED\";\n } else {\n queue.addLast(packet);\n return \"QUEUED\";\n }\n} else {\n dropped++;\n return \"DROPPED\";\n}", "TASK 2: DEQUEUE": "if (queue.isEmpty()) return \"IDLE\";\nreturn queue.removeFirst();", "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|DROPPED:\" + dropped;" } } + }, + "expectation": { + "input": "", + "output": "QUEUED\nQUEUED\nPRIORITY_QUEUED\nVIP-1\nSIZE:2/4|DROPPED:0" } }, { "title": "L5_P6 (Chunk) Chunk 4", "difficulty": "Hard", "category": "Java Architecture", + "description": "[NULL] wiped the traffic shaper's inspection tools. Packets enter the queue but there is no way to inspect them without consuming. Restore the queue with non-destructive peek and lifetime tracking.\n\nFill in the three tasks inside TrafficShaper:\n- TASK 1 (enqueue): If queue size < capacity, add packet to the END, increment totalEnqueued, and return \"QUEUED\". If full, return \"DROPPED\" (do NOT increment totalEnqueued).\n- TASK 2 (peek): Return the packet at the FRONT without removing it. Return \"IDLE\" if empty.\n- TASK 3 (status): Return \"SIZE:current/capacity|TOTAL:totalEnqueued\".", "templates": { "java": { "name": "Java Template", - "template_code": "// [NULL] wiped the traffic shaper's inspection tools.\n// Packets enter the queue but there is no way to inspect without consuming.\n// Restore the queue with peek and lifetime tracking.\n\nimport java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int totalEnqueued = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end,\n // increment totalEnqueued, and return \"QUEUED\".\n // Otherwise, return \"DROPPED\" (do NOT increment totalEnqueued).\n {TASK 1: ENQUEUE}\n }\n\n public static String peek() {\n // TASK 2: Return the front packet WITHOUT removing it.\n // If queue is empty, return \"IDLE\".\n {TASK 2: PEEK}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|TOTAL:totalEnqueued\"\n {TASK 3: STATUS}\n }\n}", + "template_code": "import java.util.LinkedList;\n\npublic class TrafficShaper {\n\n static LinkedList queue = new LinkedList<>();\n static int capacity;\n static int totalEnqueued = 0;\n\n public static void init(int cap) { capacity = cap; }\n\n public static String enqueue(String packet) {\n // TASK 1: If queue size < capacity, add packet to the end,\n // increment totalEnqueued, and return \"QUEUED\".\n // Otherwise, return \"DROPPED\" (do NOT increment totalEnqueued).\n {TASK 1: ENQUEUE}\n }\n\n public static String peek() {\n // TASK 2: Return the front packet WITHOUT removing it.\n // If queue is empty, return \"IDLE\".\n {TASK 2: PEEK}\n }\n\n public static String status() {\n // TASK 3: Return \"SIZE:current/capacity|TOTAL:totalEnqueued\"\n {TASK 3: STATUS}\n }\n\n public static void main(String[] args) {\n init(2);\n System.out.println(enqueue(\"PKT-A\"));\n System.out.println(enqueue(\"PKT-B\"));\n System.out.println(enqueue(\"PKT-C\"));\n System.out.println(peek());\n System.out.println(status());\n }\n}", "snippets": { "TASK 1: ENQUEUE": "if (queue.size() < capacity) {\n queue.addLast(packet);\n totalEnqueued++;\n return \"QUEUED\";\n} else {\n return \"DROPPED\";\n}", "TASK 2: PEEK": "if (queue.isEmpty()) return \"IDLE\";\nreturn queue.getFirst();", "TASK 3: STATUS": "return \"SIZE:\" + queue.size() + \"/\" + capacity + \"|TOTAL:\" + totalEnqueued;" } } + }, + "expectation": { + "input": "", + "output": "QUEUED\nQUEUED\nDROPPED\nPKT-A\nSIZE:2/2|TOTAL:2" } } -] \ No newline at end of file +] diff --git a/src/scripts/data/java/theict/problems.json b/src/scripts/data/java/theict/problems.json index ed0901b..024f8b9 100644 --- a/src/scripts/data/java/theict/problems.json +++ b/src/scripts/data/java/theict/problems.json @@ -1,7 +1,7 @@ [ { "title": "FIREWALL RULE ENGINE v3.1", - "description": " == FIREWALL RULE ENGINE v3.1 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the firewall's rule engine.\nPackets flow unchecked. Every rule was a single encoded string.\nParse the format, enforce the logic. One misread and the breach widens.\n\nRULE FORMAT:\n \"ACTION|port_min-port_max|protocol\"\n ACTION is either \"ALLOW\" or \"DENY\"\n port_min and port_max define an inclusive range\n protocol is a string like \"TCP\" or \"UDP\"\n\nPACKET FORMAT:\n \"port|protocol\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's port as an integer and its protocol as a string.\n 2. Parse the rule's action, port range, and protocol.\n 3. If the packet's port falls within the range (inclusive)\n AND the protocol matches (case-insensitive), return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "description": "== FIREWALL RULE ENGINE v3.1 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the firewall's rule engine. Packets flow unchecked. Restore it.\n\nRULE FORMAT: \"ACTION|port_min-port_max|protocol\"\n - ACTION is \"ALLOW\" or \"DENY\"\n - port_min and port_max define an inclusive range\n - protocol is a string like \"TCP\" or \"UDP\"\n\nPACKET FORMAT: \"port|protocol\"\n\nLOGIC: If the packet's port is within [port_min, port_max] AND the protocol matches (case-insensitive), return the ACTION. Otherwise return \"NO_MATCH\".\n\nInput: line 1 is the rule string, line 2 is Q (number of packets), next Q lines are packet strings\nOutput: Q lines, each with the result for that packet", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -12,12 +12,27 @@ "input": "ALLOW|80-443|TCP\n4\n80|TCP\n443|tcp\n8080|TCP\n80|UDP", "output": "ALLOW\nALLOW\nNO_MATCH\nNO_MATCH", "is_hidden": false + }, + { + "input": "DENY|22-22|SSH\n2\n22|SSH\n23|SSH", + "output": "DENY\nNO_MATCH", + "is_hidden": true + }, + { + "input": "ALLOW|1000-2000|UDP\n3\n1000|UDP\n2000|udp\n999|UDP", + "output": "ALLOW\nALLOW\nNO_MATCH", + "is_hidden": true + }, + { + "input": "DENY|0-65535|TCP\n2\n8080|TCP\n8080|UDP", + "output": "DENY\nNO_MATCH", + "is_hidden": true } ] }, { "title": "FIREWALL RULE ENGINE v3.2", - "description": " == FIREWALL RULE ENGINE v3.2 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the firewall's IP-based rule engine.\nTraffic flows unfiltered. Every rule was a single encoded string.\nParse the format, enforce the logic. One wrong IP and the whole floor is exposed.\n\nRULE FORMAT:\n \"ACTION|ip_prefix|port\"\n ACTION is either \"ALLOW\" or \"DENY\"\n ip_prefix is a partial IP like \"192.168\" (match if packet IP starts with this)\n port is an exact port number\n\nPACKET FORMAT:\n \"ip_address|port\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's IP address (string) and port (integer).\n 2. Parse the rule's action, IP prefix, and port.\n 3. If the packet's IP starts with the rule's ip_prefix\n AND the port matches exactly, return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "description": "== FIREWALL RULE ENGINE v3.2 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the IP-based rule engine. Traffic flows unfiltered. Restore it.\n\nRULE FORMAT: \"ACTION|ip_prefix|port\"\n - ACTION is \"ALLOW\" or \"DENY\"\n - ip_prefix is a partial IP like \"192.168\" — a packet IP matches if it STARTS WITH this string\n - port is an exact port number\n\nPACKET FORMAT: \"ip_address|port\"\n\nLOGIC: If the packet's IP starts with ip_prefix AND the port matches exactly, return the ACTION. Otherwise return \"NO_MATCH\".\n\nNote: prefix matching is a plain string prefix check — \"192.168.10\" also matches \"192.168.100.x\".\n\nInput: line 1 is the rule string, line 2 is Q (number of packets), next Q lines are packet strings\nOutput: Q lines, each with the result for that packet", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -28,12 +43,27 @@ "input": "ALLOW|192.168|8080\n3\n192.168.1.5|8080\n192.168.0.1|3000\n10.0.0.1|8080", "output": "ALLOW\nNO_MATCH\nNO_MATCH", "is_hidden": false + }, + { + "input": "DENY|10.0.0|443\n2\n10.0.0.5|443\n10.0.1.5|443", + "output": "DENY\nNO_MATCH", + "is_hidden": true + }, + { + "input": "ALLOW|192.168.10|80\n2\n192.168.100.1|80\n192.168.10.1|80", + "output": "ALLOW\nALLOW", + "is_hidden": true + }, + { + "input": "DENY|172.16|22\n2\n172.16.5.10|22\n172.16.5.10|23", + "output": "DENY\nNO_MATCH", + "is_hidden": true } ] }, { "title": "FIREWALL RULE ENGINE v3.3", - "description": " == FIREWALL RULE ENGINE v3.3 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the outbound traffic filter.\nEvery packet escapes unchecked. Rules encoded as single strings are all that remain.\nParse the format, enforce the logic. The building leaks data with every second.\n\nRULE FORMAT:\n \"ACTION|protocol|min_port\"\n ACTION is either \"ALLOW\" or \"DENY\"\n protocol is a string like \"TCP\", \"UDP\", \"ICMP\"\n min_port is a threshold: rule applies to packets with port >= min_port\n\nPACKET FORMAT:\n \"protocol|port\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's protocol (string) and port (integer).\n 2. Parse the rule's action, protocol, and minimum port.\n 3. If the protocol matches (case-insensitive)\n AND the packet's port >= min_port, return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "description": "== FIREWALL RULE ENGINE v3.3 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the outbound traffic filter. Every packet escapes unchecked. Restore it.\n\nRULE FORMAT: \"ACTION|protocol|min_port\"\n - ACTION is \"ALLOW\" or \"DENY\"\n - protocol is a string like \"TCP\", \"UDP\", \"ICMP\"\n - min_port is a threshold — the rule applies to packets with port >= min_port\n\nPACKET FORMAT: \"protocol|port\"\n\nLOGIC: If the protocol matches (case-insensitive) AND the packet's port >= min_port, return the ACTION. Otherwise return \"NO_MATCH\".\n\nInput: line 1 is the rule string, line 2 is Q (number of packets), next Q lines are packet strings\nOutput: Q lines, each with the result for that packet", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -44,12 +74,27 @@ "input": "DENY|TCP|1024\n3\nTCP|2000\nTCP|80\nUDP|2000", "output": "DENY\nNO_MATCH\nNO_MATCH", "is_hidden": false + }, + { + "input": "DENY|UDP|1024\n3\nUDP|1024\nUDP|1023\nTCP|2000", + "output": "DENY\nNO_MATCH\nNO_MATCH", + "is_hidden": true + }, + { + "input": "ALLOW|ICMP|0\n2\nicmp|1\nTCP|0", + "output": "ALLOW\nNO_MATCH", + "is_hidden": true + }, + { + "input": "ALLOW|TCP|443\n3\ntcp|443\ntcp|442\nUDP|500", + "output": "ALLOW\nNO_MATCH\nNO_MATCH", + "is_hidden": true } ] }, { "title": "FIREWALL RULE ENGINE v3.4", - "description": " == FIREWALL RULE ENGINE v3.4 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the zone-based packet filter.\nInternal zones bleed into external. Every rule was a single encoded string.\nParse the format, enforce the logic. One wrong zone and the core is exposed.\n\nRULE FORMAT:\n \"ACTION|zone|port_min-port_max\"\n ACTION is either \"ALLOW\" or \"DENY\"\n zone is a string like \"INTERNAL\", \"EXTERNAL\", \"DMZ\"\n port_min and port_max define an inclusive range\n\nPACKET FORMAT:\n \"zone|port\"\n\nEVALUATION LOGIC:\n 1. Parse the packet's zone (string) and port (integer).\n 2. Parse the rule's action, zone, and port range.\n 3. If the zone matches (case-insensitive)\n AND the port falls within the range (inclusive), return the action.\n 4. Otherwise, return \"NO_MATCH\".", + "description": "== FIREWALL RULE ENGINE v3.4 ==\nSTATUS: WIPED BY [NULL]\n\n[NULL] erased the zone-based packet filter. Internal zones bleed into external. Restore it.\n\nRULE FORMAT: \"ACTION|zone|port_min-port_max\"\n - ACTION is \"ALLOW\" or \"DENY\"\n - zone is a string like \"INTERNAL\", \"EXTERNAL\", \"DMZ\"\n - port_min and port_max define an inclusive port range\n\nPACKET FORMAT: \"zone|port\"\n\nLOGIC: If the zone matches (case-insensitive) AND the port is within [port_min, port_max], return the ACTION. Otherwise return \"NO_MATCH\".\n\nInput: line 1 is the rule string, line 2 is Q (number of packets), next Q lines are packet strings\nOutput: Q lines, each with the result for that packet", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -57,15 +102,30 @@ }, "test_cases": [ { - "input": "ALLOW|INTERNAL|80-443\n4\nINTERNAL|80\ninternal|443\nEXTERNAL|80\nINTERNAL|8080\n", + "input": "ALLOW|INTERNAL|80-443\n4\nINTERNAL|80\ninternal|443\nEXTERNAL|80\nINTERNAL|8080", "output": "ALLOW\nALLOW\nNO_MATCH\nNO_MATCH", "is_hidden": false + }, + { + "input": "DENY|DMZ|8000-9000\n3\ndmz|8000\nDMZ|9001\nINTERNAL|8500", + "output": "DENY\nNO_MATCH\nNO_MATCH", + "is_hidden": true + }, + { + "input": "ALLOW|EXTERNAL|443-443\n2\nexternal|443\nexternal|442", + "output": "ALLOW\nNO_MATCH", + "is_hidden": true + }, + { + "input": "DENY|INTERNAL|0-65535\n3\nINTERNAL|1\nEXTERNAL|1\ninternal|65535", + "output": "DENY\nNO_MATCH\nDENY", + "is_hidden": true } ] }, { "title": "DYNAMIC MEMORY ALLOCATOR v2.0", - "description": " == DYNAMIC MEMORY ALLOCATOR v2.0 ==\nSTATUS: CHAIN SEVERED BY [NULL]\n\n[NULL] corrupted the dynamic memory allocator's linked structure.\nNodes point nowhere. The chain is severed at every link.\nRebuild the node definition and the reversal engine.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndReverse(int[] values)\n\n This method must:\n 1. Build a singly linked list from the array (first element = head).\n 2. Reverse the entire linked list in-place using pointer manipulation.\n 3. Return the reversed list as a string: \"data1 -> data2 -> data3\"\n 4. Return \"EMPTY\" if the input array has no elements.", + "description": "== DYNAMIC MEMORY ALLOCATOR v2.0 ==\nSTATUS: CHAIN SEVERED BY [NULL]\n\n[NULL] corrupted the dynamic memory allocator's linked structure. Rebuild the node definition and the reversal engine.\n\nRequirements:\n1. Define a static inner class \"Node\" inside MemoryAllocator with: an int field \"data\", a Node field \"next\", and a constructor that takes an int and sets next to null.\n2. Implement: public static String buildAndReverse(int[] values)\n - Build a singly linked list from the array (first element = head).\n - Reverse the entire list in-place using pointer manipulation (no extra collections).\n - Return the reversed list as \"data1 -> data2 -> data3\".\n - Return \"EMPTY\" if the input array has no elements.\n\nInput: a single line of space-separated integers, or the word \"EMPTY\" for an empty list\nOutput: the reversed linked list as a string, or \"EMPTY\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -76,12 +136,32 @@ "input": "10 20 30 40", "output": "40 -> 30 -> 20 -> 10", "is_hidden": false + }, + { + "input": "EMPTY", + "output": "EMPTY", + "is_hidden": true + }, + { + "input": "7", + "output": "7", + "is_hidden": true + }, + { + "input": "1 2", + "output": "2 -> 1", + "is_hidden": true + }, + { + "input": "5 4 3 2 1", + "output": "1 -> 2 -> 3 -> 4 -> 5", + "is_hidden": true } ] }, { "title": "DYNAMIC MEMORY ALLOCATOR v2.1", - "description": " == DYNAMIC MEMORY ALLOCATOR v2.1 ==\nSTATUS: CORRUPTED BY [NULL]\n\n[NULL] destroyed the memory chain analyzer.\nLength is unknown. The midpoint is lost.\nRebuild the node structure, count the chain, and locate the center.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndFindMiddle(int[] values)\n\n This method must:\n 1. Build a singly linked list from the array (first element = head).\n 2. Find the middle node using slow/fast pointer technique.\n For even-length lists, return the second of the two middle nodes.\n 3. Return \"LENGTH:n|MIDDLE:data\" where n is total nodes.\n 4. Return \"EMPTY\" if the input array has no elements.", + "description": "== DYNAMIC MEMORY ALLOCATOR v2.1 ==\nSTATUS: CORRUPTED BY [NULL]\n\n[NULL] destroyed the memory chain analyzer. Length is unknown and the midpoint is lost. Rebuild the chain, count it, and locate the center.\n\nRequirements:\n1. Define a static inner class \"Node\" inside MemoryAllocator with: an int field \"data\", a Node field \"next\", and a constructor that takes an int and sets next to null.\n2. Implement: public static String buildAndFindMiddle(int[] values)\n - Build a singly linked list from the array.\n - Find the middle node using the slow/fast pointer technique.\n For even-length lists, return the SECOND of the two middle nodes.\n - Return \"LENGTH:n|MIDDLE:data\" where n is the total number of nodes.\n - Return \"EMPTY\" if the input array has no elements.\n\nInput: a single line of space-separated integers, or the word \"EMPTY\" for an empty list\nOutput: \"LENGTH:n|MIDDLE:data\" or \"EMPTY\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -92,12 +172,32 @@ "input": "1 2 3 4 5", "output": "LENGTH:5|MIDDLE:3", "is_hidden": false + }, + { + "input": "EMPTY", + "output": "EMPTY", + "is_hidden": true + }, + { + "input": "42", + "output": "LENGTH:1|MIDDLE:42", + "is_hidden": true + }, + { + "input": "1 2 3 4", + "output": "LENGTH:4|MIDDLE:3", + "is_hidden": true + }, + { + "input": "10 20 30 40 50 60", + "output": "LENGTH:6|MIDDLE:40", + "is_hidden": true } ] }, { "title": "DYNAMIC MEMORY ALLOCATOR v2.2", - "description": " == DYNAMIC MEMORY ALLOCATOR v2.2 ==\nSTATUS: POLLUTED BY [NULL]\n\n[NULL] injected duplicate entries into the memory chain.\nRepeated allocations corrupt the heap. Duplicates must be purged.\nRebuild the chain and strip all duplicate values, keeping only first occurrences.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndDeduplicate(int[] values)\n\n This method must:\n 1. Build a singly linked list from the array.\n 2. Remove all duplicate values, keeping only the FIRST occurrence.\n 3. Return the deduplicated list as \"data1 -> data2 -> data3\".\n 4. Return \"EMPTY\" if the input array has no elements.", + "description": "== DYNAMIC MEMORY ALLOCATOR v2.2 ==\nSTATUS: POLLUTED BY [NULL]\n\n[NULL] injected duplicate entries into the memory chain. Repeated allocations corrupt the heap. Rebuild the chain and strip all duplicates, keeping only the first occurrence of each value.\n\nRequirements:\n1. Define a static inner class \"Node\" inside MemoryAllocator with: an int field \"data\", a Node field \"next\", and a constructor that takes an int and sets next to null.\n2. Implement: public static String buildAndDeduplicate(int[] values)\n - Build a singly linked list from the array.\n - Remove all duplicate values, keeping only the FIRST occurrence of each.\n - Return the deduplicated list as \"data1 -> data2 -> data3\".\n - Return \"EMPTY\" if the input array has no elements.\n\nInput: a single line of space-separated integers, or the word \"EMPTY\" for an empty list\nOutput: deduplicated linked list as a string, or \"EMPTY\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -108,12 +208,32 @@ "input": "3 1 3 2 1", "output": "3 -> 1 -> 2", "is_hidden": false + }, + { + "input": "EMPTY", + "output": "EMPTY", + "is_hidden": true + }, + { + "input": "1 1 1", + "output": "1", + "is_hidden": true + }, + { + "input": "1 2 3", + "output": "1 -> 2 -> 3", + "is_hidden": true + }, + { + "input": "5 3 5 3 5", + "output": "5 -> 3", + "is_hidden": true } ] }, { "title": "DYNAMIC MEMORY ALLOCATOR v2.3", - "description": " == DYNAMIC MEMORY ALLOCATOR v2.3 ==\nSTATUS: INFECTED BY [NULL]\n\n[NULL] planted rogue entries in the memory chain.\nA known malicious value is embedded at random positions.\nRebuild the chain and surgically remove every occurrence of the target.\n\nREQUIREMENTS:\n Define a static inner class \"Node\" inside MemoryAllocator with:\n - an int field \"data\"\n - a Node field \"next\"\n - a constructor that takes an int and sets next to null\n\n Then write a static method:\n public static String buildAndPurge(int[] values, int target)\n\n This method must:\n 1. Build a singly linked list from the array.\n 2. Remove ALL nodes whose data equals target.\n 3. Return the cleaned list as \"data1 -> data2 -> data3\".\n 4. Return \"EMPTY\" if the list is empty after purging\n (or if the input array was empty).\n", + "description": "== DYNAMIC MEMORY ALLOCATOR v2.3 ==\nSTATUS: INFECTED BY [NULL]\n\n[NULL] planted rogue entries in the memory chain. A known malicious value is embedded at random positions. Rebuild the chain and surgically remove every occurrence of the target.\n\nRequirements:\n1. Define a static inner class \"Node\" inside MemoryAllocator with: an int field \"data\", a Node field \"next\", and a constructor that takes an int and sets next to null.\n2. Implement: public static String buildAndPurge(int[] values, int target)\n - Build a singly linked list from the array.\n - Remove ALL nodes whose data equals target.\n - Return the cleaned list as \"data1 -> data2 -> data3\".\n - Return \"EMPTY\" if the list is empty after purging (or if the input was empty).\n\nInput: line 1 is a space-separated list of integers, or \"EMPTY\" for an empty list; line 2 is the target integer to remove\nOutput: purged linked list as a string, or \"EMPTY\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -121,15 +241,35 @@ }, "test_cases": [ { - "input": "values=[1, 9, 2, 9, 3], target=9", + "input": "1 9 2 9 3\n9", "output": "1 -> 2 -> 3", "is_hidden": false + }, + { + "input": "5 5 5\n5", + "output": "EMPTY", + "is_hidden": true + }, + { + "input": "1 2 3 4 5\n6", + "output": "1 -> 2 -> 3 -> 4 -> 5", + "is_hidden": true + }, + { + "input": "7\n7", + "output": "EMPTY", + "is_hidden": true + }, + { + "input": "3 1 4 1 5\n1", + "output": "3 -> 4 -> 5", + "is_hidden": true } ] }, { "title": "SYSTEM BOOT SEQUENCER v1.0", - "description": " == SYSTEM BOOT SEQUENCER v1.0 ==\nSTATUS: SCRAMBLED BY [NULL]\n\n[NULL] scrambled the boot sequence.\nServices start before their dependencies, causing cascade failures.\nReconstruct the topological order. Every dependency must load first.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n (b must boot before a)\n\nOUTPUT:\n A single line of space-separated service numbers in valid boot order.\n When multiple services have no pending dependencies,\n boot the lowest-numbered service first.\n If a cycle makes ordering impossible, output \"CYCLE_DETECTED\".\n\nALGORITHM HINT:\n Track how many dependencies each service has (in-degree).\n Repeatedly pick the service with zero remaining dependencies,\n boot it, then reduce the count for everything that depends on it.\n If you finish and not all services were booted, there is a cycle.", + "description": "== SYSTEM BOOT SEQUENCER v1.0 ==\nSTATUS: SCRAMBLED BY [NULL]\n\n[NULL] scrambled the boot sequence. Services start before their dependencies, causing cascade failures. Reconstruct the topological order — every dependency must load first.\n\nImplement bootOrder(int numServices, int[][] deps) using Kahn's algorithm (BFS-based topological sort):\n- Track how many unresolved dependencies each service has (in-degree).\n- Use a min-priority queue so that when multiple services are ready, the LOWEST-numbered boots first.\n- Remove each booted service from others' dependency counts.\n- If not all services were booted, there is a cycle — return \"CYCLE_DETECTED\".\n- Otherwise return a space-separated boot order.\n\nInput: line 1 = N (number of services, labeled 0 to N-1), line 2 = M (number of dependency pairs), next M lines = \"a b\" meaning service a depends on service b (b boots before a)\nOutput: space-separated boot order, or \"CYCLE_DETECTED\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -137,15 +277,30 @@ }, "test_cases": [ { - "input": "4 services, deps 1 0 / 2 0 / 3 2", + "input": "4\n3\n1 0\n2 0\n3 2", "output": "0 1 2 3", "is_hidden": false + }, + { + "input": "3\n3\n0 1\n1 2\n2 0", + "output": "CYCLE_DETECTED", + "is_hidden": true + }, + { + "input": "3\n0", + "output": "0 1 2", + "is_hidden": true + }, + { + "input": "5\n4\n1 0\n2 0\n3 1\n4 2", + "output": "0 1 2 3 4", + "is_hidden": true } ] }, { "title": "SYSTEM BOOT SEQUENCER v1.1", - "description": " == SYSTEM BOOT SEQUENCER v1.1 ==\nSTATUS: INVERTED BY [NULL]\n\n[NULL] reversed the boot priority.\nThe system now demands highest-numbered services boot first when tied.\nReconstruct the topological order with inverted priority.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n (b must boot before a)\n\nOUTPUT:\n A single line of space-separated service numbers in valid boot order.\n When multiple services have no pending dependencies,\n boot the HIGHEST-numbered service first.\n If a cycle makes ordering impossible, output \"CYCLE_DETECTED\".\n\nEXAMPLES:\n 4 services, deps: 1->0, 2->0, 3->2\n Valid: 0 is required first (only zero-indeg node initially).\n Then 1 and 2 are free: pick 2 first (higher). Then 1, then 3.\n Boot order: 0 2 3 1\n\n 3 services, deps: 0->1, 1->2, 2->0\n Output: CYCLE_DETECTED", + "description": "== SYSTEM BOOT SEQUENCER v1.1 ==\nSTATUS: INVERTED BY [NULL]\n\n[NULL] reversed the boot priority. The system now demands the highest-numbered service boots first when multiple are ready. Reconstruct the topological order with inverted priority.\n\nImplement bootOrder(int numServices, int[][] deps) — same logic as v1.0 but use a MAX-priority queue so that when multiple services are ready at the same time, the HIGHEST-numbered boots first.\n\nExample: 4 services, deps: 1→0, 2→0, 3→2\n- Only 0 is ready first. Boot 0.\n- Both 1 and 2 become ready. Pick 2 (highest). Boot 2.\n- Both 1 and 3 become ready. Pick 3 (highest). Boot 3.\n- Only 1 remains. Boot 1.\n- Result: 0 2 3 1\n\nInput: line 1 = N (number of services), line 2 = M (dependency pairs), next M lines = \"a b\" (a depends on b)\nOutput: space-separated boot order (highest-first tiebreak), or \"CYCLE_DETECTED\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -153,15 +308,30 @@ }, "test_cases": [ { - "input": "4 services, deps 1 0 / 2 0 / 3 2", + "input": "4\n3\n1 0\n2 0\n3 2", "output": "0 2 3 1", "is_hidden": false + }, + { + "input": "3\n3\n0 1\n1 2\n2 0", + "output": "CYCLE_DETECTED", + "is_hidden": true + }, + { + "input": "3\n0", + "output": "2 1 0", + "is_hidden": true + }, + { + "input": "5\n4\n1 0\n2 0\n3 1\n4 2", + "output": "0 2 1 4 3", + "is_hidden": true } ] }, { "title": "SYSTEM BOOT SEQUENCER v1.2", - "description": " == SYSTEM BOOT SEQUENCER v1.2 ==\nSTATUS: DEPTH UNKNOWN BY [NULL]\n\n[NULL] scrambled the boot sequence and erased the layer count.\nWithout knowing how deep the dependency chain goes, staged rollout is impossible.\nReconstruct the boot order AND report the number of boot layers.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n\nOUTPUT:\n Line 1: Boot order (space-separated, lowest-first tiebreak).\n Line 2: \"LAYERS:X\" where X is the number of rounds needed.\n (A round processes all currently available zero-indeg services.)\n If a cycle, output only \"CYCLE_DETECTED\".\n\nEXAMPLES:\n 4 services, deps: 1->0, 2->0, 3->2\n Round 1: boot 0. Round 2: boot 1, 2. Round 3: boot 3.\n Output:\n 0 1 2 3\n LAYERS:3\n\n 3 services, deps: 0->1, 1->2, 2->0\n Output: CYCLE_DETECTED", + "description": "== SYSTEM BOOT SEQUENCER v1.2 ==\nSTATUS: DEPTH UNKNOWN BY [NULL]\n\n[NULL] scrambled the boot sequence and erased the layer count. Without knowing how deep the dependency chain goes, staged rollout is impossible. Reconstruct the boot order AND report the number of boot layers.\n\nImplement bootOrder(int numServices, int[][] deps) — same as v1.0 (lowest-first tiebreak) but process all currently-ready services in one round (one layer) before starting the next:\n- Round 1: boot all services with no dependencies, smallest first.\n- Round 2: boot all newly-unblocked services, smallest first. Etc.\n- Return two lines: boot order (all services space-separated) then \"LAYERS:X\".\n- If a cycle exists, return only \"CYCLE_DETECTED\".\n\nExample: 4 services, deps: 1→0, 2→0, 3→2\n- Round 1: [0]. Round 2: [1, 2]. Round 3: [3]. → \"0 1 2 3\\nLAYERS:3\"\n\nInput: line 1 = N, line 2 = M, next M lines = \"a b\" (a depends on b)\nOutput: space-separated boot order on line 1, \"LAYERS:X\" on line 2, or just \"CYCLE_DETECTED\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -169,15 +339,30 @@ }, "test_cases": [ { - "input": "4 services, deps 1 0 / 2 0 / 3 2", + "input": "4\n3\n1 0\n2 0\n3 2", "output": "0 1 2 3\nLAYERS:3", "is_hidden": false + }, + { + "input": "3\n3\n0 1\n1 2\n2 0", + "output": "CYCLE_DETECTED", + "is_hidden": true + }, + { + "input": "3\n0", + "output": "0 1 2\nLAYERS:1", + "is_hidden": true + }, + { + "input": "4\n3\n1 0\n2 1\n3 2", + "output": "0 1 2 3\nLAYERS:4", + "is_hidden": true } ] }, { "title": "SYSTEM SHUTDOWN SEQUENCER v1.0", - "description": " == SYSTEM SHUTDOWN SEQUENCER v1.0 ==\nSTATUS: CORRUPTED BY [NULL]\n\n[NULL] scrambled the shutdown sequence.\nServices that others depend on are killed first, crashing everything downstream.\nReconstruct the REVERSE topological order: shut down dependents first,\nthen their dependencies.\nIf a cycle exists, the system is unrecoverable.\n\nINPUT FORMAT:\n Line 1: N (number of services, labeled 0 to N-1)\n Line 2: M (number of dependency pairs)\n Next M lines: \"a b\" meaning service a depends on service b\n (b must boot before a, meaning a must SHUT DOWN before b)\n\nOUTPUT:\n A single line of space-separated service numbers in valid SHUTDOWN order\n (reverse of boot order).\n When multiple services can shut down, pick the LOWEST-numbered first.\n If a cycle, output \"CYCLE_DETECTED\".\n\nEXAMPLES:\n 4 services, deps: 1->0, 2->0, 3->2\n Boot order would be: 0 1 2 3\n Shutdown order (reverse): 3 1 2 0\n (3 and 1 have no dependents; pick 1 first? No: 3 depends on 2 depends on 0,\n 1 depends on 0. Shutdown: nodes with no dependents first.\n Out-degree 0: 1, 3. Pick 1 first (lowest). Then 3. Then 2. Then 0.)\n Output: 1 3 2 0\n\n 3 services, deps: 0->1, 1->2, 2->0\n Output: CYCLE_DETECTED", + "description": "== SYSTEM SHUTDOWN SEQUENCER v1.0 ==\nSTATUS: CORRUPTED BY [NULL]\n\n[NULL] scrambled the shutdown sequence. Services that others depend on are killed first, crashing everything downstream. Reconstruct the REVERSE topological order: dependents shut down before their dependencies.\n\nImplement shutdownOrder(int numServices, int[][] deps) — this is topological sort on the reverse graph:\n- A service can only shut down when nothing else depends on it (out-degree = 0 in the original graph).\n- Use a min-priority queue so the LOWEST-numbered eligible service shuts down first.\n- Return the space-separated shutdown order, or \"CYCLE_DETECTED\" if a cycle exists.\n\nExample: 4 services, deps: 1→0, 2→0, 3→2\n- Services with no dependents initially: {1, 3}. Pick 1 (lowest). Shut down 1.\n- After 1: {3}. Shut down 3. After 3: {2}. Shut down 2. After 2: {0}. Shut down 0.\n- Result: 1 3 2 0\n\nInput: line 1 = N (number of services), line 2 = M (dependency pairs), next M lines = \"a b\" (a depends on b)\nOutput: space-separated shutdown order, or \"CYCLE_DETECTED\"", "difficulty": "Hard", "category": "Java Systems", "templates": { @@ -185,10 +370,25 @@ }, "test_cases": [ { - "input": "4 services, deps 1 0 / 2 0 / 3 2", + "input": "4\n3\n1 0\n2 0\n3 2", "output": "1 3 2 0", "is_hidden": false + }, + { + "input": "3\n3\n0 1\n1 2\n2 0", + "output": "CYCLE_DETECTED", + "is_hidden": true + }, + { + "input": "3\n0", + "output": "0 1 2", + "is_hidden": true + }, + { + "input": "5\n4\n1 0\n2 0\n3 1\n4 2", + "output": "3 4 1 2 0", + "is_hidden": true } ] } -] \ No newline at end of file +] From c684290c4de14ef39f47e7e1c0e9c059167c1c2e Mon Sep 17 00:00:00 2001 From: Pathompum Jirakarnpaisan <107536914+Saannddy@users.noreply.github.com> Date: Wed, 29 Apr 2026 00:14:11 +0700 Subject: [PATCH 10/10] data: add riddles for ELVHALL and THEICT Java practice content --- .../data/java/elevatorhall/riddles.json | 152 +++++++++++++++++ src/scripts/data/java/theict/riddles.json | 153 +++++++++++++++++- src/scripts/seeders/seed_elevatorhall_java.py | 20 ++- 3 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 src/scripts/data/java/elevatorhall/riddles.json diff --git a/src/scripts/data/java/elevatorhall/riddles.json b/src/scripts/data/java/elevatorhall/riddles.json new file mode 100644 index 0000000..9f9153c --- /dev/null +++ b/src/scripts/data/java/elevatorhall/riddles.json @@ -0,0 +1,152 @@ +[ + { + "text": "A peaked steel anchor at the crown of the shaft, crossed by the horizontal safety bar that locks the cab in place when the motor stops. First in the passkey, I rise and hold, the opening cipher yet to be told.", + "char": "A", + "index": 1, + "difficulty": "Easy" + }, + { + "text": "Two call buttons stacked on the same panel beside a landing door, both lit in amber when riders are waiting on two floors at once. Second in the chain, I stack and glow, the follow-up cipher below.", + "char": "B", + "index": 2, + "difficulty": "Medium" + }, + { + "text": "The curved glass face of the badge reader mounted beside every controlled door — open and waiting, but refusing to grant access until the right credential sweeps across it. Third in the sequence, I curve and wait, the middle cipher at the gate.", + "char": "C", + "index": 3, + "difficulty": "Hard" + }, + { + "text": "A flat rear wall and a rounded cab door that slides out to meet it — the cross-section of every elevator entrance just before the panel seals shut and the cab begins to move. Fourth in the chain, I slide and seal, one step before the final reveal.", + "char": "D", + "index": 4, + "difficulty": "Medium" + }, + { + "text": "Three illuminated floor markers on the indicator strip above the doors, each lighting in turn as the cab climbs through the shaft toward the requested level. Fifth and final, I count the floors, the last cipher unlocking these doors.", + "char": "E", + "index": 5, + "difficulty": "Easy" + }, + { + "text": "The emergency stop lever mounted on the shaft wall — one arm jutting straight out and another anchoring it to the bracket, ready to halt everything if the safety relay fires. First in the passkey, I halt and hold, the opening cipher of this code.", + "char": "F", + "index": 1, + "difficulty": "Medium" + }, + { + "text": "The latch mechanism on the maintenance hatch cut into the shaft wall — a partial arc with a retaining bar that must be cleared before the panel will swing open for the service crew. Second in the sequence, I latch and turn, the follow-up cipher you must earn.", + "char": "G", + "index": 2, + "difficulty": "Hard" + }, + { + "text": "Two steel guide rails running the full height of the shaft, braced by a crossbeam that prevents the cab from swaying when it accelerates away from a floor. Third in the line, I rail and brace, the center cipher of this space.", + "char": "H", + "index": 3, + "difficulty": "Easy" + }, + { + "text": "A single illuminated call button standing alone on the panel — the only one still responding after [NULL] disabled every other control in the cab. Fourth in the slot, I stand alone, one step before the final tone.", + "char": "I", + "index": 4, + "difficulty": "Hard" + }, + { + "text": "The hook at the end of the emergency cable, curving inward to engage the safety ratchet and hold the cab suspended if the main drive wire ever fails. Fifth and last, I hook and catch, the closing cipher of this batch.", + "char": "J", + "index": 5, + "difficulty": "Medium" + }, + { + "text": "The key-switch slot on the service panel — a vertical housing with two angled teeth that engage the barrel and release the override mode when the correct maintenance key is turned. First in the passkey, I cut and catch, the opening letter of the batch.", + "char": "K", + "index": 1, + "difficulty": "Easy" + }, + { + "text": "The floor track that the cab door slides along — a vertical channel bending into a horizontal base that anchors the rail to the cab floor and keeps the panel true during every transit. Second in line, I track and hold, the follow-up cipher to be told.", + "char": "L", + "index": 2, + "difficulty": "Medium" + }, + { + "text": "A twin-shaft installation where two cabs rise and fall in parallel, their silhouettes mirroring each other against the glass wall of the atrium at every floor they pass together. Third in the sequence, I twin and climb, the center cipher marking time.", + "char": "M", + "index": 3, + "difficulty": "Hard" + }, + { + "text": "The stairwell railing that zigzags beside the shaft — angled balusters bracing each run before the next flight begins, a route for those who did not wait for the cab. Fourth in the chain, I angle and brace, one step before the final place.", + "char": "N", + "index": 4, + "difficulty": "Easy" + }, + { + "text": "The circular inspection porthole cut into the shaft access door, sealed flush when the cab is in motion and opened only by a technician who has already swiped their badge twice. Fifth and last, I seal and stare, the closing cipher of this stair.", + "char": "O", + "index": 5, + "difficulty": "Hard" + }, + { + "text": "The call panel housing on the wall — a vertical column topped with a rounded indicator that glows amber while the cab is still approaching and goes dark the moment the doors part. First in the passkey, I light and call, the opening cipher of the hall.", + "char": "P", + "index": 1, + "difficulty": "Hard" + }, + { + "text": "The surveillance camera mounted in the corner of the cab — a round lens with a trailing cable that loops down toward the recorder hidden in the ceiling panel above. Second in the sequence, I watch and trail, the follow-up cipher of this tale.", + "char": "Q", + "index": 2, + "difficulty": "Easy" + }, + { + "text": "The ratchet arm on the safety brake — a curved catch at the top that releases under rated load and a leg that kicks outward to engage the shaft teeth the instant the cab exceeds safe descent speed. Third in the line, I catch and kick, the middle cipher of this trick.", + "char": "R", + "index": 3, + "difficulty": "Medium" + }, + { + "text": "The hydraulic supply hose coiled in the service bay, curving back on itself twice before connecting to the pressure valve that raises the cab when the pump runs. Fourth in the chain, I coil and press, one step before the final rest.", + "char": "S", + "index": 4, + "difficulty": "Easy" + }, + { + "text": "The overhead I-beam carrying the pulley block at the crown of the shaft — a horizontal span resting on a single vertical anchor welded to the building frame high above every floor. Fifth and last, I span and rest, the closing cipher of the test.", + "char": "T", + "index": 5, + "difficulty": "Hard" + }, + { + "text": "The elevator pit at the base of the shaft — a concrete recess that catches the buffer springs and absorbs the last energy of the cab if every other safety system has already been exhausted. First in the passkey, I catch and hold, the opening cipher to be told.", + "char": "U", + "index": 1, + "difficulty": "Medium" + }, + { + "text": "The descending arrow on the floor indicator panel — pointing down to signal that the cab has accepted a call below and is now moving away from the floor where you are standing. Second in line, I point below, the follow-up letter in the flow.", + "char": "V", + "index": 2, + "difficulty": "Hard" + }, + { + "text": "The up and down call buttons mounted beside every landing door — two indented panels side by side, both depressed by a rider who is not sure which direction the cab will arrive from first. Third in the sequence, I press and wait, the center cipher at the gate.", + "char": "W", + "index": 3, + "difficulty": "Easy" + }, + { + "text": "The emergency cross painted on the shaft access panel — a clear warning mark that this door remains sealed unless all other options have already been tried and failed. Fourth in the chain, I mark and warn, one step before the last is born.", + "char": "X", + "index": 4, + "difficulty": "Medium" + }, + { + "text": "The branch point in the basement floor plate where the goods lift shaft splits away from the passenger shaft — a fork cast into the concrete that separates the two paths before either rises to the first floor. Fifth and last, I fork and end, the closing cipher round the bend.", + "char": "Y", + "index": 5, + "difficulty": "Easy" + } +] diff --git a/src/scripts/data/java/theict/riddles.json b/src/scripts/data/java/theict/riddles.json index 0637a08..feb8a8d 100644 --- a/src/scripts/data/java/theict/riddles.json +++ b/src/scripts/data/java/theict/riddles.json @@ -1 +1,152 @@ -[] \ No newline at end of file +[ + { + "text": "A priority-one rule at the top of the firewall table — its rank forms a sharp peak above every other entry, the first pattern matched against every packet that crosses the boundary. First in the passkey, I rank and lead, the opening cipher you will need.", + "char": "A", + "index": 1, + "difficulty": "Hard" + }, + { + "text": "Two packets queued back to back in the input buffer — each one a rounded header waiting for the rule engine to read its destination field and decide whether it passes or is dropped. Second in the chain, I queue and wait, the follow-up cipher at the gate.", + "char": "B", + "index": 2, + "difficulty": "Easy" + }, + { + "text": "A half-ring network topology with both endpoints still unconnected — the arc of a segment that was meant to close into a full loop before [NULL] severed the last link. Third in the sequence, I arc and wait, the middle cipher in the chain.", + "char": "C", + "index": 3, + "difficulty": "Medium" + }, + { + "text": "A framed data packet — a flat header field on the left edge and a rounded payload body on the right, the standard envelope the protocol uses to carry every message across the wire. Fourth in the chain, I frame and send, one step before the final bend.", + "char": "D", + "index": 4, + "difficulty": "Hard" + }, + { + "text": "Three firewall rules stacked in the policy table — each one a horizontal row tested in order from the top, the engine reading down until the first match tells it whether to allow or deny. Fifth and final, I rule and end, the last cipher round the bend.", + "char": "E", + "index": 5, + "difficulty": "Easy" + }, + { + "text": "A routing fork where an outbound packet reaches a split interface — one path continues straight toward the primary gateway and the other branches to the backup route assigned when the main link is saturated. First in the passkey, I fork and route, the opening cipher of this bout.", + "char": "F", + "index": 1, + "difficulty": "Medium" + }, + { + "text": "A gateway latch holding a socket half-open — a partial arc with a retaining bar, the shape of a TCP connection that has sent its SYN but is still waiting for the handshake to be acknowledged. Second in the sequence, I latch and hold, the follow-up cipher to be told.", + "char": "G", + "index": 2, + "difficulty": "Hard" + }, + { + "text": "Two linked-list nodes joined by a pointer bridge — two data fields standing side by side with a reference arrow between them, the fundamental unit repeated along the entire memory chain. Third in the line, I link and bridge, the center cipher on the ridge.", + "char": "H", + "index": 3, + "difficulty": "Easy" + }, + { + "text": "A single server node standing alone in the rack — the last process still responding after every dependent service in the boot chain has been taken offline by [NULL]'s shutdown sequence. Fourth in the slot, I stand and wait, one step before the final state.", + "char": "I", + "index": 4, + "difficulty": "Medium" + }, + { + "text": "The head pointer of a linked list — a hook that curves down to latch onto the first node, the only anchor for the entire chain that extends behind it through every allocated block of memory. Fifth and last, I hook and link, the closing cipher of this sync.", + "char": "J", + "index": 5, + "difficulty": "Hard" + }, + { + "text": "A network switch port housing — a vertical barrel with two angled prongs that engage the cable clip when the connector is fully seated, locking the link in place until it is deliberately released. First in the passkey, I lock and hold, the opening letter of the fold.", + "char": "K", + "index": 1, + "difficulty": "Easy" + }, + { + "text": "A patch cable run that travels the full length of a server row and bends ninety degrees into the floor tray at the end — the shape every wire makes when it turns a corner and disappears under the raised floor. Second in line, I run and turn, the follow-up cipher you will earn.", + "char": "L", + "index": 2, + "difficulty": "Medium" + }, + { + "text": "A dual-node cluster where two servers share the workload — each one a peak on the monitoring dashboard, their load curves rising and falling in rough parallel until one node fails and the other absorbs everything. Third in the sequence, I mirror load, the center cipher of the code.", + "char": "M", + "index": 3, + "difficulty": "Hard" + }, + { + "text": "The hop diagram in a traceroute result — each bounce angled away from the last, a jagged line plotting the path a packet took across four intermediate routers before it reached its destination. Fourth in the chain, I hop and trace, one step before the final place.", + "char": "N", + "index": 4, + "difficulty": "Easy" + }, + { + "text": "A closed routing loop — a circular path that a misdirected packet circles through indefinitely, the TTL counter decrementing with each pass until the value reaches zero and the packet is finally discarded. Fifth and last, I loop and drain, the closing cipher of the chain.", + "char": "O", + "index": 5, + "difficulty": "Medium" + }, + { + "text": "A port number in the packet header — a vertical identifier field topped with a rounded destination label that tells the router which service on the receiving host should handle this segment before anything else is read. First in the passkey, I port and lead, the opening cipher you will need.", + "char": "P", + "index": 1, + "difficulty": "Hard" + }, + { + "text": "A database cursor looping through a result set — a circular query handle with a trailing reference that marks the most recently examined row, moving forward until the last record has been returned. Second in the sequence, I query on, the follow-up cipher to carry on.", + "char": "Q", + "index": 2, + "difficulty": "Easy" + }, + { + "text": "A router's classification arm — an input barrel at the top that reads the destination, a matching hump where the rule fires, and a leg that kicks the packet toward the correct outbound interface without stopping to explain itself. Third in the line, I route and kick, the middle cipher of this trick.", + "char": "R", + "index": 3, + "difficulty": "Medium" + }, + { + "text": "The serpentine path a packet traces through three consecutive NAT stages — curving back on itself twice before emerging with a translated source address at the far side of the perimeter gateway. Fourth in the chain, I curve and shift, one step before the final lift.", + "char": "S", + "index": 4, + "difficulty": "Hard" + }, + { + "text": "The SYN-ACK crossover at the centre of a TCP handshake — two acknowledgement signals meeting at a midpoint, forming the balanced exchange that confirms a connection is established before any payload is transferred. Fifth and last, I cross and end, the closing cipher round the bend.", + "char": "T", + "index": 5, + "difficulty": "Easy" + }, + { + "text": "A buffer underrun event — the moment an output queue empties faster than it is refilled, leaving a concave gap in the data stream that the scheduler must close before the next transmission window opens. First in the passkey, I drain and dip, the opening cipher of this trip.", + "char": "U", + "index": 1, + "difficulty": "Medium" + }, + { + "text": "The descending arrow in a priority queue drain log — pointing downward as each high-severity entry exits first and lower-priority packets wait longer with every pass, sinking further from the front. Second in line, I drain below, the follow-up cipher in the flow.", + "char": "V", + "index": 2, + "difficulty": "Hard" + }, + { + "text": "A W-shaped dip in a ping latency graph — two valleys marking the moments where routing delays spiked and the path briefly rerouted before settling back near the baseline that the SLA requires. Third in the sequence, I dip and ping, the center cipher of the ring.", + "char": "W", + "index": 3, + "difficulty": "Easy" + }, + { + "text": "Two packets crossing in opposite directions at the moment both endpoints send a TCP RST simultaneously — the connection terminating cleanly from both sides, neither waiting for the other to close first. Fourth in the chain, I cross and close, one step before the curtain goes.", + "char": "X", + "index": 4, + "difficulty": "Medium" + }, + { + "text": "The branch point inside a load balancer where an incoming request forks — one copy heading to the primary node and the other continuing to the failover, a wishbone etched into every traffic diagram that maps this infrastructure. Fifth and last, I split and end, the closing cipher round the bend.", + "char": "Y", + "index": 5, + "difficulty": "Hard" + } +] diff --git a/src/scripts/seeders/seed_elevatorhall_java.py b/src/scripts/seeders/seed_elevatorhall_java.py index 5fdc057..7f312b4 100644 --- a/src/scripts/seeders/seed_elevatorhall_java.py +++ b/src/scripts/seeders/seed_elevatorhall_java.py @@ -7,7 +7,7 @@ from sqlmodel import Session, select from infrastructure import engine from models import ( - Category, Tag, Question, Choice, Chunk, ChunkTemplate, Snippet, Expectation, Problem, TestCase + Category, Tag, Riddle, Question, Choice, Chunk, ChunkTemplate, Snippet, Expectation, Problem, TestCase ) from sqlalchemy.orm.attributes import flag_modified @@ -33,6 +33,7 @@ def seed_elevatorhall_java(): logging.error("No database engine found. Skipping seeding.") return + RIDDLES = load_json("riddles.json") CHUNKS = load_json("chunks.json") PROBLEMS = load_json("problems.json") @@ -62,6 +63,23 @@ def get_or_create_tag(name): elv_hall_tag = get_or_create_tag("JAV_ELVHALL") java_cat = get_or_create_category("Java") + logging.info(f"Seeding {len(RIDDLES)} Java riddles...") + for i, r_data in enumerate(tqdm(RIDDLES, desc="Seeding Riddles")): + r_id = get_uuid(f"jav_elvhall_r_{i}") + if session.exec(select(Riddle).where(Riddle.id == r_id)).first(): + continue + + riddle = Riddle( + id=r_id, + riddle_text=r_data["text"], + refer_char=r_data["char"], + refer_index=r_data["index"], + difficulty=r_data.get("difficulty", "Medium"), + created_at=datetime.now(timezone.utc) + ) + riddle.tags = [elv_hall_tag] + session.add(riddle) + logging.info(f"Seeding {len(CHUNKS)} Java chunks...") for c_data in tqdm(CHUNKS, desc="Seeding Chunks"): c_id = get_uuid(f"jav_elvhall_chunk_{c_data['title']}")