Here is a programming challenge. Make a function for these examples.
In[]:=
matrixFunction[1]={{1}}
Out[]=
{{1}}
In[]:=
matrixFunction[1]
Out[]=
{{1}}
In[]:=
matrixFunction[2]=
1
1
1
1

Out[]=
{{1,1},{1,1}}
In[]:=
matrixFunction[3]=
1
1
1
1
2
1
1
1
1
Out[]=
{{1,1,1},{1,2,1},{1,1,1}}
In[]:=
matrixFunction[4]=
1
1
1
1
1
2
2
1
1
2
2
1
1
1
1
1
Out[]=
{{1,1,1,1},{1,2,2,1},{1,2,2,1},{1,1,1,1}}
In[]:=
matrixFunction[5]=
1
1
1
1
1
1
2
2
2
1
1
2
3
2
1
1
2
2
2
1
1
1
1
1
1
Out[]=
{{1,1,1,1,1},{1,2,2,2,1},{1,2,3,2,1},{1,2,2,2,1},{1,1,1,1,1}}
In[]:=
matrixFunction[6]=
1
1
1
1
1
1
1
2
2
2
2
1
1
2
3
3
2
1
1
2
3
3
2
1
1
2
2
2
2
1
1
1
1
1
1
1
Out[]=
{{1,1,1,1,1,1},{1,2,2,2,2,1},{1,2,3,3,2,1},{1,2,3,3,2,1},{1,2,2,2,2,1},{1,1,1,1,1,1}}
In[]:=
matrixFunction[7]=
1
1
1
1
1
1
1
1
2
2
2
2
2
1
1
2
3
3
3
2
1
1
2
3
4
3
2
1
1
2
3
3
3
2
1
1
2
2
2
2
2
1
1
1
1
1
1
1
1
Out[]=
{{1,1,1,1,1,1,1},{1,2,2,2,2,2,1},{1,2,3,3,3,2,1},{1,2,3,4,3,2,1},{1,2,3,3,3,2,1},{1,2,2,2,2,2,1},{1,1,1,1,1,1,1}}
We will now solve this with LLMExampleFunction.
In[]:=
fun=LLMExampleFunction2->
1
1
1
1
,3->
1
1
1
1
2
1
1
1
1
,4->
1
1
1
1
1
2
2
1
1
2
2
1
1
1
1
1
,5->
1
1
1
1
1
1
2
2
2
1
1
2
3
2
1
1
2
2
2
1
1
1
1
1
1
,6->
1
1
1
1
1
1
1
2
2
2
2
1
1
2
3
3
2
1
1
2
3
3
2
1
1
2
2
2
2
1
1
1
1
1
1
1
,7->
1
1
1
1
1
1
1
1
2
2
2
2
2
1
1
2
3
3
3
2
1
1
2
3
4
3
2
1
1
2
3
3
3
2
1
1
2
2
2
2
2
1
1
1
1
1
1
1
1

Out[]=
LLMFunction
​
Content: Input: 2Output: {{1, 1}, {1, 1}}​Input: 3Output: {{1, 1, 1}, {1, 2, 1}, {1, 1, 1}}​Input: 4Output: {{1, 1, 1, 1}, {1, 2, 2, 1}, {1, 2, 2, 1}, {1, 1, 1, 1}}​Input: 5Output: {{1, 1, 1, 1, 1}, {1, 2, 2, 2, 1}, {1, 2, 3, 2, 1}, {1, 2, 2, 2, 1}, {1, 1, 1, 1, 1}}​Input: 6Output: {{1, 1, 1, 1, 1, 1}, {1, 2, 2, 2, 2, 1}, {1, 2, 3, 3, 2, 1}, {1, 2, 3, 3, 2, 1}, {1, 2, 2, 2, 2, 1}, {1, 1, 1, 1, 1, 1}}​Input: 7Output: {{1, 1, 1, 1, 1, 1, 1}, {1, 2, 2, 2, 2, 2, 1}, {1, 2, 3, 3, 3, 2, 1}, {1, 2, 3, 4, 3, 2, 1}, {1, 2, 3, 3, 3, 2, 1}, {1, 2, 2, 2, 2, 2, 1}, {1, 1, 1, 1, 1, 1, 1}}​Input:
1
Output:
Parameters: 1

The output is a string.
In[]:=
fun[4]
Out[]=
{{1, 1, 1, 1}, {1, 2, 2, 1}, {1, 2, 2, 1}, {1, 1, 1, 1}}
In[]:=
Out[29]//InputForm
Out[]//InputForm=
{{1, 1, 1, 1}, {1, 2, 2, 1}, {1, 2, 2, 1}, {1, 1, \
1, 1}}
In[]:=
ToExpression[Out[29]]
Out[]=
{{1,1,1,1},{1,2,2,1},{1,2,2,1},{1,1,1,1}}
We can now put it in MatrixForm:
In[]:=
MatrixForm[ToExpression[Out[29]]]
Out[]//MatrixForm=
1
1
1
1
1
2
2
1
1
2
2
1
1
1
1
1
I can now define a function that works:
In[]:=
AIMatrixFunction[n_Integer?IntegerQ]:=ToExpression[Out[33][n]]
Test the function.
In[]:=
MatrixForm/@AIMatrixFunction/@Range[1,7]
Out[]=
(
1
),
1
1
1
1
,
1
1
1
1
2
1
1
1
1
,
1
1
1
1
1
2
2
1
1
2
2
1
1
1
1
1
,
1
1
1
1
1
1
2
2
2
1
1
2
3
2
1
1
2
2
2
1
1
1
1
1
1
,
1
1
1
1
1
1
1
2
2
2
2
1
1
2
3
3
2
1
1
2
3
3
2
1
1
2
2
2
2
1
1
1
1
1
1
1
,
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
1
1
2
3
3
3
3
2
1
1
2
3
4
4
3
2
1
1
2
3
4
4
3
2
1
1
2
3
3
3
3
2
1
1
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1


Regular Expression example.

This is from an exercise for class. I have to write a Python program but I can also do it with LLMExampleFunction.
For this exercise, you will be working with a list of names and phone numbers. This list is in a
single text file with one data point per line. The list was compiled from multiple sources and the
formatting is not consistent. Each line of the file has a name and a phone number. An example
file is shown below.
​
Joan Smith 304 696-0001
Smith, Frank 999-012-2345
(304) 555-1212 Bobby Johnson
Jane Frank 304 654 3210
3044327777 Smith-Jones, Destiny
​
As you can see, the names can be before or after the phone numbers. The number itself may
have spaces, dashes, and/or parentheses. However, there are never any gaps between the digits
of the area code, never any gaps between the digits of the prefix, and never any gaps between
the digits of the line number (final 4 digits). Each line of the file has just a name and phone
number, and the names never contain digits.
​
Your goal is to extract a list of just the phone numbers, in the format “(304) 123-4567”. For
the file above, the output should be exactly as shown below.
​
(304) 696-0001
(999) 012-2345
(304) 555-1212
(304) 654-3210
(304) 432-7777
• Use the Python regular expression library to do this, do not write any kind of custom parser.
I want to make a text file public so I will change $Permissions with Block.
In[]:=
$Permissions
Out[]=
Private
In[]:=
Block[{$Permissions="Public"},$Permissions]
Out[]=
Public
In[]:=
FileNameSplitFile
"C:\\Users\\peter\\OneDrive - Marshall University\\Documents\\fall-2023\\automata-and-formal-languages\\homework\\cs-360-homework-2b-input-file.txt"

Out[]=
{C:,Users,peter,OneDrive - Marshall University,Documents,fall-2023,automata-and-formal-languages,homework,cs-360-homework-2b-input-file.txt}
In[]:=
TakeFileNameSplitFile
"C:\\Users\\peter\\OneDrive - Marshall University\\Documents\\fall-2023\\automata-and-formal-languages\\homework\\cs-360-homework-2b-input-file.txt"
,6;;
Out[]=
{fall-2023,automata-and-formal-languages,homework,cs-360-homework-2b-input-file.txt}
In[]:=
StringRiffleTakeFileNameSplitFile
"C:\\Users\\peter\\OneDrive - Marshall University\\Documents\\fall-2023\\automata-and-formal-languages\\homework\\cs-360-homework-2b-input-file.txt"
,6;;,"/"
Out[]=
fall-2023/automata-and-formal-languages/homework/cs-360-homework-2b-input-file.txt
In[]:=
CloudObjectStringRiffleTakeFileNameSplitFile
"C:\\Users\\peter\\OneDrive - Marshall University\\Documents\\fall-2023\\automata-and-formal-languages\\homework\\cs-360-homework-2b-input-file.txt"
,6;;,"/"
Out[]=
CloudObject[
https://www.wolframcloud.com/obj/burbery1/fall-2023/automata-and-formal-languages/homework/cs-360-ho
mework-2b-input-file.txt
]
In[]:=
Block{$Permissions="Public"},CopyFileFile
"C:\\Users\\peter\\OneDrive - Marshall University\\Documents\\fall-2023\\automata-and-formal-languages\\homework\\cs-360-homework-2b-input-file.txt"
,CloudObjectStringRiffleTakeFileNameSplitFile
"C:\\Users\\peter\\OneDrive - Marshall University\\Documents\\fall-2023\\automata-and-formal-languages\\homework\\cs-360-homework-2b-input-file.txt"
,6;;,"/"
Out[]=
CloudObject[
https://www.wolframcloud.com/obj/burbery1/fall-2023/automata-and-formal-languages/homework/cs-360-ho
mework-2b-input-file.txt
]
In[]:=
CloudImport[CloudObject[
https://www.wolframcloud.com/obj/burbery1/fall-2023/automata-and-formal-languages/homewo
rk/cs-360-homework-2b-input-file.txt
],"List"]
Test the function: