Skip to content

Instantly share code, notes, and snippets.

@ChristopherBilg
Last active October 2, 2023 22:40
Show Gist options
  • Save ChristopherBilg/bc4b217b7e7a111b94c3b886e9d6ebde to your computer and use it in GitHub Desktop.
Save ChristopherBilg/bc4b217b7e7a111b94c3b886e9d6ebde to your computer and use it in GitHub Desktop.
r/DailyProgrammer Rack Management 1
#!usr/bin/env python3
"""
This script is the r/DailyProgrammer Easy Challenge #294 titled
Rack Management 1.
Author: Christopher Bilger
"""
def scrabble(rack_str, desired_str):
"""
Function that will handle the scrabble rack_str as input and output a
boolean of whether or not the rack_str contains the letters to make
the desired_str.
@param str: current rack
@param str: desired word from rack
@return True if desired_str in rack_str, else False
"""
for letter in desired_str:
if letter in rack_str:
rack_str = rack_str.replace(letter, "", 1)
elif "?" in rack_str:
rack_str = rack_str.replace("?", "", 1)
else:
return False
# Empty sequence evaluates to False in Python; more 'Pythonic'
if not rack_str:
return True
def main():
"""
Main function that will be used to start the program.
"""
racks = []
with open("racks.txt", "r") as all_racks:
for rack in all_racks.readlines():
rack_io = rack.split(";")
racks.append([rack_io[0], rack_io[1][:-1]])
for rack_io in racks:
print("scrabble({}, {}) -> {}".format(
rack_io[0],
rack_io[1],
str(scrabble(rack_io[0], rack_io[1]))
))
if __name__ == '__main__':
main()
pizza??;pizzazz
piizza?;pizzazz
a??????;program
b??????;program
pizza??;pizzazz
piizza?;pizzazz
a??????;program
b??????;program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment