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):

=================================

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}

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}

You silly goof, write an interpreter and then run the code to see what happens. I guarantee that you'll get the job. :)

^^^

Smart, only thing is I don't have knowledge of that, I'm a rookie

I didn't even know you could write interpreters, how do i do that?

:)

And you're applying for a software engineer position? To be perfectly frank, if you're having trouble with this then maybe you aren't right for the job. Let's go over question 4:

@OT,1@W0@N0,{2,4,6,8}@W0@N0,3@W0@N0@F0@R0

Functions begin with @, and the operation for each function has been given already. So, start at the beginning:

@OT creates a file to work with. The language specification doesn't say what a comma outside of braces does, so you have to make an assumption. In this case, we'll ignore them until told otherwise. An atom declaration places that atom in the register, so

register = 1

@W0 writes the contents of the register to the file we just created, so

register = 1
record = 1

@N0 moves to the next record in file 0 so that a subsequent write operation will not overwrite what we wrote previously. There's no change in either the register or the record.

A list declaration does the same thing as an atom declaration, {2,4,6,8} is placed in the register and overwrites 1, so

register = {2,4,6,8}
record = 1

@W0 writes the contents of the register to the current record, which is the record after 1 in file 0, so

register = {2,4,6,8}
record = {2,4,6,8}
file:
1
{2,4,6,8}

@N0,3@W0@N0 moves to the next record, pushes 3 into the register, writes 3 to the file 0, and moves to the next record, leaving you with

register = 3
record = 3
file:
1
{2,4,6,8}
3

@F0 resets the file index to 0, so you're looking back at the first record, giving you

register = 3
record = 1
file:
1
{2,4,6,8}
3

@R0 reads the current record into the register, so the final answer is

register = 1
record = 1

Use the same analysis for the other questions and the problem becomes much easier.

>I didn't even know you could write interpreters, how do i do that?
Just for fun, I might write one. If I do then I'll post it. :)

And you're applying for a software engineer position? To be perfectly frank, if you're having trouble with this then maybe you aren't right for the job.

>I didn't even know you could write interpreters, how do i do that?
Just for fun, I might write one. If I do then I'll post it. :)

Yeah I see what you are saying, it seems that way but I am good a programming, I was the best in all my programming classes (Java, C++, C++ advanced, Visual "Easy" Basic, etc.) , problem is i don't own a computer and i haven't coded since my last class which was about 3 yrs ago. I'm very rusty and have a lot of catching up to do. I really need to invest in a computer, that's what's really keeping me back.

I'll read the instructions (in its entirety), try it myself before looking at your answers, and see what I can come up with.

Thanks for the help, i'm interested in seeing how to make a compiler, i was just reading up on how to make one in java but the online example i just found was incomplete and didn't tell me much. If you make one post it and email me :) fasola456@yahoo.com

Narue,

Okay this is my answer before looking at yours:

Question 4

@OT,1@W0@N0,{2,4,6,8}@W0@N0,3@W0@N0@F0@R0

what is the Register = 1
what is the Record =

1
{2,4,6,8}
3

=======================

I think im good :)

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}

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 = 1
what is the Record =

1
{2,4,6,8}
3

Question 5

@R0+(@N0@R0|1)+(@N0@R0)

what is the Register = 8
what is the Record =

1
{2,4,6,8}
3

Question 6

@F0@N0@R0|2@N0@W0

what is the Register = 6
what is the Record =

1
{2,4,6,8}
6

Question 7

@F0@R0+(@L0@R0)

what is the Register = 7
what is the Record =

1
{2,4,6,8}
6

Question 8

@P0@R0|{1,2}@L0@N0@W0|0

what is the Register = 4
what is the Record =

1
{2,4,6,8}
6
{4,6}

Question 9

@R0@+@W0

what is the Register = 10
what is the Record =

1
{2,4,6,8}
6
10

Question 10

@F0@N0@R0|0@N0@N0+@R0@CT

what is the Register = 10
what is the Record =

1
{2,4,6,8}
6
10

Question 11

Write the code to produce the following file:

{"A","B"}
"C"
{1,2,3}
{4,5,6}

@OT, {"A", "B"}@W0@N0, "C"@W0@N0, {1,2,3}@W0@N0, {4,5,6}@W0@CT

OR

@OT, {"A","B","C"}|{0,1}@W0@N0|2@W0@N0, {1,2,3,4,5,6}|{0,1,2}@W0@N0|{3,4,5}@W0@CT

i'm thinking the register in question 10 should be 2 + 10, which equals 12, not 10

>i'm thinking the register in question 10 should be 2 + 10, which equals 12, not 10
You beat me to that one.

>@OT, {"A","B","C"}|{0,1}@W0@N0|2@W0@N0, {1,2,3,4,5,6}|{0,1,2}@W0@N0|{3,4,5}@W0@CT
Don't forget that indexing a list places a new list in the register.

lol @ You beat me to that one.

hmmmm...thinks about > Don't forget that indexing a list places a new list in the register

*looks for problem*

in the meantime we should play chess, do you know how to play?

That's like checkers with six classes of pieces that move differently, right. ;)

Did you get the position?

It seems like the codes submitted for this new language is accurate. Are you located in Atlanta?

Thanks

^^^

Smart, only thing is I don't have knowledge of that, I'm a rookie

I didn't even know you could write interpreters, how do i do that?

:)

>Did you get the position?
It's generally better to send a private message for something like this than to resurrect a two year old thread started by a member who isn't active anymore.