Pick a Random Byte
About points...
We associate a certain number of points with each exercise.
When you click an exercise into a collection, this number will be taken as points for the exercise, kind of "by default".
But once the exercise is on the collection, you can edit the number of points for the exercise in the collection independently, without any effect on "points by default" as represented by the number here.
That being said... How many "default points" should you associate with an exercise upon creation?
As with difficulty, there is no straight forward and generally accepted way.
But as a guideline, we tend to give as many points by default as there are mathematical steps to do in the exercise.
Again, very vague... But the number should kind of represent the "work" required.
When you click an exercise into a collection, this number will be taken as points for the exercise, kind of "by default".
But once the exercise is on the collection, you can edit the number of points for the exercise in the collection independently, without any effect on "points by default" as represented by the number here.
That being said... How many "default points" should you associate with an exercise upon creation?
As with difficulty, there is no straight forward and generally accepted way.
But as a guideline, we tend to give as many points by default as there are mathematical steps to do in the exercise.
Again, very vague... But the number should kind of represent the "work" required.
About difficulty...
We associate a certain difficulty with each exercise.
When you click an exercise into a collection, this number will be taken as difficulty for the exercise, kind of "by default".
But once the exercise is on the collection, you can edit its difficulty in the collection independently, without any effect on the "difficulty by default" here.
Why we use chess pieces? Well... we like chess, we like playing around with \(\LaTeX\)-fonts, we wanted symbols that need less space than six stars in a table-column... But in your layouts, you are of course free to indicate the difficulty of the exercise the way you want.
That being said... How "difficult" is an exercise? It depends on many factors, like what was being taught etc.
In physics exercises, we try to follow this pattern:
Level 1 - One formula (one you would find in a reference book) is enough to solve the exercise. Example exercise
Level 2 - Two formulas are needed, it's possible to compute an "in-between" solution, i.e. no algebraic equation needed. Example exercise
Level 3 - "Chain-computations" like on level 2, but 3+ calculations. Still, no equations, i.e. you are not forced to solve it in an algebraic manner. Example exercise
Level 4 - Exercise needs to be solved by algebraic equations, not possible to calculate numerical "in-between" results. Example exercise
Level 5 -
Level 6 -
When you click an exercise into a collection, this number will be taken as difficulty for the exercise, kind of "by default".
But once the exercise is on the collection, you can edit its difficulty in the collection independently, without any effect on the "difficulty by default" here.
Why we use chess pieces? Well... we like chess, we like playing around with \(\LaTeX\)-fonts, we wanted symbols that need less space than six stars in a table-column... But in your layouts, you are of course free to indicate the difficulty of the exercise the way you want.
That being said... How "difficult" is an exercise? It depends on many factors, like what was being taught etc.
In physics exercises, we try to follow this pattern:
Level 1 - One formula (one you would find in a reference book) is enough to solve the exercise. Example exercise
Level 2 - Two formulas are needed, it's possible to compute an "in-between" solution, i.e. no algebraic equation needed. Example exercise
Level 3 - "Chain-computations" like on level 2, but 3+ calculations. Still, no equations, i.e. you are not forced to solve it in an algebraic manner. Example exercise
Level 4 - Exercise needs to be solved by algebraic equations, not possible to calculate numerical "in-between" results. Example exercise
Level 5 -
Level 6 -
Question
Solution
Short
Video
\(\LaTeX\)
No explanation / solution video to this exercise has yet been created.
Visit our YouTube-Channel to see solutions to other exercises.
Don't forget to subscribe to our channel, like the videos and leave comments!
Visit our YouTube-Channel to see solutions to other exercises.
Don't forget to subscribe to our channel, like the videos and leave comments!
Exercise:
You have a stream of bytes from which you can read one byte at a time. You only have enough space to store one byte. After processing those bytes you have to return a random byte. Note: The probability of picking any one of those bytes should be equal.
Solution:
Since we can only store one byte at a time we have to be able to work with the bytes as they come in. We can’t store everything count the number of bytes and pick one. That would be too easy wouldn’t it? Let’s think it through. We don’t know how many bytes there are so at any po in time we should have a random byte picked from all the bytes we have seen so far. We shouldn’t worry about the total number of bytes at any time. When we get the first byte it is simple. There is only one so we store it. When we get the second one it has frac probability of being picked and the one we have stored has a frac probability of being picked we can use any programming language’s built-in random function. After picking one we replace the current stored byte with the one we picked. Now it gets eresting. When we get the third one it has frac probability of being picked and the one we have stored has a frac probability of being picked. We pick one of the two bytes based on this probability. We can keep doing this forever. Just generalizing when we get the nth byte it has a fracn probability of being picked and the byte we have stored has fracn-n probability of being picked. Sometimes this question is a little confusing. The question said you have only space to store one byte but there is an asption that you have space to store variables to track the number of bytes and so on. Another asption is that the stream of bytes is not infinite. If not we won’t be able to calculate fracn-n.
You have a stream of bytes from which you can read one byte at a time. You only have enough space to store one byte. After processing those bytes you have to return a random byte. Note: The probability of picking any one of those bytes should be equal.
Solution:
Since we can only store one byte at a time we have to be able to work with the bytes as they come in. We can’t store everything count the number of bytes and pick one. That would be too easy wouldn’t it? Let’s think it through. We don’t know how many bytes there are so at any po in time we should have a random byte picked from all the bytes we have seen so far. We shouldn’t worry about the total number of bytes at any time. When we get the first byte it is simple. There is only one so we store it. When we get the second one it has frac probability of being picked and the one we have stored has a frac probability of being picked we can use any programming language’s built-in random function. After picking one we replace the current stored byte with the one we picked. Now it gets eresting. When we get the third one it has frac probability of being picked and the one we have stored has a frac probability of being picked. We pick one of the two bytes based on this probability. We can keep doing this forever. Just generalizing when we get the nth byte it has a fracn probability of being picked and the byte we have stored has fracn-n probability of being picked. Sometimes this question is a little confusing. The question said you have only space to store one byte but there is an asption that you have space to store variables to track the number of bytes and so on. Another asption is that the stream of bytes is not infinite. If not we won’t be able to calculate fracn-n.
Meta Information
Exercise:
You have a stream of bytes from which you can read one byte at a time. You only have enough space to store one byte. After processing those bytes you have to return a random byte. Note: The probability of picking any one of those bytes should be equal.
Solution:
Since we can only store one byte at a time we have to be able to work with the bytes as they come in. We can’t store everything count the number of bytes and pick one. That would be too easy wouldn’t it? Let’s think it through. We don’t know how many bytes there are so at any po in time we should have a random byte picked from all the bytes we have seen so far. We shouldn’t worry about the total number of bytes at any time. When we get the first byte it is simple. There is only one so we store it. When we get the second one it has frac probability of being picked and the one we have stored has a frac probability of being picked we can use any programming language’s built-in random function. After picking one we replace the current stored byte with the one we picked. Now it gets eresting. When we get the third one it has frac probability of being picked and the one we have stored has a frac probability of being picked. We pick one of the two bytes based on this probability. We can keep doing this forever. Just generalizing when we get the nth byte it has a fracn probability of being picked and the byte we have stored has fracn-n probability of being picked. Sometimes this question is a little confusing. The question said you have only space to store one byte but there is an asption that you have space to store variables to track the number of bytes and so on. Another asption is that the stream of bytes is not infinite. If not we won’t be able to calculate fracn-n.
You have a stream of bytes from which you can read one byte at a time. You only have enough space to store one byte. After processing those bytes you have to return a random byte. Note: The probability of picking any one of those bytes should be equal.
Solution:
Since we can only store one byte at a time we have to be able to work with the bytes as they come in. We can’t store everything count the number of bytes and pick one. That would be too easy wouldn’t it? Let’s think it through. We don’t know how many bytes there are so at any po in time we should have a random byte picked from all the bytes we have seen so far. We shouldn’t worry about the total number of bytes at any time. When we get the first byte it is simple. There is only one so we store it. When we get the second one it has frac probability of being picked and the one we have stored has a frac probability of being picked we can use any programming language’s built-in random function. After picking one we replace the current stored byte with the one we picked. Now it gets eresting. When we get the third one it has frac probability of being picked and the one we have stored has a frac probability of being picked. We pick one of the two bytes based on this probability. We can keep doing this forever. Just generalizing when we get the nth byte it has a fracn probability of being picked and the byte we have stored has fracn-n probability of being picked. Sometimes this question is a little confusing. The question said you have only space to store one byte but there is an asption that you have space to store variables to track the number of bytes and so on. Another asption is that the stream of bytes is not infinite. If not we won’t be able to calculate fracn-n.
Contained in these collections: