Open essepuntato opened 3 years ago
I don't know if this basic flowchart will be fine as an answer, I hope so! Maybe a practical example could be the comparison between two strings. The decision widget can check if the two strings share the same alphanumeric characters in the same positions and if the two strings have the same length. Another example could be the comparison between two files, if they are the same type or not (PDF, RTF, JPG...), but I don't think a shared type can exactly define two objects as "the same".
I think the algorithm can be represented through this flowchart:
I wrote this in a couple of hours, not continuously but taking some breaks. I've been a little slow and I hope to be faster in the future. I remember some math from high school, so I'm sure that there will be another mathematical form for what I've written in the algorithm. I don't want to seem picky, I want to make the conversation start 😁 Let me know what you think
According to the Oxford Dictionary, a letter is a written or printed sign representing a sound used in speech (https://www.oxfordlearnersdictionaries.com/definition/english/letter_1) .
So, for this example, we'll have in mind as input the words "SHOOT" and "SHOUT".
It is asked to input two words, and after that, to name them F(X) and G(Y) where X and Y indicate respectively the number of signs in the two words. If you want to take the example of SHOOT and SHOUT, we'll assume that SHOOT will be F(5) and SHOUT will be G(5).
After that, it is informed that, if the two numbers X and Y are the same, we have a chance that the algorithm will give as output "yes" (i.e. it would mean that the two words had the same sign number).
Next passage consists in naming every letter of the two words in numbers, respectively starting from 1 for A and so on. It doesn't matter if the signs are in the uppercase or lowercase format.
Then it is asked to sum the first and the last number in G(X) and check if is the same as the sum of first and last number in F(Y).
If yes, it means that the two words in the input start and end with the same sign. This is another step that give the algorithm a chance that it will give as output "yes".
A word has to have at least two signs. So in the next passage the flowline leads to a decision widget to see if the word constists in two signs of more.
If the signs are more, the flowline conducts the algorithm to a process widget, through which the algorithm will be able to know how many signs in the words are left, apart from the first and the last sign. (See the photo below)
So, if α= X-2=Y-2, where 2 is to exclude the first and last signs of the two words given as input, then (X-α) = (Y-α) will indicate the remaining letters in the two words, both F(X) and G(Y).
At this point, what the algorithm have to check is whether the two words are the same or not.
So the algorithm will go through a process widget: every remaining sign in the two input words, transformed in number before, will get an indicative name: x₂ x₃ for signs in G(X) ... and y₂ y₃ for signs in F(Y)... The numbers in subscript start from 2, since the first and last sign are excluded from this reasoning.
If the sum between the x₂ + x₃ ... is equal to the sum between y₂ + y₃ ... , then the agorithm will get as output "yes". Otherwise, the two words will not be equal and the algorithm will return "no".
Hi all,
There are a few suggestions I list here that may be useful to improve your diagram and, in general, for even the future diagrams you will have to define:
A note for @teragramgius: what happens if I run the algorithm specifying as input "shoot" and "thoos"?
All right, you got me🤣 Thank you🤝
def alg(obj_1, obj_2):
if obj_1 == obj_2:
return "yes"
else:
return "no"
print(alg("skyrim", "oblivion"))
print(alg("skyrim", "Skyrim"))
print(alg("skyrim", "skyrim"))
def test_alg(obj_1, obj_2, expected):
result = alg(obj_1, obj_2)
if result == expected:
return True
else:
return False
print(test_alg("skyrim", "oblivion", "no"))
print(test_alg("skyrim", "Skyrim", "no"))
print(test_alg("skyrim", "skyrim", "yes"))
OUTPUT:
no
no
yes
True
True
True
Hope that's fine
Write the flowchart of an algorithm that takes in input two objects and returns the string “yes” whether the two objects are the same; otherwise, it returns the string “no”.