32-bit x86 Assembly- Reversing Order of Array through Rotates/Shifts - arrays

I googled this question for the past 2 hours and couldn't find exactly what's needed so I figured I'd ask for help.
So..
We have 2 arrays. Both have a length of 10. The first one stores your student/teacher/work ID number with a prefix of 0. For example: 0,1,2,3,4,5,6,7,8,9
The goal of this program is to reverse the order by using shifts and rotates and store them in the second array.For example: 9,8,7,6,5,4,3,2,1,0
I can't seem to figure out the algorithm; I've been staring at the screen for too long.
The other requirements are to sum the 2 values from each array and show the memory locations, but I think that won't cause me much trouble.
Precise Constraints:
Draft a program that adds two BCD numbers (10-digits each)
The first BCD number is stored in array1 and the reversed order will be stored in array2.
Use shifts/rotates using array1 to fill array2
Display contents of the memory locations in question
Add both values by using BCD arithmetic
Store the sum in a variable named Result
Those were the requirements. No other information was given.
Thank you

Related

Getting 10 nsmallest arrays from a set of arrays

First of all, I apologize for the confusing title, the task which I'm trying to accomplish is itself still confusing to me, hence why I'm finding it hard to do it. I'll try to be as clear as I can from now on.
I have 100 500x500 arrays, the values inside range from 0 to 1. What I would like to do is write a code that gives me 10 arrays, these arrays will be a sort of composite of the minimum values between them.
The first array is made of the absolute minimum values, the second array with the 2nd order minimum values....and so on. So the 10 arrays will be a composite of sorted ascending values.
I managed to get the absolute minimum with np.minimum() but I have no clue on how to proceed to the next ones.
To reiterate, I don't want to sort the 100 arrays, but loop through them and create new arrays with the lowest values found in each position.
Sorting is the most efficient way.
np.sort([array0,array1,...], 0)
Will yield an array where the first element is an 100x100 array of the smallest element-wise entries of all your arrays, the second the second smallest, etc.

Find a fixed length path of adjacent 2D array elements

I have a m x m two-dimensional array and I want to randomly select a sequence of n elements. The elements have to be adjacent (not diagonally). What is a good approach here? I though about a depth-first search from a random starting point but that seemed a little bit overkill for such a simple problem.
If I get this right, you are looking for sequence like continuous numbers ?
When i simplyfy this:
9 4 3
0 7 2
5 6 1
So when the 1 is selected, you'd like to have path from 1 to 4 right ? I personally think that Depth-First search would be the best choice. It's not that hard, it's actually pretty simple. Imagine you select number 2. You'll remember position of number 2 and then you can look for lowest numbers until there are any. When you are done with this part, you just do the same for higher numbers.
You have two stacks one for possible ways and another one for final path.
When going through the array, you are just poping from possibilities and pushing right ones into the final stack.
The best approach would be finding the lowest possible number without saving anything and then just looking for higher numbers and storing them so at the end you'll get stack from the highest number to the lowest.
If I get that wrong and you mean just like selecting elements that are "touching" like (from my table) 9 0 7 6, which means that the content doesn't matter, then you can do it simple by picking one number, storing all possibilities (every element around it) and then pick random number from 0 to size of that stored values. When you select one, you remove it from these stored values but you keep them. Then you run this on the new element and you just add these new elements to stored elements so the random will always pick surrounding around these selected numbers.

How to put random characters into a multi dimentional array in C

I'm trying to build a board of 4X4 and I'm trying to use the rand function to put random characters in the board.
I need 8 pairs of characters and I don't want to have more than one pair of the same char.
how should I do it?.. I tried a lot of variations without success.
Please help.
Not sure my answer is what you exactly want. I hope it will be helpful.
It looks like your question is more like a algorithm issue. Let's say you are trying to find 8 unique random character pairs and each pair contains two different characters.
Then you can do as following:
Get all possible characters you may use, for instance A ~ Z.
Create one array and its value is a unique character pair which has two characters you want to use. You can use a nested loop to do it.
Record how many elements you have in the array. Assume the value is N.
Use function rand() and number N to get one random number r1.
Pick up the value at position r1 of array and put it into your board.
Switch this element with the last element of array.
Use function rand() and number N-1 to get one random numbe r2. Then do step 5, 6 again.
Do it as step 4 to step 7 to get all 8 pair you want.
If you just want to get 16 unique characters, then just ignore step 2 but keep an array which has all possible characters.
If you want to some weird character, such as '$', '%', etc, then use ASC values.

Result of Long Positive Integers & Search and element in array

I have two Questions for which I cannot find answers by googling, but I find these questions very important for preparation.. Kindly explain only the logic, I will be able to code.
In Search of Efficient Logic..... in terms of Memory and Time.
WAP to add two long positive integers. What Data structure / data type we can use to store the numbers and result.
What is the best way to search an element from an array in shortest time. Size of the array could be large enough, and any elements could be stored in the array(i.e. no range).
Thanks.
A simple array is fine for storing long numbers, then the logic for addition follows naturally.
3 byte arrays would work well, two for the numbers to be added and one for the result.
The fastest way to search an element in an array would be some sort of Binary Search, so long as the array is sorted
Since it`s mentioned the numbers are large enough a linked list where each node is based on the indices of the digits within a number. A traversal through a single list can help us with the solution.
If it`s sorted then Binary search would be apt , but if not Hash table would be the best pick as it takes constant time.

Array Tree...Maybe recursion?

I am trying to divide arrays recursively... I think that is what this would be called haha....
For instance, lets say the initial array contains 50 values the highest being 97 and the lowest being 7... I want to split this array into two, dividing them based on whether they are greater or lower than the midrange of the entire set. The midrange being 52...( (97+7)/2 )
Then I want to divide these two arrays using the same method and so on, ideally having a program that repeat this process an arbitrary number of times....
Load Values into array1
Find Midrange
For every value in array1{
if value > midrange{
assign value to ArrayHigh1}
Else{ assign value to ArrayLow1}
}
Perform same thing on ArrayHigh1 and ArrayHigh2
Etc etc etc.
I'm having trouble figuring out how I would create the successive arrays (ArrayHigh2 3 4 etc)
Also, I feel like there must be an easier way to do this, but I cannot think of one at the moment...
Thanks for the help
You seem to be working your way towards a B-tree or an implementation of Merge- or Quicksort. Plenty of reference implementations are available online.
Though speaking generally, you might benefit greatly from reading a book many here are familiar with.

Resources