Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
lecture-code
Commits
a640fb0a
Commit
a640fb0a
authored
4 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
autocommit
parent
16276f93
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
06/wordle1.py
+42
-3
06/wordle1.py
with
42 additions
and
3 deletions
+42
-3
06/wordle1.py
View file @
a640fb0a
...
...
@@ -19,15 +19,54 @@ def is_valid_guess(guess: str):
def
how_many_exact_matches
(
word1
:
str
,
word2
:
str
)
->
int
:
...
count
:
int
=
0
for
i
in
range
(
len
(
word1
)):
if
word1
[
i
]
==
word2
[
i
]:
count
+=
1
return
count
def
get_counts_of_letters_1
(
word
:
str
)
->
dict
[
str
,
int
]:
d
:
dict
[
str
,
int
]
=
{}
for
letter
in
UPPERCASE_LETTERS
:
count
:
int
=
0
for
c
in
word
:
if
c
==
letter
:
count
+=
1
d
[
letter
]
=
count
return
d
def
get_counts_of_letters
(
word
:
str
)
->
dict
[
str
,
int
]:
...
d
:
dict
[
str
,
int
]
=
{}
for
c
in
word
:
if
c
in
d
:
d
[
c
]
=
d
[
c
]
+
1
else
:
d
[
c
]
=
0
+
1
return
d
def
how_many_overall_matches
(
guess
:
str
,
answer
:
str
)
->
int
:
...
guess_count
=
get_counts_of_letters
(
guess
)
answer_count
=
get_counts_of_letters
(
answer
)
count
:
int
=
0
for
letter
in
UPPERCASE_LETTERS
:
count_a
:
int
=
0
if
letter
in
guess_count
:
count_a
=
guess_count
[
letter
]
count_b
:
int
=
0
if
letter
in
answer_count
:
count_b
=
answer_count
[
letter
]
count
+=
min
(
count_a
,
count_b
)
return
count
print
(
how_many_overall_matches
(
"AAB"
,
"BAC"
))
def
play_wordle_game
():
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help