Decodes message from file based on number in each line of text.
Attached file ... coding_qual_input.txt
has lines of text, each line has number, then space, then text
The goal is to read these lines and create full statements based on numbers in each line
The numbers are as below, triangular number, meaning
1, 3, 6, 10, 15, 21, 28, ....
Found formula online
n = any integer
xn = number found in text
xn = n (n + 1) / 2
n = (sqr(8 * xn + 1) - 1) / 2
Result from attached file
huge wish electric lot visit offer all our system now card current way check parent whole design skill wait man people deal planet moment
This one was part of longer task I was told to fix today.
Function FileSpecialDecode(message_file)
Open message_file For Input As #1
mssg = Input(LOF(1), #1)
outmsg = ""
For Each line1 In Split(mssg, vbCrLf)
If line1 > "" Then
line1_1 = CInt(Left(line1, InStr(line1, " ") - 1))
line1_2 = Mid(line1, InStr(line1, " ") + 1)
line1_3 = (8 * line1_1) + 1 ' [ n = \frac{{\sqrt{{8x_n + 1}} - 1}}{2} ]
line1_3 = Sqr(line1_3) - 1
line1_3 = line1_3 / 2
If line1_3 = CInt(line1_3) Then outmsg = outmsg & line1_2 & " "
End If
Next
FileSpecialDecode = outmsg
Close
End Function
Open message_file For Input As #1
mssg = Input(LOF(1), #1)
outmsg = ""
For Each line1 In Split(mssg, vbCrLf)
If line1 > "" Then
line1_1 = CInt(Left(line1, InStr(line1, " ") - 1))
line1_2 = Mid(line1, InStr(line1, " ") + 1)
line1_3 = (8 * line1_1) + 1 ' [ n = \frac{{\sqrt{{8x_n + 1}} - 1}}{2} ]
line1_3 = Sqr(line1_3) - 1
line1_3 = line1_3 / 2
If line1_3 = CInt(line1_3) Then outmsg = outmsg & line1_2 & " "
End If
Next
FileSpecialDecode = outmsg
Close
End Function
message_file
Views 429
Downloads 65
CodeID
DB ID