I'm an indie dev that codes mostly in Java :)
jasonhorkles / discord-bots Goto Github PK
View Code? Open in Web Editor NEWDiscord bots I made
License: GNU General Public License v3.0
Discord bots I made
License: GNU General Public License v3.0
This affects words with two letters in it. Only one E should be highlighted:
Here is the fix, but written in Python. The zip()
function btw lets me have multiple variables in a for loop.
First, it tallies the number of letters in the answer, then as it checks the guess, it decreases the tally for letters the exact place (first) then any letters left that are misplaced (second)
class LetterType:
WRONG = 'โฌ'
MISPLACED = '๐จ'
EXACT = '๐ฉ'
def highlight(guess, answer):
highlights = [LetterType.WRONG for i in answer]
# Tallying
answer_tally = {}
for letter in answer:
if answer_tally.get(letter) is not None:
continue
answer_tally[letter] = answer.count(letter)
print("Answer:", answer)
print("Guess: ", guess)
# Green pass
for i, current_letter_guess, current_letter_answer in zip(range(len(answer)), guess, answer):
if current_letter_guess != current_letter_answer:
continue
highlights[i] = LetterType.EXACT
answer_tally[current_letter_guess] -= 1
# Yellow pass
for i, current_letter_guess, current_letter_highlight in zip(range(len(answer)), guess, highlights):
if current_letter_highlight == LetterType.EXACT:
continue
if answer_tally.get(current_letter_guess) == 0 or answer_tally.get(current_letter_guess) is None:
continue
highlights[i] = LetterType.MISPLACED
answer_tally[current_letter_guess] -= 1
print(''.join(highlights))
return highlights
highlight("speed", "abide") # Expected: โฌโฌ๐จโฌ๐จ
highlight("speed", "erase") # Expected: ๐จโฌ๐จ๐จโฌ
highlight("speed", "steal") # Expected: ๐ฉโฌ๐ฉโฌโฌ
highlight("speed", "crepe") # Expected: โฌ๐จ๐ฉ๐จโฌ
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.