This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def evaluate_guess(guess, current_dictionary): | |
| new_length = 0 | |
| for word in current_dictionary: | |
| if word == guess: | |
| continue | |
| scorer = Scorer(word) | |
| score = scorer.score(guess) | |
| new_dict = filter_dictionary(current_dictionary, score) | |
| new_length += len(new_dict) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def evaluate_solver(dictionary_filename: str, | |
| trials: str, | |
| solver_factory: Callable[[Scorer], WordleSolver], | |
| scorer=Scorer()): | |
| five_letter_words = read_dictionary(dictionary_filename) | |
| successes = 0 | |
| total_score = 0 | |
| sum_of_squares = 0 | |
| for i in range(trials): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NaiveSolver(WordleSolver): | |
| def __init__(self, opener='SLATE'): | |
| self.opener = opener | |
| def guess_next_word(self, words_remaining, trial): | |
| if trial == 0: | |
| return self.opener | |
| return random_word(words_remaining) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def filter_word(word: str, score: dict) -> bool: | |
| for i, (letter, value) in enumerate(score): | |
| if value == -1 and letter in word: | |
| return False | |
| if value == 0 and (letter not in word or letter == word[i]): | |
| return False | |
| if value == 1 and not (letter == word[i]): | |
| return False | |
| return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def score_guess(secret: str, guess: str): | |
| score = [(letter, -1) for letter in guess] | |
| for i, letter in enumerate(guess): | |
| if secret[i] == guess[i]: | |
| score[i] = (letter, 1) | |
| elif guess[i] in secret: | |
| score[i] = (letter, 0) | |
| return score |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def play_wordle(dictionary, secret, solver: WordleSolver, scorer: Scorer = Scorer()): | |
| guesses = [] | |
| words_remaining = dictionary | |
| for i in range(6): | |
| guess = solver.guess_next_word(words_remaining, i) | |
| guesses.append(guess) | |
| score = scorer.score(secret, guess) | |
| if secret == guess: | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public ExchangeRateProvider exchangeRateProvider() { | |
| return MonetaryConversions.getExchangeRateProvider(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Profile("test") | |
| @Configuration | |
| public class TestConfig { | |
| @Bean | |
| public ExchangeRateProvider exchangeRateProvider() { | |
| return new TestingExchangeRateProvider(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TestingExchangeRateProvider extends AbstractRateProvider { | |
| public TestingExchangeRateProvider() { | |
| super(ProviderContext.of("TEST")); | |
| } | |
| @Override | |
| public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) { | |
| CurrencyUnit baseCurrency = conversionQuery.getBaseCurrency(); | |
| CurrencyUnit fromCurrency = conversionQuery.getCurrency(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Optional<Invoice> createClientInvoice(String clientId, LocalDate date) { | |
| List<Fee> fees = feeRepository.findByClientId(clientId); | |
| if (fees.isEmpty()) { | |
| return Optional.empty(); | |
| } | |
| Optional<Contract> optionalContract = contractRepository.findByClientId(clientId); | |
| if (optionalContract.isEmpty()) { | |
| return Optional.empty(); | |
| } | |
| Contract contract = optionalContract.get(); |