|
It amounts to simply writing down the steps necessary to complete the task. Since it's pseudo code, you don't need to be technically accurate.
What is the first thing that has to happen to solve this problem? What is the second thing?
Hint:
1. User enters number
2. First step to calculate answer
3. Second step to calculate answer
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Here's one clue: when you want to have a loop that is guaranteed to be executed once, that construct is: Do ... While. In this case consider:
Do
// code
// code
While (the user has not entered 9999)
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|
There is no standard for writing pseudo-code, so you almost free to write without bounds of language syntax (however I saw universities with there own standard, and if you have something like this at your college, you should use it).
Read about the idea of pseudo-code - start here http://en.wikipedia.org/wiki/Pseudocode[^]
This is one sample to the '9-2.5' problem...
GET temp_f
WHILE temp_f != 9999
COMPUTE temp_c = (temp_f - 32) * 5/9
PRINT temp_c
GET temp_f
LOOP
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).
|
|
|
|
|
Thanks a lot man! I appreciate it!
|
|
|
|
|
You're not supposed to do the work for him!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
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 2-Dec-13 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 bit-wise expression fit the same function?
modified 6-Nov-13 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 20-Nov-13 12:37pm.
|
|
|
|
|
Thank you,it's 32bit word
|
|
|
|
|
The spiral function f(n),
maps a non-negative 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 non-edge numbers (in the center block) is always an odd number squared.
E.g. for 1-8, it's the single number, 0, which is 1 squared. For 9-24, it's 3 squared (the nine digits 0-8).
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 upper-right corner of the center block.
|
|
|
|