fighter1107a 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/PKG-INFO +1 -1
- fighter1107a-0.1.3/fighter1107a/algos/1.0.txt +9 -0
- fighter1107a-0.1.3/fighter1107a/algos/1.1.txt +8 -0
- fighter1107a-0.1.3/fighter1107a/algos/2.1.txt +9 -0
- fighter1107a-0.1.3/fighter1107a/algos/2.2.txt +8 -0
- fighter1107a-0.1.3/fighter1107a/algos/3.txt +12 -0
- fighter1107a-0.1.3/fighter1107a/algos/4.1.txt +10 -0
- fighter1107a-0.1.3/fighter1107a/algos/4.2.txt +11 -0
- fighter1107a-0.1.3/fighter1107a/algos/5.txt +11 -0
- fighter1107a-0.1.3/fighter1107a/algos/6.txt +12 -0
- fighter1107a-0.1.3/fighter1107a/algos/7.txt +11 -0
- fighter1107a-0.1.3/fighter1107a/algos/8.txt +12 -0
- fighter1107a-0.1.3/fighter1107a/algos/9.txt +12 -0
- fighter1107a-0.1.3/fighter1107a/cli.py +116 -0
- fighter1107a-0.1.3/fighter1107a/codes/A search.py +79 -0
- fighter1107a-0.1.3/fighter1107a/codes/Assignment1_38_12411944.py +30 -0
- fighter1107a-0.1.3/fighter1107a/codes/Assignment5_38_12411944.py +61 -0
- fighter1107a-0.1.3/fighter1107a/codes/Assignment7_38_12411944.py +42 -0
- fighter1107a-0.1.3/fighter1107a/codes/Assignment8_38_12411944.py +48 -0
- fighter1107a-0.1.3/fighter1107a/codes/Assignment9_38_12411944.py +49 -0
- fighter1107a-0.1.3/fighter1107a/codes/BFS.py +48 -0
- fighter1107a-0.1.3/fighter1107a/codes/DFS.py +49 -0
- fighter1107a-0.1.3/fighter1107a/codes/Graph Colouring.py +75 -0
- fighter1107a-0.1.3/fighter1107a/codes/Greedy Best-First Search.py +81 -0
- fighter1107a-0.1.3/fighter1107a/codes/UCS.py +66 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a.egg-info/PKG-INFO +1 -1
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a.egg-info/SOURCES.txt +12 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/pyproject.toml +2 -2
- fighter1107a-0.1.2/fighter1107a/cli.py +0 -91
- fighter1107a-0.1.2/fighter1107a/codes/A search.py +0 -58
- fighter1107a-0.1.2/fighter1107a/codes/Assignment1_38_12411944.py +0 -35
- fighter1107a-0.1.2/fighter1107a/codes/Assignment5_38_12411944.py +0 -62
- fighter1107a-0.1.2/fighter1107a/codes/Assignment7_38_12411944.py +0 -47
- fighter1107a-0.1.2/fighter1107a/codes/Assignment8_38_12411944.py +0 -46
- fighter1107a-0.1.2/fighter1107a/codes/Assignment9_38_12411944.py +0 -39
- fighter1107a-0.1.2/fighter1107a/codes/BFS.py +0 -45
- fighter1107a-0.1.2/fighter1107a/codes/DFS.py +0 -44
- fighter1107a-0.1.2/fighter1107a/codes/Graph Colouring.py +0 -50
- fighter1107a-0.1.2/fighter1107a/codes/Greedy Best-First Search.py +0 -51
- fighter1107a-0.1.2/fighter1107a/codes/UCS.py +0 -39
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/README.md +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a/__init__.py +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a/__main__.py +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a/codes/Assignment1.1_38_12411944.py +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a.egg-info/dependency_links.txt +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a.egg-info/entry_points.txt +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/fighter1107a.egg-info/top_level.txt +0 -0
- {fighter1107a-0.1.2 → fighter1107a-0.1.3}/setup.cfg +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter the status of Rooms A and B as Clean or Dirty; reject invalid entries.
|
|
3
|
+
3. Enter the initial vacuum position, A or B; reject any other entry.
|
|
4
|
+
4. Check the room at the current position.
|
|
5
|
+
5. If it is Dirty, clean it and mark it Clean.
|
|
6
|
+
6. Otherwise, check the other room. Move there only if it is Dirty.
|
|
7
|
+
7. Repeat until the current room and the other room are both Clean.
|
|
8
|
+
8. Display the final status of both rooms.
|
|
9
|
+
9. Stop.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter the total number of floors and initialize current floor to 1.
|
|
3
|
+
3. Repeatedly enter destination floor (or 0 to exit); reject invalid floors.
|
|
4
|
+
4. Compare current floor with target floor using condition-action rules:
|
|
5
|
+
- If target > current: MOVE_UP one floor at a time.
|
|
6
|
+
- If target < current: MOVE_DOWN one floor at a time.
|
|
7
|
+
- If target == current: OPEN_DOOR and serve passengers.
|
|
8
|
+
5. Stop when the user enters 0.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter the vertex and edge counts; reject invalid values.
|
|
3
|
+
3. Build an undirected graph from valid pairs of vertices.
|
|
4
|
+
4. Enter and validate the starting vertex.
|
|
5
|
+
5. Add the start to a queue and mark it visited.
|
|
6
|
+
6. Remove the front vertex and add it to the traversal.
|
|
7
|
+
7. Mark each unvisited adjacent vertex and add it to the queue.
|
|
8
|
+
8. Repeat until the queue is empty; display the BFS traversal.
|
|
9
|
+
9. Stop.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Use the same undirected graph and validated starting vertex.
|
|
3
|
+
3. Mark the start visited and add it to the traversal.
|
|
4
|
+
4. For each unvisited adjacent vertex, visit it recursively.
|
|
5
|
+
5. Backtrack when a vertex has no unvisited adjacent vertex.
|
|
6
|
+
6. Continue until all vertices reachable from the start are visited.
|
|
7
|
+
7. Display the DFS traversal.
|
|
8
|
+
8. Stop.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter valid vertex and edge counts, then build an undirected weighted graph.
|
|
3
|
+
3. Reject invalid vertices and negative edge costs.
|
|
4
|
+
4. Enter and validate the start and goal vertices.
|
|
5
|
+
5. Insert the start in a priority queue with cost 0 and its initial path.
|
|
6
|
+
6. Remove the entry with the lowest accumulated path cost.
|
|
7
|
+
7. Skip it if its vertex was already visited; otherwise mark it visited.
|
|
8
|
+
8. If it is the goal, display its path and total cost, then stop.
|
|
9
|
+
9. For each unvisited neighbor, add the edge cost and insert the extended path in the queue.
|
|
10
|
+
10. Repeat until the goal is found or the queue is empty.
|
|
11
|
+
11. If the queue empties, display that no path exists.
|
|
12
|
+
12. Stop.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter a valid undirected weighted graph and nonnegative heuristic for each vertex.
|
|
3
|
+
3. Enter and validate the start and goal vertices.
|
|
4
|
+
4. Put the start in a priority queue ordered by heuristic value.
|
|
5
|
+
5. Remove the vertex with the lowest heuristic; skip it if already visited.
|
|
6
|
+
6. Mark it visited. If it is the goal, reconstruct the path from parent links.
|
|
7
|
+
7. Otherwise, record and queue each neighbor not visited or previously discovered.
|
|
8
|
+
8. Repeat until the goal is found or the queue is empty.
|
|
9
|
+
9. Display the path and its edge cost, or report no path.
|
|
10
|
+
10. Stop.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Use the same graph, heuristics, start, and goal.
|
|
3
|
+
3. Set the start path cost g to 0 and queue it with f = g + h.
|
|
4
|
+
4. Remove the entry with the lowest f; ignore it if its g value is outdated.
|
|
5
|
+
5. If it is the goal, reconstruct and display the path and total cost.
|
|
6
|
+
6. For each neighbor, calculate new g = current g + edge cost.
|
|
7
|
+
7. If new g is lower than its recorded cost, update its cost and parent.
|
|
8
|
+
8. Insert the updated neighbor with f = new g + its heuristic.
|
|
9
|
+
9. Repeat until the goal is found or the queue is empty.
|
|
10
|
+
10. If the queue empties, report no path.
|
|
11
|
+
11. Stop.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter a positive maximum number of random starts.
|
|
3
|
+
3. For each attempt, place one queen in a random row of every column.
|
|
4
|
+
4. Count pairs of queens attacking each other.
|
|
5
|
+
5. If the count is zero, display the board and attempt count, then stop.
|
|
6
|
+
6. Generate neighbors by moving one queen to another row in its column.
|
|
7
|
+
7. Choose the neighbor with the fewest conflicts.
|
|
8
|
+
8. If it improves the count, move to it and repeat the check.
|
|
9
|
+
9. If no neighbor improves the count, begin a new random attempt.
|
|
10
|
+
10. After the limit, report that no solution was found.
|
|
11
|
+
11. Stop.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter valid, unique region names and neighboring region pairs.
|
|
3
|
+
3. Reject unknown regions and any region paired with itself.
|
|
4
|
+
4. Enter a positive number of unique, nonempty color names.
|
|
5
|
+
5. Leave all regions uncolored and select the first in input order.
|
|
6
|
+
6. Try an available color for the selected region.
|
|
7
|
+
7. Accept it only if no already colored neighbor has that color.
|
|
8
|
+
8. Recursively select the next region after a valid assignment.
|
|
9
|
+
9. If later regions fail, remove the assignment and try the next color.
|
|
10
|
+
10. Continue until every region is colored or all choices are exhausted.
|
|
11
|
+
11. Display the coloring, or report that no valid coloring exists.
|
|
12
|
+
12. Stop.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter a nonempty Gemini API key and configure the AI model.
|
|
3
|
+
3. Enter a nonempty project description.
|
|
4
|
+
4. Choose SRS, user stories, or software documentation; reject an invalid choice.
|
|
5
|
+
5. Build a prompt from the description and chosen document type.
|
|
6
|
+
6. Ask the model to include relevant requirements and flag unclear details.
|
|
7
|
+
7. Send the prompt to the Gemini API and check that the reply is nonempty.
|
|
8
|
+
8. Display the generated document.
|
|
9
|
+
9. Save it as SRS.txt, User_Stories.txt, or Software_Documentation.txt.
|
|
10
|
+
10. If input, API, or network processing fails, display the error.
|
|
11
|
+
11. Stop.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter a nonempty Gemini API key and configure the AI model.
|
|
3
|
+
3. Enter a nonempty programming requirement and language.
|
|
4
|
+
4. Prompt the model to generate complete source code with input and edge case handling.
|
|
5
|
+
5. Send the prompt; check that the response is nonempty.
|
|
6
|
+
6. Display the generated code and save it as generated_code.txt.
|
|
7
|
+
7. Ask whether an AI code review is required.
|
|
8
|
+
8. If yes, prompt the model to review the code for errors, security, performance, and quality.
|
|
9
|
+
9. Check the review response, display it, and save it as code_review.txt.
|
|
10
|
+
10. If the answer is invalid, report that review was skipped.
|
|
11
|
+
11. If input, API, or network processing fails, display the error.
|
|
12
|
+
12. Stop.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
1. Start.
|
|
2
|
+
2. Enter a nonempty Gemini API key and configure the AI model.
|
|
3
|
+
3. Read source code line by line until END is entered alone on a line.
|
|
4
|
+
4. Reject empty source code.
|
|
5
|
+
5. Prompt the model for executable Python unittest tests covering normal, boundary, invalid, and edge cases.
|
|
6
|
+
6. Send the prompt and check that the response is nonempty.
|
|
7
|
+
7. Display the tests and save them as unit_tests.txt.
|
|
8
|
+
8. Prompt the model to find syntax, logic, runtime, boundary, and input handling bugs.
|
|
9
|
+
9. Send the source code again and check that the report is nonempty.
|
|
10
|
+
10. Display suggested corrections and save the report as bug_report.txt.
|
|
11
|
+
11. If input, API, or network processing fails, display the error.
|
|
12
|
+
12. Stop.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
|
|
4
|
+
ASSIGNMENTS = [
|
|
5
|
+
("1.0", "Simple Reflex Vacuum Cleaner Agent", "Assignment1_38_12411944.py"),
|
|
6
|
+
("1.1", "Simple Reflex Agent (Lift Operation)", "Assignment1.1_38_12411944.py"),
|
|
7
|
+
("2.1", "Breadth-First Search (BFS)", "BFS.py"),
|
|
8
|
+
("2.2", "Depth-First Search (DFS)", "DFS.py"),
|
|
9
|
+
("3", "Uniform Cost Search (UCS)", "UCS.py"),
|
|
10
|
+
("4.1", "Greedy Best-First Search", "Greedy Best-First Search.py"),
|
|
11
|
+
("4.2", "A* Search Algorithm", "A search.py"),
|
|
12
|
+
("5", "Hill Climbing - 8 Queens Problem", "Assignment5_38_12411944.py"),
|
|
13
|
+
("6", "CSP - Map Coloring using Backtracking", "Graph Colouring.py"),
|
|
14
|
+
("7", "AI-Based SRS and User Story Generator", "Assignment7_38_12411944.py"),
|
|
15
|
+
("8", "AI-Based Code Generator and Code Reviewer", "Assignment8_38_12411944.py"),
|
|
16
|
+
("9", "AI-Based Unit Test Generator and Bug Detector", "Assignment9_38_12411944.py"),
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
ALIASES = {
|
|
20
|
+
"1": ["1.0"],
|
|
21
|
+
"vacuum": ["1.0"],
|
|
22
|
+
"lift": ["1.1"],
|
|
23
|
+
"2": ["2.1", "2.2"],
|
|
24
|
+
"bfs": ["2.1"],
|
|
25
|
+
"dfs": ["2.2"],
|
|
26
|
+
"ucs": ["3"],
|
|
27
|
+
"4": ["4.1", "4.2"],
|
|
28
|
+
"gbfs": ["4.1"],
|
|
29
|
+
"astar": ["4.2"],
|
|
30
|
+
"a*": ["4.2"],
|
|
31
|
+
"hc": ["5"],
|
|
32
|
+
"queens": ["5"],
|
|
33
|
+
"csp": ["6"],
|
|
34
|
+
"srs": ["7"],
|
|
35
|
+
"review": ["8"],
|
|
36
|
+
"test": ["9"],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
BY_KEY = {key: (title, fname) for key, title, fname in ASSIGNMENTS}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def print_code(keys, mode="both"):
|
|
43
|
+
base = files("fighter1107a")
|
|
44
|
+
codes_dir = base.joinpath("codes")
|
|
45
|
+
algos_dir = base.joinpath("algos")
|
|
46
|
+
|
|
47
|
+
for idx, key in enumerate(keys):
|
|
48
|
+
title, fname = BY_KEY[key]
|
|
49
|
+
algo_text = algos_dir.joinpath(f"{key}.txt").read_text(encoding="utf-8").strip()
|
|
50
|
+
code_text = codes_dir.joinpath(fname).read_text(encoding="utf-8").strip()
|
|
51
|
+
|
|
52
|
+
if idx > 0:
|
|
53
|
+
print("\n")
|
|
54
|
+
|
|
55
|
+
print("=" * 64)
|
|
56
|
+
print(f" PRACTICAL {key}: {title} ({fname})")
|
|
57
|
+
print("=" * 64)
|
|
58
|
+
|
|
59
|
+
if mode in ("both", "algo"):
|
|
60
|
+
print("\n--- [ ALGORITHM ] ----------------------------------------------")
|
|
61
|
+
print(algo_text)
|
|
62
|
+
|
|
63
|
+
if mode in ("both", "code"):
|
|
64
|
+
print("\n--- [ PYTHON CODE ] --------------------------------------------")
|
|
65
|
+
print(code_text)
|
|
66
|
+
|
|
67
|
+
print("=" * 64)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def resolve_choice(raw):
|
|
71
|
+
choice = raw.strip().lower()
|
|
72
|
+
if choice in BY_KEY:
|
|
73
|
+
return [choice]
|
|
74
|
+
if choice in ALIASES:
|
|
75
|
+
return ALIASES[choice]
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def show_menu():
|
|
80
|
+
print("AI in Software Engineering - Algorithms & Codes (Print Only)")
|
|
81
|
+
print("-" * 60)
|
|
82
|
+
for key, title, _ in ASSIGNMENTS:
|
|
83
|
+
print(f" {key:<4} : {title}")
|
|
84
|
+
print("-" * 60)
|
|
85
|
+
print("Tip: Run `aise 3`, `aise bfs`, `aise 3 --algo`, or `aise 3 --code`")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def main():
|
|
89
|
+
args = sys.argv[1:]
|
|
90
|
+
mode = "both"
|
|
91
|
+
if "--algo" in args:
|
|
92
|
+
mode = "algo"
|
|
93
|
+
args = [a for a in args if a != "--algo"]
|
|
94
|
+
elif "--code" in args:
|
|
95
|
+
mode = "code"
|
|
96
|
+
args = [a for a in args if a != "--code"]
|
|
97
|
+
|
|
98
|
+
if args:
|
|
99
|
+
arg = " ".join(args)
|
|
100
|
+
keys = resolve_choice(arg)
|
|
101
|
+
if not keys:
|
|
102
|
+
print(f"Unknown assignment '{arg}'. Run `aise` to see options.", file=sys.stderr)
|
|
103
|
+
sys.exit(1)
|
|
104
|
+
print_code(keys, mode=mode)
|
|
105
|
+
return
|
|
106
|
+
|
|
107
|
+
show_menu()
|
|
108
|
+
choice = input("\nEnter assignment number/name (or q to quit): ").strip()
|
|
109
|
+
if choice.lower() in ("q", "quit", "exit", ""):
|
|
110
|
+
return
|
|
111
|
+
keys = resolve_choice(choice)
|
|
112
|
+
if not keys:
|
|
113
|
+
print(f"Invalid choice '{choice}'.")
|
|
114
|
+
sys.exit(1)
|
|
115
|
+
print()
|
|
116
|
+
print_code(keys, mode=mode)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import heapq
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def read_int(msg, min_val=0):
|
|
5
|
+
while True:
|
|
6
|
+
try:
|
|
7
|
+
val = int(input(msg))
|
|
8
|
+
if val >= min_val:
|
|
9
|
+
return val
|
|
10
|
+
except ValueError:
|
|
11
|
+
pass
|
|
12
|
+
print(f"Invalid value! Enter an integer >= {min_val}.")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
v = read_int("Enter number of vertices: ", 1)
|
|
16
|
+
e = read_int("Enter number of edges: ", 0)
|
|
17
|
+
|
|
18
|
+
graph = {i: {} for i in range(v)}
|
|
19
|
+
print(f"Vertices are 0 to {v - 1}")
|
|
20
|
+
|
|
21
|
+
for i in range(e):
|
|
22
|
+
while True:
|
|
23
|
+
try:
|
|
24
|
+
u, w, cost = map(int, input(f"Enter edge {i + 1} (u v cost): ").split())
|
|
25
|
+
if 0 <= u < v and 0 <= w < v and cost >= 0:
|
|
26
|
+
graph[u][w] = cost
|
|
27
|
+
graph[w][u] = cost
|
|
28
|
+
break
|
|
29
|
+
except ValueError:
|
|
30
|
+
pass
|
|
31
|
+
print("Invalid vertices or negative cost! Try again.")
|
|
32
|
+
|
|
33
|
+
h = {}
|
|
34
|
+
for i in range(v):
|
|
35
|
+
h[i] = read_int(f"Enter heuristic h({i}): ", 0)
|
|
36
|
+
|
|
37
|
+
while True:
|
|
38
|
+
start = read_int("Enter start vertex: ", 0)
|
|
39
|
+
goal = read_int("Enter goal vertex: ", 0)
|
|
40
|
+
if start < v and goal < v:
|
|
41
|
+
break
|
|
42
|
+
print("Invalid start or goal vertex!")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def astar(graph, h, start, goal):
|
|
46
|
+
g_cost = {start: 0}
|
|
47
|
+
parent = {start: None}
|
|
48
|
+
pq = [(h[start], 0, start)]
|
|
49
|
+
|
|
50
|
+
while pq:
|
|
51
|
+
_, current_g, node = heapq.heappop(pq)
|
|
52
|
+
if current_g > g_cost.get(node, float("inf")):
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
if node == goal:
|
|
56
|
+
path = []
|
|
57
|
+
cur = goal
|
|
58
|
+
while cur is not None:
|
|
59
|
+
path.append(cur)
|
|
60
|
+
cur = parent[cur]
|
|
61
|
+
path.reverse()
|
|
62
|
+
return path, current_g
|
|
63
|
+
|
|
64
|
+
for nb, weight in graph[node].items():
|
|
65
|
+
new_g = current_g + weight
|
|
66
|
+
if new_g < g_cost.get(nb, float("inf")):
|
|
67
|
+
g_cost[nb] = new_g
|
|
68
|
+
parent[nb] = node
|
|
69
|
+
heapq.heappush(pq, (new_g + h[nb], new_g, nb))
|
|
70
|
+
|
|
71
|
+
return [], None
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
path, total_cost = astar(graph, h, start, goal)
|
|
75
|
+
if path:
|
|
76
|
+
print("A* Shortest Path:", " -> ".join(map(str, path)))
|
|
77
|
+
print("Total cost:", total_cost)
|
|
78
|
+
else:
|
|
79
|
+
print("No path exists.")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
def get_status(room):
|
|
2
|
+
while True:
|
|
3
|
+
s = input(f"Enter status of Room {room} (Clean/Dirty): ").strip().lower()
|
|
4
|
+
if s in ("clean", "dirty"):
|
|
5
|
+
return s
|
|
6
|
+
print("Invalid entry! Please enter Clean or Dirty.")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
rooms = {"A": get_status("A"), "B": get_status("B")}
|
|
10
|
+
|
|
11
|
+
while True:
|
|
12
|
+
pos = input("Enter initial vacuum position (A/B): ").strip().upper()
|
|
13
|
+
if pos in ("A", "B"):
|
|
14
|
+
break
|
|
15
|
+
print("Invalid entry! Please enter A or B.")
|
|
16
|
+
|
|
17
|
+
while rooms["A"] == "dirty" or rooms["B"] == "dirty":
|
|
18
|
+
print(f"\nChecking Room {pos}: {rooms[pos].capitalize()}")
|
|
19
|
+
if rooms[pos] == "dirty":
|
|
20
|
+
rooms[pos] = "clean"
|
|
21
|
+
print(f"Action: Suck -> Room {pos} is now Clean.")
|
|
22
|
+
else:
|
|
23
|
+
other = "B" if pos == "A" else "A"
|
|
24
|
+
if rooms[other] == "dirty":
|
|
25
|
+
pos = other
|
|
26
|
+
print(f"Action: Move to Room {pos} (Dirty).")
|
|
27
|
+
|
|
28
|
+
print("\nFinal Status:")
|
|
29
|
+
print("Room A:", rooms["A"].capitalize())
|
|
30
|
+
print("Room B:", rooms["B"].capitalize())
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
N = 8
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def count_conflicts(state):
|
|
7
|
+
conflicts = 0
|
|
8
|
+
for i in range(N):
|
|
9
|
+
for j in range(i + 1, N):
|
|
10
|
+
if state[i] == state[j] or abs(state[i] - state[j]) == abs(i - j):
|
|
11
|
+
conflicts += 1
|
|
12
|
+
return conflicts
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def show_board(state):
|
|
16
|
+
for r in range(N):
|
|
17
|
+
print(" ".join("Q" if state[c] == r else "." for c in range(N)))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
while True:
|
|
21
|
+
try:
|
|
22
|
+
max_starts = int(input("Enter max random starts (positive integer): "))
|
|
23
|
+
if max_starts > 0:
|
|
24
|
+
break
|
|
25
|
+
except ValueError:
|
|
26
|
+
pass
|
|
27
|
+
print("Invalid input! Enter a positive integer.")
|
|
28
|
+
|
|
29
|
+
solved = False
|
|
30
|
+
for attempt in range(1, max_starts + 1):
|
|
31
|
+
current = [random.randint(0, N - 1) for _ in range(N)]
|
|
32
|
+
current_h = count_conflicts(current)
|
|
33
|
+
|
|
34
|
+
while current_h > 0:
|
|
35
|
+
best_state = current
|
|
36
|
+
best_h = current_h
|
|
37
|
+
|
|
38
|
+
for col in range(N):
|
|
39
|
+
for row in range(N):
|
|
40
|
+
if row == current[col]:
|
|
41
|
+
continue
|
|
42
|
+
neighbor = current[:]
|
|
43
|
+
neighbor[col] = row
|
|
44
|
+
h = count_conflicts(neighbor)
|
|
45
|
+
if h < best_h:
|
|
46
|
+
best_h = h
|
|
47
|
+
best_state = neighbor
|
|
48
|
+
|
|
49
|
+
if best_h >= current_h:
|
|
50
|
+
break
|
|
51
|
+
current = best_state
|
|
52
|
+
current_h = best_h
|
|
53
|
+
|
|
54
|
+
if current_h == 0:
|
|
55
|
+
print(f"\nSolution found in attempt {attempt}:")
|
|
56
|
+
show_board(current)
|
|
57
|
+
solved = True
|
|
58
|
+
break
|
|
59
|
+
|
|
60
|
+
if not solved:
|
|
61
|
+
print("\nNo solution found within the attempt limit.")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import google.generativeai as genai
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
api_key = input("Enter Gemini API key: ").strip()
|
|
5
|
+
if not api_key:
|
|
6
|
+
raise ValueError("API key cannot be empty.")
|
|
7
|
+
|
|
8
|
+
genai.configure(api_key=api_key)
|
|
9
|
+
model = genai.GenerativeModel("gemini-2.5-flash")
|
|
10
|
+
|
|
11
|
+
desc = input("Enter project description: ").strip()
|
|
12
|
+
if not desc:
|
|
13
|
+
raise ValueError("Project description cannot be empty.")
|
|
14
|
+
|
|
15
|
+
print("1. SRS\n2. User Stories\n3. Software Documentation")
|
|
16
|
+
choice = input("Choose document type (1/2/3): ").strip()
|
|
17
|
+
|
|
18
|
+
files = {
|
|
19
|
+
"1": ("SRS", "SRS.txt"),
|
|
20
|
+
"2": ("User Stories", "User_Stories.txt"),
|
|
21
|
+
"3": ("Software Documentation", "Software_Documentation.txt"),
|
|
22
|
+
}
|
|
23
|
+
if choice not in files:
|
|
24
|
+
raise ValueError("Invalid document choice.")
|
|
25
|
+
|
|
26
|
+
doc_type, filename = files[choice]
|
|
27
|
+
prompt = (
|
|
28
|
+
f"Generate {doc_type} for this project: {desc}. "
|
|
29
|
+
f"Include relevant requirements and clearly flag any unclear details."
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
reply = model.generate_content(prompt).text.strip()
|
|
33
|
+
if not reply:
|
|
34
|
+
raise ValueError("Received empty response from Gemini API.")
|
|
35
|
+
|
|
36
|
+
print(f"\n--- {doc_type} ---\n{reply}")
|
|
37
|
+
with open(filename, "w", encoding="utf-8") as f:
|
|
38
|
+
f.write(reply)
|
|
39
|
+
print(f"\nSaved to {filename}")
|
|
40
|
+
|
|
41
|
+
except Exception as e:
|
|
42
|
+
print("Error:", e)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import google.generativeai as genai
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
api_key = input("Enter Gemini API key: ").strip()
|
|
5
|
+
if not api_key:
|
|
6
|
+
raise ValueError("API key cannot be empty.")
|
|
7
|
+
|
|
8
|
+
genai.configure(api_key=api_key)
|
|
9
|
+
model = genai.GenerativeModel("gemini-2.5-flash")
|
|
10
|
+
|
|
11
|
+
req = input("Enter programming requirement: ").strip()
|
|
12
|
+
lang = input("Enter programming language: ").strip()
|
|
13
|
+
if not req or not lang:
|
|
14
|
+
raise ValueError("Requirement and language cannot be empty.")
|
|
15
|
+
|
|
16
|
+
code_prompt = (
|
|
17
|
+
f"Write complete {lang} source code for: {req}. "
|
|
18
|
+
f"Include proper input validation and edge case handling."
|
|
19
|
+
)
|
|
20
|
+
code = model.generate_content(code_prompt).text.strip()
|
|
21
|
+
if not code:
|
|
22
|
+
raise ValueError("Empty code response from Gemini API.")
|
|
23
|
+
|
|
24
|
+
print(f"\n--- Generated Code ---\n{code}")
|
|
25
|
+
with open("generated_code.txt", "w", encoding="utf-8") as f:
|
|
26
|
+
f.write(code)
|
|
27
|
+
print("\nSaved to generated_code.txt")
|
|
28
|
+
|
|
29
|
+
ans = input("\nDo you want an AI code review? (yes/no): ").strip().lower()
|
|
30
|
+
if ans in ("yes", "y"):
|
|
31
|
+
review_prompt = (
|
|
32
|
+
f"Review this {lang} code for errors, security issues, "
|
|
33
|
+
f"performance, and code quality:\n{code}"
|
|
34
|
+
)
|
|
35
|
+
review = model.generate_content(review_prompt).text.strip()
|
|
36
|
+
if not review:
|
|
37
|
+
raise ValueError("Empty review response from Gemini API.")
|
|
38
|
+
print(f"\n--- Code Review ---\n{review}")
|
|
39
|
+
with open("code_review.txt", "w", encoding="utf-8") as f:
|
|
40
|
+
f.write(review)
|
|
41
|
+
print("\nSaved to code_review.txt")
|
|
42
|
+
elif ans in ("no", "n"):
|
|
43
|
+
print("Code review skipped.")
|
|
44
|
+
else:
|
|
45
|
+
print("Invalid answer. Code review skipped.")
|
|
46
|
+
|
|
47
|
+
except Exception as e:
|
|
48
|
+
print("Error:", e)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import google.generativeai as genai
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
api_key = input("Enter Gemini API key: ").strip()
|
|
5
|
+
if not api_key:
|
|
6
|
+
raise ValueError("API key cannot be empty.")
|
|
7
|
+
|
|
8
|
+
genai.configure(api_key=api_key)
|
|
9
|
+
model = genai.GenerativeModel("gemini-2.5-flash")
|
|
10
|
+
|
|
11
|
+
print("Enter Python source code (type END on a new line to finish):")
|
|
12
|
+
lines = []
|
|
13
|
+
while True:
|
|
14
|
+
line = input()
|
|
15
|
+
if line.strip() == "END":
|
|
16
|
+
break
|
|
17
|
+
lines.append(line)
|
|
18
|
+
code = "\n".join(lines).strip()
|
|
19
|
+
if not code:
|
|
20
|
+
raise ValueError("Source code cannot be empty.")
|
|
21
|
+
|
|
22
|
+
test_prompt = (
|
|
23
|
+
f"Generate executable Python unittest test cases covering normal, "
|
|
24
|
+
f"boundary, invalid, and edge cases for:\n{code}"
|
|
25
|
+
)
|
|
26
|
+
tests = model.generate_content(test_prompt).text.strip()
|
|
27
|
+
if not tests:
|
|
28
|
+
raise ValueError("Empty unit test response from Gemini API.")
|
|
29
|
+
|
|
30
|
+
print(f"\n--- Generated Unit Tests ---\n{tests}")
|
|
31
|
+
with open("unit_tests.txt", "w", encoding="utf-8") as f:
|
|
32
|
+
f.write(tests)
|
|
33
|
+
print("\nSaved to unit_tests.txt")
|
|
34
|
+
|
|
35
|
+
bug_prompt = (
|
|
36
|
+
f"Find syntax, logic, runtime, boundary, and input handling bugs "
|
|
37
|
+
f"in this Python code and suggest corrections:\n{code}"
|
|
38
|
+
)
|
|
39
|
+
bugs = model.generate_content(bug_prompt).text.strip()
|
|
40
|
+
if not bugs:
|
|
41
|
+
raise ValueError("Empty bug report response from Gemini API.")
|
|
42
|
+
|
|
43
|
+
print(f"\n--- Bug Detection Report ---\n{bugs}")
|
|
44
|
+
with open("bug_report.txt", "w", encoding="utf-8") as f:
|
|
45
|
+
f.write(bugs)
|
|
46
|
+
print("\nSaved to bug_report.txt")
|
|
47
|
+
|
|
48
|
+
except Exception as e:
|
|
49
|
+
print("Error:", e)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
def read_int(msg, min_val=0):
|
|
2
|
+
while True:
|
|
3
|
+
try:
|
|
4
|
+
val = int(input(msg))
|
|
5
|
+
if val >= min_val:
|
|
6
|
+
return val
|
|
7
|
+
except ValueError:
|
|
8
|
+
pass
|
|
9
|
+
print(f"Invalid value! Enter an integer >= {min_val}.")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
v = read_int("Enter number of vertices: ", 1)
|
|
13
|
+
e = read_int("Enter number of edges: ", 0)
|
|
14
|
+
|
|
15
|
+
graph = {i: [] for i in range(v)}
|
|
16
|
+
print(f"Vertices are 0 to {v - 1}")
|
|
17
|
+
|
|
18
|
+
for i in range(e):
|
|
19
|
+
while True:
|
|
20
|
+
try:
|
|
21
|
+
u, w = map(int, input(f"Enter edge {i + 1} (u v): ").split())
|
|
22
|
+
if 0 <= u < v and 0 <= w < v:
|
|
23
|
+
graph[u].append(w)
|
|
24
|
+
graph[w].append(u)
|
|
25
|
+
break
|
|
26
|
+
except ValueError:
|
|
27
|
+
pass
|
|
28
|
+
print("Invalid vertices! Try again.")
|
|
29
|
+
|
|
30
|
+
while True:
|
|
31
|
+
start = read_int("Enter starting vertex: ", 0)
|
|
32
|
+
if start < v:
|
|
33
|
+
break
|
|
34
|
+
print("Invalid starting vertex!")
|
|
35
|
+
|
|
36
|
+
visited = {start}
|
|
37
|
+
queue = [start]
|
|
38
|
+
order = []
|
|
39
|
+
|
|
40
|
+
while queue:
|
|
41
|
+
node = queue.pop(0)
|
|
42
|
+
order.append(node)
|
|
43
|
+
for nb in graph[node]:
|
|
44
|
+
if nb not in visited:
|
|
45
|
+
visited.add(nb)
|
|
46
|
+
queue.append(nb)
|
|
47
|
+
|
|
48
|
+
print("BFS Traversal:", order)
|