
I believe in innocent. His not asked just because his lazy but because he don't know how to ask even.
So beside to give him some  not very bright  solution I tried to point him to the right direction...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).





It's quite clear from the original question that this is a college assignment. So by giving him the answer you are not really helping him. It's much better that people like him learn to think for themselves and at least try to work out the answer.
Veni, vidi, abiit domum





I made a website (my master project at Technical University of Graz) where you can find animations of some algorithms.
It is made with SVG/Javascript. You can run/pause/step/back an algorithm and see the pseudo code variables changing in real time.
It should be very helpful for Bsc students and also teachers can use it during lectures.
The site is called: alg0rithms.com (0 = zero)
I'm waiting for your feedbacks...





Perhaps some more algorithms, for example heapsort, bucket sort, counting sort, shell sort, midpoint circle algorithm..
Btw I think this may technically be the wrong forum for this type of question





Thank you for your feedback. I will do that if the site gets enough users.





It's nice, and you made me curious. What master project for?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).





Thank you. It is a master project for visualization of algorithms at TU Graz.





It looks really good. After seeing your work, I am planning to implement the same in .net technology MVC. I think you have used php.
modified 2Dec13 6:28am.





Thank you. Yes a mix of PHP and JavaScript.





I tried to watch the site but don't work.
Changed address ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein





Hi, I want to implement a ceiling function:
x++;
if ( x>7 ) x =7;
Anybody know if there is a bitwise expression fit the same function?
modified 6Nov13 16:14pm.





Certainly, but it's going to suck unless you make some assumptions.
For example, if x is known to be < 8 and bigger than 2 before the increment, then it's enough to do this:
x++;
x = x >> 3; which subtracts 0 if x is already less than 8, otherwise x is 8 (because of the assumption) and it subtracts 1.
Or, if you have 32 bit ints (pretty common, and you can adapt it to other widths) and arithmetic shifts (you usually do) and x is known to be less than 8 and bigger than 2147483642 prior to the increment:
x = (x  7) >> 31;
which effectively adds one if (x  7) is negative (ie if x is less than 7)
Or, if you have 32 bit ints (adaptable), arithmetic shifts, and x is pretty much anything, you can do
x++;
int mask = (x  7) >> 31;
x = (mask & x)  (~mask & 7);
which uses the "bitwise minimum" trick, and it valid for almost all x, except x < 0x80000006 or x == 0x7fffffff





first one is OK for me, cause the variable's value range is 0  10





Out of curiosity, which way did you pick?





2147483642 = 0xFFFF FFFF 8000 0006, Could you explain why a number must greater than the 0xFFF FFFF 8000 0006?
if I want to implement a logic: if x++ > 290 then x = 290, shall I use the same 0xFFFF FFFF 8000 0006?





Wait, are your integers 64bits long? That changes some things, such as the limits.
You can, with 32bit integers and arithmetic shifts, use
x = ((x  290) >> 31);
Will work from x = 2147483358 to x = 290.
For 64bit integers and arithmetic shifts:
x = ((x  290) >> 63);
Will probably work from x = 0x8000000000000122 to x = 290, but I haven't tried it.
(the third way, of course, has higher upper limits)
The number had to be greater than 0x80000006 (or 0x80000121 in this case) because otherwise for lower x (there are very few values lower than that, of course), subtracting 7 (290 in this case) would overflow. That usually results in wrapping to a positive number (thus destroying the mask), or, because signed overflow is actually UB in C++, it could do something .. unspecified, which is also not a good thing. The first reasons makes it so that you can't cast to unsigned to do the subtraction to get rid of the UB and thereby fix the problem  you can absolutely cast to unsigned to do the subtraction and that would get rid of the UB, but it wouldn't fix the problem.
modified 20Nov13 12:37pm.





Thank you,it's 32bit word





The spiral function f(n),
maps a nonnegative integer n onto an ordered pair of integers ¡
x(n), y(n)
. For example, it maps n = 9 onto the ordered pair (1; 2)
11 10 9
2 1 8
3 0 7
4 5 6
0<=n<=1000
is there any direct mapping function or I have to use looping..?
i thing there is direct mapping function because question is from "Concrete Mathematics"





Never heard of that function. Can you tell us more about it?





The first step is the observation that the number of nonedge numbers (in the center block) is always an odd number squared.
E.g. for 18, it's the single number, 0, which is 1 squared. For 924, it's 3 squared (the nine digits 08).
So you find the largest odd square that can be subtracted from n without going negative. The remainder gives the position on the edge, starting from the position above the upperright corner of the center block.





I need a test input file for a function I'm developing  no problem I thought, I'll quickly whip one up in Excel and get on with it. I've now been trying to create the test file for three days!
It seems so simple, but probability appears to be working against me!
I need a 1000x1000 symmetric matrix with 49 'random' ones in each column, filled in reciprocally to make the thing symmetrical. Obviously as you come to the bottom corner of the matrix the available 'random' slots start to run out. Nevermind I thought, I'll wait until my code gets to the hard bit, stop it and then fill in the missing bits by hand.
Unfortunately, I always seem to be left with an insoluble problem  I can't fill in the column, because (somehow) the reciprocal spaces I 'need' have already been used. I'm sure I've made some elementary mistake, but I just can't spot it.
Can anyone fix my code? (Or come up with an algorithm that works!)
Ugly hacky VBA below:
Option Explicit
Public Sub CreateRandomPeers()
Dim TotalEntries As Integer
Dim colEnd As Integer
Dim rowEnd As Integer
Dim colStart As Integer
Dim rowStart As Integer
Dim curCol As Integer
Dim curRow As Integer
Dim curEntries As Integer
Dim rndEntries As Integer
Dim rndRow As Integer
Dim count As Integer
Dim colcnt As Integer
Dim i As Integer, j As Integer
Dim row As Integer
Dim col As Integer
Dim calcmode As XlCalculation
TotalEntries = 49
colEnd = 1001
rowEnd = 1001
colStart = 2
rowStart = 2
calcmode = Application.Calculation
Application.Calculation = xlCalculationAutomatic
curRow = rowStart
For curCol = colStart To colEnd Step 1
curPeers = 0
For i = rowStart To rowEnd Step 1
If (Application.Cells(i, curCol) = 1) Then
curEntries = curEntries + 1
End If
Next i
rndEntries = TotalEntries  curEntries
Randomize
count = 0
While (count < rndEntries)
DoEvents
rndRow = CInt(Int((rowEnd  rowStart + 1) * Rnd())) + rowStart
If (rndRow <> curCol) Then
If (Application.Cells(rndRow, curCol) = 0) Then
colcnt = 0
For j = rowStart To rowEnd Step 1
colcnt = colcnt + Application.Cells(j, rndRow)
Next j
If (colcnt < TotalEntries) Then
Application.Cells(rndRow, curCol) = 1
Application.Cells(curCol, rndRow) = 1
count = count + 1
End If
End If
End If
Wend
Next curCol
Application.Calculation = calcmode
End Sub
Public Sub Reset()
Application.Range("B2:ALM1001") = 0
Application.Calculation = xlCalculationAutomatic
End Sub
modified 29Oct13 20:00pm.





The matrix you are creating would have zeroes on the diagonal, and then you insert "1's" at random on #49 pairs of "symmetric" cells of the form cell[i,j] = 1, and cell[j,i] = 1 ?
One thing that "jumped out" at me reading your code:
rndEntries = TotalEntries  curEntries I can't see 'TotalEntries being initialized to any value in your code; is it possible that 'TotalEntries should be: 'TotalPeers ?
thanks, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
modified 29Oct13 11:59am.





Yeah, TotalEntries should be 49, edited to fix





Hey guys!
Recently I posted this question "Picking entities from a group[^]" on the codeproject. I was advised to move it to this forum because some of you clever ones may have a way to go.
My problem is that I have a group of n people (in my example I said 8 but let's say a minimum of four). I want each person in the group to point to a different person in the group. This means no person can point to himself. Also if a person points to some person in the group, no other person in the group can point to the same person. So everyone in the group must point to a person, and everyone in the group is pointed at. I also want the process to be random.
For now I've already done this by creating a generic list of 'allowed' persons, pick a random person from the list, remove that person from the list and so on.
Now here comes the difficult part..
I also want to be able to configure impossible combinations. Like Person A cannot point to Person B and Person B cannot point to Person A.
This makes the process way more difficult. I'd like to have the ability to test whether a certain configuration is possible and to only pick between these possible 'combination sets'.
My solution now, is a trial on error method. I start a large loop and start to random picking just like above. I generate a list of possibilities and pick one of the possibilities. If the list of possibilities happens to be empty, that means I ran into an impossible 'combination set' and start the entire process again. If the picking fails a certain number of times, I assume the configuration is impossible.
As you understand my solution for now isn't ideal, 'cause there's no way to check whether a configuration is possible and if my picking routine tells me the configuration is not possible you're not actually sure the config is not possible.
I think I got my problem explained well as my English is fairly good but way from perfect. Hope you guys can point me in a good direction.
Thanks! Eduard
.: I love it when a plan comes together :.




