Skip to content

Commit

Permalink
update formula functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
kv9898 committed Sep 23, 2024
1 parent bb22006 commit d96dc14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
33 changes: 24 additions & 9 deletions GUI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
#import os
from itertools import permutations
from PySide6.QtWidgets import (QApplication, QWidget, QMainWindow, QLineEdit, QLabel,
QHBoxLayout, QVBoxLayout, QGridLayout, QFrame)
from PySide6.QtCore import Qt, QPoint, QMimeData, QEvent
Expand All @@ -10,7 +9,28 @@ def compute(formula):
fml, outcome = formula.split("=")
fml = fml.split("+")

answers = ["".join([str(x) for x in list(a)]) for a in permutations([1, 2, 3, 4])]
def IsColor(input_string):
r = "r" in input_string
g = "g" in input_string
b = "b" in input_string
y = "y" in input_string
return (r or g or b or y)

def get_outcome(input_sequence, output_sequence):
map = {i:n for n,i in enumerate(input_sequence)}
outcome = [map[o]+1 for o in output_sequence]
return("".join(str(x) for x in outcome))

# if outcome and the first element of fml contains any of "y", "b", "g", "red",
# then we need to execute get_outcome()
if IsColor(outcome) and IsColor(fml[0]):
outcome = get_outcome(fml[0], outcome)
fml = fml[1:]

#answers = ["".join([str(x) for x in list(a)]) for a in permutations([1, 2, 3, 4])]
answers = ['1234', '1243', '1324', '1342', '1423', '1432', '2134', '2143', '2314', '2341',
'2413', '2431', '3124', '3142', '3214', '3241', '3412', '3421', '4123', '4132',
'4213', '4231', '4312', '4321']

def switch(a, b):
a = {o:i for o,i in enumerate(a)}
Expand Down Expand Up @@ -186,11 +206,6 @@ def clear_lineedits():
window.line_edit.clear()
window.result.clear()

def get_outcome():
map = {i:n for n,i in enumerate(input_sequence)}
outcome = [map[o]+1 for o in output_sequence]
return("".join(str(x) for x in outcome))

class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
Expand Down Expand Up @@ -241,9 +256,9 @@ def keyPressEvent(self, event):
self.result.setText(get_outcome())
else:
if self.line_edit.text().endswith("="):
formula = self.line_edit.text()+get_outcome()
formula = input_sequence + '+' + self.line_edit.text() + output_sequence
else:
formula = self.line_edit.text()+'='+get_outcome()
formula = input_sequence + '+' + self.line_edit.text()+ '=' + output_sequence
self.result.setText(compute(formula))
else:
super().keyPressEvent(event)
Expand Down
26 changes: 22 additions & 4 deletions command_line.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
from itertools import permutations

def compute(formula):
fml, outcome = formula.split("=")
fml = fml.split("+")
#fml.insert(0, "1234")

answers = ["".join([str(x) for x in list(a)]) for a in permutations([1, 2, 3, 4])]
def IsColor(input_string):
r = "r" in input_string
g = "g" in input_string
b = "b" in input_string
y = "y" in input_string
return (r or g or b or y)

def get_outcome(input_sequence, output_sequence):
map = {i:n for n,i in enumerate(input_sequence)}
outcome = [map[o]+1 for o in output_sequence]
return("".join(str(x) for x in outcome))

# if outcome and the first element of fml contains any of "y", "b", "g", "red",
# then we need to execute get_outcome()
if IsColor(outcome) and IsColor(fml[0]):
outcome = get_outcome(fml[0], outcome)
fml = fml[1:]

#answers = ["".join([str(x) for x in list(a)]) for a in permutations([1, 2, 3, 4])]
answers = ['1234', '1243', '1324', '1342', '1423', '1432', '2134', '2143', '2314', '2341',
'2413', '2431', '3124', '3142', '3214', '3241', '3412', '3421', '4123', '4132',
'4213', '4231', '4312', '4321']

def switch(a, b):
a = {o:i for o,i in enumerate(a)}
Expand Down

0 comments on commit d96dc14

Please sign in to comment.