add two or more numbers using a turing machine emulator - turing-machines

I'm playing around with a turing machine emulator and I'm trying to add more than two numbers together. I can make it add two numbers together and halt, but I cant make it halt if I add 3 or more numbers (eg 4+3+3 will not halt after adding the last number instead it continues for ever). - if this doesn't work I can trying something else.
This is what I have, I'm just not sure what I need to do. Any help is appreciated, if you need more information don't hesitate to ask


In KVM/QEMU, is it possible to merge two hyper-threaded CPUs?

I cant find anything in the docs showing how to make them appear as one and give the performance of a non-hyper-threaded CPU.

How should multi-part Codecept.js scenarios be organized?

What is the preferred (or just a good) pattern for a multi-part Codecept.js scenario, such as this:
Select file to upload.
Clear selection.
Select file to upload after having cleared selection.
I can do this in a single scenario and use I.say to delineate the parts, but it feels like I should be able to write these as independent scenarios and use .only on part 2, for example, and have part 1 run prior to part 2, because it depends on it.
I would also want to skip parts 2 and 3 if part 1 fails when running the whole suite.
I like thinking about behaviour in terms of capabilities. I can see that you have a couple here:
Uploading files
Correcting mistakes while uploading files.
So I would expect these to be in two scenarios:
One where you actually upload the file
One where you correct mistakes you make.
A lot of people say there should only be one "When" in scenarios, but that doesn't take into account interactions with people (including your past mistaken self) or time. In this situation, it's the whole process of correcting the file upload that provides the value. I can't see any value in the intermediate steps, so I'd leave them all in one scenario.
If there's any different behaviour associated with different contexts (eg: you've already got too many files uploaded) or outcomes (eg: your file system doesn't have room) or rules (eg: your status means you qualify for super-fast upload) then I would expect those to be new scenarios. If you start getting to the point where there are a lot of scenarios associated with file uploads and different things that happen to them, that might be a good time to separate this scenario out. Right now I can't see any reason to do that.
Re failing the first part: if you're doing BDD right, you'll be talking through not just the behaviour of your system, but the behaviour of individual bits of code too. That should help produce a good design which minimizes the chances of having bugs. Really good BDD teams produce scenarios that hardly ever catch bugs!
The scenarios act as living documentation, rather than regression tests; helping future devs understand the value of the code and get it right, rather than nailing it down to stop them getting it wrong.
So I wouldn't worry about it failing. If it's doing that a lot, you've got a different problem. Code it as if it's going to be passing most of the time, and make sure it's readable and comprehensible. As long as you can see when it fails and work it out, even if that takes a little bit of time, it'll be fine.
Having said that, I'd be surprised if Codecept doesn't have at least an option to stop on failure. Most BDD tools don't continue a scenario after a failed step; it would be an odd thing to do.
As far as I know, you're not be able to set priority for execution in codeceptjs. Better make one test. it is also will be more flexible if you will need to add or delete some part.

How can I reset timer of dropwizard metrics?

We are processing messages that comes in periodically. We use codahale dropwizard metrics' "Timer" for measuring the time it takes to process them.
I found someone had the same issue here:
"problem with exponentially decaying reservoir is that if no new data comes in, it will keep on giving the same numbers all the times. For example, let say you update a timer with 5 and 7 (then don't put anything at all) , then no matter when you see (even after x hours), timer will still show the average to be 6 which is not representative of last 5 mins by any means.
so, it works only if data is arriving all the time."
As you can see with the dark blue line:
But there's no suggestion to solve it. And they say it's not going to be implemented:
How can I reset these timers properly or how should I visualize it so it's not confusing?
Note: It is too long for comment.
Using the SlidingTimeWindowReservoir will cover most of the use-cases.
But as pointed out in this comment there could be a problem depending on the number of events:
it keeps all the measurements in the window in-memory which becomes unacceptable at large number of events
Could we do better? Let's continue searching. If we are lucky we will find this blog post. It describes exactly your kind of problem. There is a link to their simple dirty solution. Also a suggestion for using HdrHistogram.
Also on the metrics mailing list there are several messages about exactly this problem.
For example and point to Marshall Pierce/hdrhistogram-metrics-reservoir. What is HdrHistogram and why use it to measure latencies check the project description.
And finally after some more digging you could find also vladimir-bukhtoyarov/metrics-core-hdr
project. It's using HdrHistogram also.
So there are two similar libraries that use the same data structure and claim to solve the problem case you have hit.

CloudBalance example tweak

I've been playing with the basic CloudBalance example, and have given it input of one Computer and two Processes. Both processes are too much to fit on the computer, so only one should go on. However, when solving the solution (albeit with negative HardScore) is that both Processes are on the Computer. I understand there is not actual solution for both Processes, but shouldn't the result only have one Process assigned to the Computer, and the other not assigned? How would I need to change the setup to make that happen?
Look at Overconstrained Planning in the docs. By default, OptaPlanner will assign all Processes, because assigning to null is not an option.

How to scale a trie across multiple servers

Does anyone know how I might scale a Trie across multiple machines? Say the first machine runs out of space and I need to add more words from a very large dictionary, what might I do to add more words? (I am a Java thinker, but I believe the answer can be language agnostic). I have already realized that I cannot just say one machine for each first character, but that doesn't really scale.
Ok, given the assumption, that both of your machines have the same resources available, let’s first look at a simpler example:
how would you scale a binary tree? Or even better - an AVL tree? There are several examples to do this:
If there would be only 2 machines and storage is your problem, I’d keep the root and the left subtree on one machine, and send the right subtree to the other.
If you’d have 3 machines and would also want to have a load balancer, the root would stay on one machine and the left and right subtree would be split accross the other 2 machines. If you have 5 you keep the root and first level of children on the load balancer and split the rest of the tree.
(note that balancing such a distributed tree will be much more complicated, as you’ll need to communicate with other machines and do it possibly inside a distributed transaction, to be able to answer all requests concurrently)
So, now a trie, which - AFAIR - is a tree / letter. If the letters in your words would be distributed evenly, you could have A-M on one machine and N-Z on the other. This will probably not work, but you’ll for sure be able to split it more or less 50/50 like this.
If you now want to add more and more machines, I’d keep a main node which would work as a load balancer and distribute it to the child nodes, which would only take care of few letters. For instance you could have nodes
Assuming, you have roughly as much data for the letters A-F as you have for the letter S. (There actually might be a language, where this would be at least close to the most optimal distribution)
Now if you get too many letters in A-F you can just split it into A-D and E-F for instance, nothing really changes there. The problem will be if you’d get too many letters in S. Now you’d have 3 possibilities:
You make another load balancer for the letter S - this will be for sure easy, as you already have a load balancer implemented and you can use the same functionality on any level
You keep letters SA-SM (for instance) in one node, which will be the main node, store SN-SZ on a separate node. So if you get SP.. the first load balancer would send it to your SA-SM node and that one would forward it to SN-SZ
You modify the load root load balancer to be able to specify more complex boundaries between nodes, such as you’d have now the nodes
Here number 1 is probably the easiest and cleanest solution, but might have some unused hardware. In case you can use different resources for nodes, option 1 with a small load balancer for the letter S would be probably the way to go.
Option 2 is a dirty mix, and option 3 might be the nicest way to go, but it makes the load balancer potentially complicated and error prone.
Hope this ideas help you.