Skip to content

Commit

Permalink
More Pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
A-F-V committed Feb 23, 2024
1 parent 7121dc3 commit 2d031cf
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 417 deletions.
96 changes: 95 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,100 @@
# Project Less

![Photo](Less%20Code%20Example.PNG)
# Results

## Example:

> Query:
> In the file 'edit_distance/edit_distance.py', there is function called '`lowest_...`'. Edit the function by using better names #for the variables. Do not rename the function"
**Old Code**:

```python
# ...
def lowest_cost_action(ic, dc, sc, im, dm, sm, cost) -> str:
"""Given the following values, choose the action (insertion, deletion,
or substitution), that results in the lowest cost (ties are broken using
the 'match' score). This is used within the dynamic programming algorithm.
* ic - insertion cost
* dc - deletion cost
* sc - substitution cost
* im - insertion match (score)
* dm - deletion match (score)
* sm - substitution match (score)
"""
best_action = None
best_match_count = -1
min_cost = min(ic, dc, sc)
if min_cost == sc and cost == 0:
best_action = EQUAL
best_match_count = sm
elif min_cost == sc and cost == 1:
best_action = REPLACE
best_match_count = sm
elif min_cost == ic and im > best_match_count:
best_action = INSERT
best_match_count = im
elif min_cost == dc and dm > best_match_count:
best_action = DELETE
best_match_count = dm
else:
raise Exception("internal error: invalid lowest cost action")
return best_action
```

**New Code**

```python
#...
def lowest_cost_action(insertion_cost, deletion_cost, substitution_cost, insertion_match, deletion_match, substitution_match, cost) -> str:
"""Given the following values, choose the action (insertion, deletion,
or substitution), that results in the lowest cost (ties are broken using
the 'match' score). This is used within the dynamic programming algorithm.
* insertion_cost - insertion cost
* deletion_cost - deletion cost
* substitution_cost - substitution cost
* insertion_match - insertion match (score)
* deletion_match - deletion match (score)
* substitution_match - substitution match (score)
"""
best_action = None
best_match_count = -1
min_cost = min(insertion_cost, deletion_cost, substitution_cost)
if min_cost == substitution_cost and cost == 0:
best_action = EQUAL
best_match_count = substitution_match
elif min_cost == substitution_cost and cost == 1:
best_action = REPLACE
best_match_count = substitution_match
elif min_cost == insertion_cost and insertion_match > best_match_count:
best_action = INSERT
best_match_count = insertion_match
elif min_cost == deletion_cost and deletion_match > best_match_count:
best_action = DELETE
best_match_count = deletion_match
else:
raise Exception("internal error: invalid lowest cost action")
return best_action

```

Git Diff:
![Photo](pics/git%20diff.PNG)

State and History of Agent:
![Photo](pics/Less%20Code%20Example.PNG)

# Running

Expand Down
Loading

0 comments on commit 2d031cf

Please sign in to comment.