I was given this today as a test to see if I could figure it out for a Software Engineer position. Proprietary Computer Language called Magic Lite. Below is exactly what they gave me (I'll put my answers up tomorrow):
=================================
Please answer the following questions about Magic Lite using the code instructions found below:
Magic Lite
Definitions:
Functions are defined as two character upper-case alphas preceded by an at sign (@). Functions will perform operations on a data register and leave their result in that register. If a function does not return a value, the value already in the register remains there.
OT
create temporary file 0
R0
read record from file 0 (returns a value - i.e. puts the record in the register)
W0
write contents of the register to the current record in file 0, overwriting the value that had been in that record
N0
move to next record in file 0
P0
move to previous record in file 0
F0
move to first record (head) of file 0
L0
move to last record (tail) of file 0
CT
close temporary file 0
All operations on file 0 are also valid on files 1-9. Records can contain atoms (text or numeric strings) or lists. Lists are bounded by braces (e.g. {}) and elements in those lists are separated by commas. An element of a list can be an atom or another list {0,1,2,3} is a list of the atoms 0,1, 2 and 3. Non-numeric text atoms need quotation marks (") around them.
The declaration of an atom or list replaces the existing value in the register with that atom or list.
| is the piece operator, acts on the register to extract elements from a list. The elements are numbered beginning with 0
{3,7,1}|1 returns 7
{3,7,1}@W0|1 would write {3,7,1} to file 0 and then execute |1 to return 7.
A list may be the argument to the piece operator. Each position listed is returned in a list
{"ABC","DEF","G",7}|{1,3} returns {"DEF",7}
+ is the addition operator
1+3 leaves 4 in the register
@+ is the list addition operator
{3,5}@+ returns 8
===========================================
The following lines of code build a file 0 with each line of code inheriting the state left after the previous line of code has executed. What are the results of the following lines of code: (i.e. what is left in the register and what does file 0 look like after executing each line of code)
Question 4
@OT,1@W0@N0,{2,4,6,8}@W0@N0,3@W0@N0@F0@R0
what is the Register =
what is the Record =
Question 5
@R0+(@N0@R0|1)+(@N0@R0)
what is the Register =
what is the Record =
Question 6
@F0@N0@R0|2@N0@W0
what is the Register =
what is the Record =
Question 7
@F0@R0+(@L0@R0)
what is the Register =
what is the Record =
Question 8
@P0@R0|{1,2}@L0@N0@W0|0
what is the Register =
what is the Record =
Question 9
@R0@+@W0
what is the Register =
what is the Record =
Question 10
@F0@N0@R0|0@N0@N0+@R0@CT
what is the Register =
what is the Record =
Question 11
Write the code to produce the following file:
{"A","B"}
"C"
{1,2,3}
{4,5,6}