RosettaCodeData/Task/Amb/Yabasic/amb.basic

36 lines
1020 B
Plaintext

sub wordsOK(string1$, string2$)
return right$(string1$, 1) == left$(string2$, 1)
End sub
sub Amb$(A$(), B$(), C$(), D$())
local a2, b2, c2, d2
For a2 = 1 To arraysize(A$(), 1)
For b2 = 1 To arraysize(B$(), 1)
For c2 = 1 To arraysize(C$(), 1)
For d2 = 1 To arraysize(D$(), 1)
If wordsOK(A$(a2), B$(b2)) And wordsOK(B$(b2), C$(c2)) And wordsOK(C$(c2), D$(d2)) Then
Return A$(a2) + " " + B$(b2) + " " + C$(c2) + " " + D$(d2)
End If
Next
Next
Next
Next
Return ""
End sub
Dim set1$(1), set2$(1), set3$(1), set4$(1)
void = token("the that a", set1$())
void = token("frog elephant thing", set2$())
void = token("walked treaded grows", set3$())
void = token("slowly quickly", set4$())
result$ = Amb$(set1$(), set2$(), set3$(), set4$())
If result$ <> "" Then
Print "Correct sentence would be: ", result$
Else
Print "Failed to fine a correct sentence."
End If