2 kyu
Assembler interpreter (part II)
1,029 of 2,757ShinuToki
Loading description...
Interpreters
Refactoring
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This exercise has a good concept, but several aspects could be improved. First, the specification of function returns is unclear, which can lead to confusion, especially when dealing with recursive calls. Additionally, jump instructions and labels need more details, such as what to do if a label is undefined. There’s also a lack of proper validation for instruction parameters and error management. It would be helpful if the prompt provided more details on handling spaces, comments in the code, and how to properly concatenate values in the msg instruction.
why this fail,it expect -1 but it doesn't jump to exit function since both not equal
mov i, 2 ; instruction mov i, 2 mov q, 12 ; instruction mov q, 12 call func msg 'Random result: ', n end
func: cmp i, q je exit mov n, i sub n, q ret ; Do nothing exit: msg 'Do nothing'
you're probably reading your test output wrong and mixing up test cases. also the formatting in your post is messed up :x
C# tests seem to be timing out on correct answer. Adding " " to output fails with only that as the error, but leaving it out times out every time.
I decided to learn Rust's Nom crate. Got a nice solution up and running with Nom, only to experience that Nom is not accepted. Nom has 158+ million downloads, and I will suggest that any rustacean would consider Nom for a task like this.
Allow Rust Nom crate!
You could save yourself the trouble by checking the list of available packages.
Additional packages can be requested by creating a ticket in the Codewars runner repository.
Thank you for answering. I have submitted my request.
Nice kata, too easy for 2kyu though
1-st 2 kyu kata in my life! Thanks for this xp, that was awesome. :)
The description contains incomplete information about the task; very important information is missing:
Loved this Kata! (Swift version) My solution is way over engineered: I ended up creating a full Tokenizer -> Parser -> Interpreter chain. But it was great fun. And something I wanted to explore anyway. Thanks for creating this Kata!
This comment has been hidden.
Could it be updated to a more recent Node version?
I have finished this on my machine, but I am unable to pass the tests because a bunch of functions and language features are missing.
Things such as:
/(?<number>\d+)/
)Nevertheless, it was fun to complete!
Thank you for this kata. Took some time (and a lot of code) but I highly enjoyed comeing up with a solution just how I wanted it.
C:
(char *)-1
) is nonsensical, very bad practice and undocumented;(char *)-1
and the actual value is not;I have just tried a "solution" that merely printed the program to stderr and returned the program:
But, the
program_fail
sample test always segfaults anyway. I think the problem is that for the "expected" argument toshouldBe()
, the test definition casts the value-1
to a(const char *)
which IIUC is equal to the maximum value of asize_t
. ThenshouldBe()
compares that to detect whether it is supposed to be anything. OK. But it seemscr_assert_str_eq()
then tries to access/dereference it, unconditionally. At least, if I put that-1
in quotes, or return fromshouldBe()
before that, it prevents the crash. Of course you pass the test and avoid the crash by returning-1
but it seems to be an odd case of the test crashing and not the solution.cr_assert_eq
callsstrcmp
behind the scenes. Due to the faulty logic inshouldBe
, when the expected value is-1
, the tests suite is comparing your returned string with(char *)-1
which of course, crashesHaving to return
(char *)-1
in case of error is very bad design...I did it! Thanks for kata
Very interesting kata. It took some time, but it was a pleasure. Thanks to the author:)
Language C:
Looking for some hints for the actual test cases. I'm able to pass all example cases and one of the random ones. However, I keep getting stuck with a SEGFAULT Invalid Memory Access. Obviously I cannot print out the test case during a SEGFAULT, but I'm trying to think of edge cases where my program could SEFAULT. I can't think of weird inputs that would cause an invalid memory access. Are there any "gotcha's" in the submission cases that I'm missing?
In my other comment here, I described a test crashing when the solution simply cannot. Even the initially provided empty function
char* assembler_interpreter (const char* program) {}
"crashes" on theprogram_fail
sample test, even though it does nothing, because of the way expected output and actual output are handled. It probably doesn't help much since you already passed all the simple tests, but it may be something to think about.Can someone please explain to me why this test case should return -1?
Does the program store something in the registers ?Edit : bad hint.
No, but I still don't understand this test case
From description:
Thank you!
Wrote my first 64-bit C++ assembler interpreter on my CS studies in university. Then it was about 1000 lines of code (although there were about a hundred functions instead of 20). Now it is 150 lines in JS. Pretty kata, i like it!
I don't understand why it's a 2 kyu kata - it is rather simple. The only tricky things to me was "msg" command. You have to check if comma is a separator or just is in the substring to be printed.
There is 4 kyu kata that is more difficult to me (find all correct fraction with given denominator). Still "timeout" there. :-(
This comment has been hidden.
Very nice kata i enjoyed so much but if you wrote in assembly and knew how things work in assembly it is actually too easy to write.
I think the kata description should've mentioned that labels/coroutines themselves can be "run over" and the program should just ignore them. I've spent a lot of unnecessary time trying to wrap my head around that recursive power function due to this (@Blind4Basics and @AnitaK comments helped a lot, but all necessary information should be available in the kata description or tests).
Also, even though it's not tested, I think the kata's description should mention that indentation has no particular meaning, since that implies labels/coroutines can be nested.
Hi,
Some questions :
Thanks !
If I'm not mistaken:
I guess program_fibonacci is broken.
In this segment:
Instead of
Should be
Why?
Please don't back up issues on I guesses.
Because with jle I get the next fibonacci number instead of the correct one. For example, 8th number with jle is 34, not 21.
All another tests my solution passes without problem. I don't see where else the error could be.
The sample test cases have "tabs" that are actually several spaces, but the real test cases have tabs that are actually tabs. One of these should be changed so they match.
done
It seems that this problem is back. It was driving me crazy before I saw this comment and handled tab characters too.
I don't usually comment on Katas, but I have to congratulate the author(s) on how much fun and entretaining this one was. Thanks!
The
2^10 = 1024
test case is wrong (at least for python). Theje continue
instruction leads to aret
instruction only for the last recursive call. The other calls are then left hanging and the program, therefore, must return -1 because it cannot exitproc_func
.There are 2 possible solutions:
ret
at the end ofproc_func
proc_func
tojump proc_func
. Then theret
statement will return to thecall proc_func
statement in the "main" method.This is the unmodified test case (without any of the fixes):
I agree that this test case is a bit counterintuitive, (I had the same thought as you) but this point has been adressed previously.
See this comment for an explanation: https://www.codewars.com/kata/58e61f3d8ff24f774400002c/discuss/python#5c35e71101883f5597eb533d
The link doesn't work (don't ask me why, I've never been able to put a valid link toward a post, you may just give the original poster and the date).
It's obviously not the test case that is wrong, with the kata already being solved 1800+ times. Closing.
Awesome kata!! Thanks! All hail the power of regex too! haha
COBOL translation.
Approved.
Thanks :)
This comment has been hidden.
I've written one in Go, as the first part allowed for Go. But this second part doesn't . :-( How do we get Go supported?
Someone must write a translation and the translation be approved.
Working on Scala When I am sending a code like def interpret(input: String): Option[String] =None or like smth in answer ut's working perfectly well and do compilation, but when I send my code with some realised functions, that works well on my computer - it sends an error message: Test Suite Aborted Exception encountered when invoking run on a nested suite - Unable to load a Suite class that was discovered in the runpath: SampleAssemblerInterpreterSuite
What is it?
Why is it a kata issue?
This kata may be more interesting if parameter passing is required. 2333
@WinterShiver What do you mean by that? Not sure I understand the statement.
The standard of register names is not clarified in detail. In Assembler interpreter (part I), they are described as re alphabetical (letters only). But actually in this kata, to pass the tests, you should allow register names to begin with
_/letters
and follow by_/letters/numbers
, like most common identifiers.Data.HashMap
is not supported by the Haskell compiler. Could I use something instead?Maybe
Data.Map
withzip
ped list?Overall kata is great but the msg instruction is definately non-assembler and looks like C command.
I have to agree. 'msg' is definitely not assembler like. I got a nice little assembler engine going then hit 'msg'. The description of how it's supposed to work is lacking from some concrete examples (call them acceptance criteria if you like.) Happily I noticed another message here that illuminated the problem (no, not a spoiler). So it turns out that the assembler needs what I think is called a 'Lexer' which definitely isn't part of what an assembler engine should be doing. Going back to my youth, I/O was handled by specialized chips that you wrote/read to/from. The analogy here is that whilst the assembler engine works, I have to 'off-board' the message instruction to a specialized handler.
If that was the intent of the kata, then perhaps it's grading needs looking at.
To keep it more in keeping of what an assembler would do, perhaps authors need to consider providing the off-board components, e.g. mov STDOUT a flush STDOUT
which would shift content of reg a into the offboard stdout, obviously a byte/word at a time, with the flush op sending it to screen.
Failing that, how about adding to the kata sequence with something that is directed at such off-board components.
Assembler was my first language, many, many, many moons ago. If nothing else, the kata has revitalised my interest in it again!
Great Kata! Thank you.
This comment has been hidden.
To be more specific, the answers are wrong in that they are off by a few numbers. For example, I got 14 as the correct answer on my computer, but when I ran it in CodeWars, I got 12 :/ I originally thought it was just my own poor programming, but after seeing similar results for multiple random test cases, I am starting to think that the problem does not lie in my code.
Compiler is ok and is the same version you have at home :) I guess you must do something bad somewhere. Please provide clear example with code, fails and logs, or nothing can be done about that.
The task is fine, but it is very unclear that a function can has "call" instruction without "ret" instruction
Why would you have a code point (function) without a return point? Assemblers are dumb. If you don't return, then carry on.
This one's a bit frustrating. I've come up with many ways to write it badly, but can't quite get it done well.
Whew, got it. Great kata! My solution ended up a little too generalized, so it runs a bit long, but it works.
Congratulations!
(I'll return after completing it).
Elixir translation revised.
Great kata, full of learnings Tried to follow a CPU/COMPILER/EMULATOR implementation.. and for the first time make use of some C++ features I never used before : . string_view (VERY good for string performance, WARNING should not modify the base string) . variant (IMO very fit for parsing the arguments of any emulator) . 'if init' (GREAT)
In JS, at first my code passed all tests except the "program_fibonacci" basic test because it did not handle properly the case where the register had the value 0. However I could cheat the tests adding a special returned value for this case. I guess that means there are no other cases where the register can have the value 0. Maybe the tests could be reinforced in that languages by adding some random cases with the same configuration.
Perhaps it is because the kata requires integer division, and JS uses floating-point numbers by default.
On the other hand, Kata itself does lack relevant random examples.
It has nothing to do with floor / integer division. Sure, random tests are very incomplete in several langugages (I realized it after translating it to COBOL).
Haskell translation
.
Very nice kata, thanks!
Question should specify the field we are operating in, i.e. 16 or 32 or 64 or 128 bit int, signed or unsigned.
Also the
msg
instruction can be worded more clearly. For example,This is no real assembly, just follow the description: why should we care about the registers size? And without any precision it is clear that you are not expected to operate on unsigned integers. About the rewording, this is at most a suggestion, not an issue.
I'm a bit confused why the syntax changes compared to the first part. Why have you introduced the commas? Also the change of the function's return type causes that all tests from the first part need to be adapted. The resulting message could have been a special 'msg'-register in the returned dictionary.
Finally, Solved it!!!! Took me 6 hours, had my tea and dinner alongside hahah! The return part was confusing also the 'msg' command was a bit tricky. Everything aside, it was a satisfying kata!
Thank you for this great kata. Amazingly, the implementation of the msg-routine took here the most time.
Do you really want the
cmp
instruction to compare two integer constants in one of its forms? Which of the known assemblers has such a form? It doesn't make sense.Where i was wrong?
Program is: mov a, 11 ; value1 mov b, 3 ; value2 call mod_func msg 'mod(', a, ', ', b, ') = ', d ; output end
; Mod function mod_func: mov c, a ; temp1 div c, b mul c, b mov d, a ; temp2 sub d, c ret
My output is 0, but should be 2. How i know i am right but i have error there
This was a real headscratcher but I finally got it.
The description for
div x, y
is "same with integer division" - integer being the key word we both missed.Btw, a very fun to solve kata
When doing the c-version there's a large number of warnings. It seems it's connected to the upgrade to clang 8. There's so many it's hard to find my own errors :-)
it seems to have been fixed
Elixir translation.
...
.
I had to std::cout the tokens while parsing the program, otherwise the server would timeout, that's strange! Any idea why that could happen?
Loved, loved, loved this kata. Really fun!
Debería ser de nivel 1
This comment has been hidden.
There's no whitespace in register or label names. The tests don't seem to call msg twice - my code inserts newlines when it sees repeat calls.
Wonderful kata ! thanks for the challenge !
Do i need realize a error handling? Or input will be correctly anyway?
If there's an error in the program, you should return the int value -1
Amazing kata! Solving it was equally fun and frustrating. Bravo 👌
I imagine completing this in C will be a huge task.....
can we write a different class for parser in c#?i tested it but it looks like u can only write a single class.....
You can have as many classes as you like, just remember that the method
public static string Interpret(string input)
is the entry point to your solution and all logic has to begin there, so you need to instantiate your parser somewhere in this method. But it can be in separate class.What would happen if the 'end' command doesn't exist in this example:
"mov a, 5 inc a call function msg '(5+1)/2 =', a
function: div a, 2 ret "
Does execution carry straight through to the function and end when the instruction pointer is beyond the last instruction?
i.e. will it call function, then set msg then divide a by 2 and then return... return to where? Or does ret only count if its in a function call?
stay focused on the task: all programs are valid, hence you'll always find a
end
where appropriate.In case @qmstuart is curious about situations not covered in the tests: The code after the label 'function' would run twice, and hitting ret a second time would be an error. When the program stops without hitting an "end", it should return integer -1
There is no 'end' Thus execution is mov a, 5 inc a
div a, 2 msg '(5+1)/2 =', a div a, 2
Undefined end: return -1
This one is just pure joy. I've spent two days on it. I rarely have courage to finish my solutions where unexpected unclear bugs appear, but this time I even enjoyed the process of setting breakpoints and really reading in. Thank you.
I really enjoyed working on this! Compared to other difficult Katas, the challenge in this one was making sure the structure of my solution was solid. Great addition to the Simple Interpreter Kata. Highly recommend completing it first as the author said.
This comment has been hidden.
The meaning of \n is undefined in this langauge - you're assuming it must become a newline.
This is a fantastic exercise. Many thanks!
It would be nice if the description clarified the relationship between cmp and subroutines (i.e. should subroutines affect the value of the parent "most recent cmp" or get their own). I don't believe this case is tested either way, though.
Great Kata! :)
I like this kind of kata, the solution is easy ("just follow the... instructions", no pun intended) and the real challenge lies in writing code that is easy to read and debug (DRY etc.).
To me the key design choices are as follows:
How to parse the source code of the input program. This is not really a choice because regex is the way to go, but if you don't know your regex you can get away with some "manual" splitting, slicing, parsing etc. (ugly!).
How to manage the opcode switch in the main loop. You can use
switch
orif..elif..
statements, or set up a dictionary with opcodes as keys and functions as values (if the language supports first class functions). The latter approach can go all the way down to using the language built-in operator functions. It is elegant but on the downside you end up with a lot of functions.How to manage the program counter (aka instruction pointer). You can defer increments and assignments to the functions that emulate the processor instructions, or increment the program counter at the end of the main loop (unless a jmp instruction was executed).
Last but not least, OOP vs functional approach.
P.S. thanks for this kata!
This comment has been hidden.
My goal was fast execution of the code, so I moved as much effort as possible into the parsing step. That was probably influenced by the prior kata in the series where some lines get executed hundreds of thousands of times. In situations like that, parsing pays a great dividend.
There isn't really a good phrase that covers both a switch statement and dictionary - delegating? Maybe the "delegating instructions" step, where an advantage of the dictionary to function approach is the speed of execution.
I didn't encounter debugging hell with the OOP approach, but maybe asserts in the right places and having an intuition for what could go wrong helped.
Haskell translation would be really nice!
Please review and approve Rust translation (https://www.codewars.com/kumite/5eb67e3a9b138200255ffa74?sel=5eb67e3a9b138200255ffa74)
Please review and approve Scala translation (https://www.codewars.com/kumite/5eaebbce9a4f1f002d4ec583?sel=5eaebbce9a4f1f002d4ec583)
Great kata! :)
I take a lot of time to finish it,it's too hard for me.I'm in trouble about how to return default -1 and some spetial msg parameters(which contains , nested in '').finally,i complete it,but maybe not very correct about the condition of return -1 without the end command.This is a good kaka of course.
I can sympathize - I spent more time debugging the "msg" instruction than anything else. My first attempt using Python's "re" module didn't go well. I wound up writing custom code to deal with it.
As to finishing without an "end", yes that should cause -1 to be returned. Any error or problem results in a -1 return value.
Enjoying this Kata so far (Python right now, JS, maybe php). It will help me making a simple French pseudo code intepreter in JS I've been thinking about lately.
Recently I've researching alot about Assembly languages when suddenly this challenge appeared. Thoroughly enjoyed this challege..
This is a typo in Details. 'to' 2 times.
jmp lbl - jumps ----> to to <------ the label lbl.
done
I managed to do this with SWIFT and passed the test. But I think there would be a more elegant way to do it in SWIFT, using protocol oriented design. I look forward to seeing and learning from that.
Thanks for the kata, find some past memory on embedded development ;) Not as hard as other 2kyu katas, just from my angle though.
call should never be used as an unconditional jump like the case in the recursive subroutine of the program_power test, because in real assemblers, when CALL is called, it pushes the IP location from where the instruction was called onto the stack, then jumps to the location of the label, and when RET is called the top value of on the stack gets popped back into the IP. In the Test, when CALL is called to jump back to proc_func label, its location gets pushed onto the stack everytime, so that when RET is finally called, to get back to the line after where it was called, it pops back the location of the recursive CALL instead, which cause the program to halt. Please fix it and use JMP instead. Thank you
what test are you talking about exactly? Paste the commands here if it's a random one.
program_power in the Sample Tests
This comment has been hidden.
I've solved that issue in my code tho, but still it's wrong to use CALL in recursion. What I'm facing now is that in the Random tests, the numerical solution is right, but the output string isn't samples of the errors I get: Expected: 'Random result: 3', instead got: 'Do nothing3' Expected: 'Random result: 30', instead got: 'Do nothing30' Test Passed: Value == -1 Expected: 'Random result: 22', instead got: 'Do nothing22' Test Passed: Value == -1 Test Passed: Value == -1 Expected: 'Random result: 28', instead got: 'Do nothing28'
I have no idea where the 'Do nothing' came from and I don't know how to see the input of any of the random test
ok, not an issue, just your code that is wrong:
Do nothing
that is showing upis supposed to be a comment in the random programs. Clearly, your parsing is incorrect.Edit: Actually, that could be something else: I didn't see there was another proc defined below. But still, your code cannot be correct since when the epxected output is 'Do nothing', you're not supposed to output the value after it. So in any case, the problem stays on your side. ;)Note that there are already hundreds of solves in JS and noboby raised an issue (that hasn't been clarified as being an error on the user side) about that.
=> closing & enjoy your debugging. ;)
cheers
I dont get the difference between
jmp
andcall
. How are they different?jmp lbl
: Jumps to the labellbl
call lbl
: Call to the subroutine identified bylbl
So for instance
jmp func
andcall func
should do the same thing right? Iffunc
had aret
, the instruction pointer would return to thejmp
orcall
respectively.the difference is
ret
;)The implementations need to be distinct because you may wish to use jmp within a funcion without messing up your return :)
This comment has been hidden.
;)
Please review and approve my C translation
you still have to fix your C/C++/C-whatever translations to the regexp parser kata...
Interesting you mention that here... I did not get any notifications on that. Will check.
This comment has been hidden.
read the description again... ;p
Yep I've already read again and again. But no idea why ret ins in func1 is the ending of program :( It should back to 'call func1' ins in main block, isnt it?
Ask yourself: where this program does actually end?
From meaning of ret ins - "when a ret is found in a subroutine, the instruction pointer should return to the instruction that called the current function", the ret in func2 should return func1 and one in func1 should return in main. So it will be reached the end ins. But I know my explaination is wrong. Can you help me, again?
the problem isn't in func1 or func2. Go further
Oh, I see the point. Thank you. Can I know your name please :)
cool
errr... nope. ;)
Is there a difference between the jmp and the call commands?
Okay, I thought i figured it out: With a ret command you return to the position after the last call command, not after a jump command.
But then one of the test cases doesn't work:
When calling the proc_func more than second time, the ret in the continue function will return to that position and not the "main" function.
no, the
ret
command makes you return to the command who called that routine. Meaning that the ret in the continue routine makes you go back to theje continue
line.@Blind4Basics If that is the case doesn't the test case above continue in an infinite loop?
mmmmh... Correct, I had it wrong (did that one a fair amont of time ago, sorry...).
I don't have time right now to investigate further, sorry.
With what language version do you have this problem?
As I understood that case, after you return inside
continue: ret
to thecall proc_func
(line 14), you will keep moving forward line-by-line and run into thecontinue: ret
on lines 16-17 again and again. This wayret
operation will be called enough times to return you back to line 5, and you should proceed to theend
operation normally.@hobovsky I was working with Java8
@FArekkusu After returning to call proc_func (line 14) there are no more lines to keep moving forward to. Or do you keep moving forward into other functions?
ok, went to it with a brain in better shape than last time... x)
This:
is actually equivalent to this:
and you have to keep track of the different levels of the calls to interpret that correctly.
all routines will always have a
ret
command somewhere (sometimes, the ret of onecall
ed routine is the one of another routine that you reach using a jump command instead of acall
one, as in the present case), so you have to go back to the location of the previouscall
command.EDIT: keep in mind that all registers are global variables, here.
Yes, that is exactly what I thought.
But then lets follow the flow of the program: First some initialisation, then proc_func is called for the first time. d != 1 so the ret command is skipped. proc_func is called for a second time. This skipping of ret and calling of proc_func will keep going until d == 1. Then the ret command returns from the last call of proc_func. But then there is no statement anynore, so the program terminates.
The expected behaviour of the program could be accomplished by adding a ret command after call proc_func.
True. But for the purposes of this kata it seems entering another function (by parsing the commands sequentially), and calling
ret
inside that other function is deemed the same as calling a non-existantret
command insideproc_func
. At least, such logic lines up with the way this test case is structured.You need to mimic plain recursive calls. Meaning that when the first
ret
is executed, you go back to the lastcall proc_func
statement executed. Meaning, in that routine, you continue to read the commands after the call, then you end up on theret
inside thecontinue:
routinelabel, which sents you to the previouscall proc_func
statement executed, and again, and again, ... until you finallyret
from the first call of the routine and go back to the 5th line of the script, then print the result, then end the program.Meaning, you need to see those two routines as one single block:
equivalent to:
EDIT: note the difference in the names: one is called
proc_...
, meaning it will be "called" while the other is just a label used to mimic a GOTO statement.Thanks for the replies. I think I get it now. When reaching the end of a function (a labeled block of code) without encountering a return statement, you continue executing the next lines (possibly a next function).
unless the code isn't correctly written, all proc will end with a ret command. But yes. ;)
Excellent. Rather nasty parsing multiple spaces and the msg format itself.
Maybe a part III could be done adding, for example:
Really enjoyed it
Not related to this kata.
If you mean not related to an Assembler Interpreter based kata I beg to disagree. Sorry, didn't expect to ruffle any feathers. It was just a suggestion to make an even harder kata. Sorry if I didn't phrase the idea conveniently.
Suggestions are related only to the task they're left under. They're not for suggesting what should be included in some arbitrary future katas.
Where would suggestions for future katas in the series go, if they don't go in the comments?
Description:
:-)
Fixed ;-)
C++ translation. Please, review and approve.
Note: it includes description update for both Ruby and C++ version, and should be approved last.
Ruby translation. Please, review and approve.
Why do you not test the case "label and instruction in one line", i.e "repeat: dec b" ?
Why do you not test the case "semicolon in string" (JavaScript), i.e "msg 'a = ', a, '; b = ', b" ?
This comment has been hidden.
I created C# translation, based on B4B's Java translation. Please verify, and eventually accept.
Thanks for accepting!
Swift version won't pass even when test cases are satisfied because of warnings in the test harness writing to stderr.
A simple assignment to '_' would suffice for swift 3.
For swift 4 an additional warning is output to stderr:
I've came across this issue too. Is there a way to workaround it? I am on a brink of rewriting this kata on other language.
I was honestly hoping that since the fix was simple enough, someone would be able to incorporate it easily. I'm not aware of any way to workaround it at this point besides writing it in another language since the issue is in the test harness.
done
in the description for mul x, y you spelled 'with' as 'mith'. this isn't runescape
Looks fixed ;-)
Good kata, fairly straightforward, though. Only thing that tripped me up was parsing the msg format.
Coffeescript translation
Approved.
Also, not to get too far ahead, which kata is Part 1?
Part I: https://www.codewars.com/kata/simple-assembler-interpreter/
Maybe you should put that in the descriptions :)
Yeah, you are right.
Oh, okay. Now I remember it. Already done, bummer.
Hmm. Just found this, and I am an old Assembly programmer! Thank you, but this sure seems like it should be a level 1. Irregardless, I am looking forward to coding it!
What are the possible names of the registers?
Lowercase letters
a
toz
.Does a
; comment
end when it encounters an opcode, or when a newline is encountered? I.e is this a comment still; this is a mov a , 5 comment
Nevermind, just saw that the code is EOL delimited from the description.
JS translation
;-)
Will you be add the javascript to this kata?
If you add a javascript translation, I'll approve it :)
Challenge accepted
JS translation as promised
Really liked this kata! But the inevitable messing with regex gave me quite a headache...
Nice kata, but I somewhat dislike the unclean use of spaces and commas to separate fields. With a proper syntax, the solution could have become a lot cleaner.
Thanks for reminding me that this kata exists ;-)
Took half an hour to finish it and approved it.
Java translation, please review and approve.
Approved :)
This one is just EXCELLENT! :)
Some troubles with the description, as in the part I, but not so much. I'll try to do a java translation and I'll make some modifications to the description at the same time.
Despite the previous ranking suggestions, I believe this should be ranked 2 kyu because:
btw:
Corrected my ranking from 3 to 2kyu;-)... long time ago, 5 month... and i agree, really a "nice kata";-)!
Then you should really try To BrainFuck Transpiler. This one is really hard and is rated 4 kyu (why?!)
I don't do JS... ;)
This happen on 9nd test Traceback: in File "/usr/lib/python3.6/random.py", line 274, in shuffle x[i], x[j] = x[j], x[i] KeyError: 0
And after i put a print on the beginning of my code nothing appear so the test case maybe broke.
Or it was your code. Most probably that... Closing.
Is it allowed to call a function inside a function - would be a little bit more work (good to know before implementing and a point for your description);-)?
It is, as you can see in at least one of the tests.
Yes thanks, just saw it;-)... Your answer was quicker than my delete:-)
By the way interesting kata (remember my old Apple II, C64, Atari a.s.o. 6502/68000 processor/assembler), for me it's too late now, surely solve it tomorrow (if i find some minutes time:-))...
Thank you!!
New question;-): Message (msg) output means end of the program - it's only possible to return a single message...?
No, but all the examples return a single message. The program shouldn't end until you get the
END
instruction or the last instruction of the program is reached.But all messages excluded the last one get lost... (by the way my code works for your first two test examples - i have to implement the last "commands", but later on...;-))
The messages don't get lost, but perhaps I should add an EOL after every
msg
is sent.At the end there's one return, so one output - all messages have to be collected to one string separated by EOL (no other output like your Assembler I kata)? For me your description sometimes is a little bit unclear or better not complete;-)...
I know, that's because my english is very poor. If you have any suggestion I'd be glad to modify the details :)
No problem... just some points i saw... first i solve it, later on perhaps some hints, between perhaps some questions;-)... But for the moment it's ok and i'm busy too, so takes a little bit;-)...
Ok, again i found some minutes to complete the last commands;-)... For me now everything works as expected, so no new questions or comments (perhaps there are some little thinks, but it's ok):-)! I ranked it as 3kyu, which is really a high ranking here. But... most same or easier "interpreter katas" have same or perhaps higher rankings. We will see what others say;-)! Many thanks for your good work and this funny kata;-)!
I'm glad you liked it :) Interestingly enough, it was funnier to code the assembler programs of the tests than the interpreter itself. Perhaps I'll create an even more advanced assembly kata, adding more instructions (push, pop, lea, xor, etc...).
Yes... i saw your test examples which looked interesting enough to solve your kata:-). I think new instructions will make it not harder, but only more typing;-). Perhaps you can preload an assembler interpreter and the task will be to write an assembler program;-)...
If I add memory access instead of only registers... that might make it harder. I also thought that, but I don't know if it will be too hard to write assembler programs.
Short and simple programs, don't know...? Too hard:-)? You did it for your testcases. Some (ok many:-)) years ago, many programs or at least parts were written in assembler, little bit earlier only with hex codes:-)...
I'll try it, but the problem is that there isn't an assembler category and the kata will be located in the python category (which is a quite recent programing language). We'll see if people are capable of solve the problems :)