Skip to content

Instantly share code, notes, and snippets.

@WorryingWonton
WorryingWonton / lacewords.py
Last active July 12, 2023 07:54
Program to cheat at the iOS game Word Laces
from itertools import permutations
class LaceWords:
def __init__(self, dictionary=None, interface=None):
self.dictionary = dictionary
if not dictionary:
self.dictionary = 'scrabble_2020_dict'
self.interface = interface
if not self.interface:
@WorryingWonton
WorryingWonton / temperature_mk_2.py
Created March 19, 2019 16:28
Temperature Converter
def temp_converter(temps, mode, reversed):
return {'f': lambda x, y: [((temp - 32) * 5/9 + 273.15 if not y else (temp - 273.15) * 9/5 + 32) for temp in x],
'k': lambda x, y: x,
'c': lambda x, y: [temp + (273.15 if not y else -273.15) for temp in x]}[mode](temps, reversed)
def format_outputs(temps, mode):
return f'°{mode[-1].upper()}, '.join(map(lambda temp: str(round(temp, 2)), temps)) + f'°{mode[-1].upper()}'
if __name__ == '__main__':
mode = input('What temperature scales would you like to convert between? ').lower()
@WorryingWonton
WorryingWonton / next_player_selector.py
Last active October 31, 2018 05:50
New method of selecting the next active player, which does not require any refactoring of the Monopoly code outside of monopoly.py
import unittest
from itertools import cycle
"""
There's a very bad pattern in my code with having to run a filter operation in two separate methods on Game.players
How do I fix this? (See lines 16 and 30)
"""
class Game:
def __init__(self):
self.all_players = []
class Node:
def __init__(self, data, p_node=None, n_node=None):
self.p_node = p_node
self.n_node = n_node
self.data = data
class LList:
def __init__(self):
self.length = 0
self.first = None
@WorryingWonton
WorryingWonton / arg_list_parser_3.py
Created June 4, 2018 07:12
Tuple work-around for parse error caused by multiple inputs to a function in Java
#See the terminal symbol 'arg_list' in cbat_grammar
#I noticed that functions on CodingBat were always in the form 'function_name' '(' 'arg' (',' 'whitespace_token'? arg)* ')'
#My grammar originally didn't have a way to deal with this.
#It could deal with multiple arguments in an array or map, but multiple-
#comma separated arguments not in a container literal would cause Lark to fail.
#To get around this, I figured I could treate the parentheses around the function arguments as a tuple, so... that's what I've done.
#Thus far it seems to work, though it feels inelegant.
from lark import Transformer, Lark
from lark import Transformer, Lark
cbat_grammar = """
?literal : string
| char
| array
| map
| int
| float
| boolean
array : "[" [literal ("," literal)*] "]"
from lark import Transformer
cbat_grammar = """
?literal : string
| char
| array
| map
| int
| float
| boolean
class QuestionA:
def __init__(self, question_dict):
self.question_dict = question_dict
class QuestionB:
def __init__(self, question_text, answer_dict):
self.question_text = question_text
self.answer_dict = answer_dict