|
Thanks all - I can feel my first CP article coming on now. Not specifically to do with this control, but the whole concept of doing something, hitting problems, the investigation, the questions asked, teh answers, the application of the answers to the problem etc.
Thanks again.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
You're welcome.
Looking forward to your article; please make sure it ends on "12".
|
|
|
|
|
Luc Pattyn wrote: and they match very closely with what MS Word is offering with their "Fill Gradient between
Two Colors".
I know, I made a little test after posting my answer (I was a bit confident...).
Luc Pattyn wrote: Well done !
Thank you very much.
Luc Pattyn wrote: BTW: curious how you would solve it if you are not as lucky as to find one of (r,g,b)
at a constant value tho.
Well, maybe with a little help of my friend sphere ...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Just plugged the formula in and it worked a treat, just had to use 100-n instead of n to reverse the gradient.
Thanks again.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Malcolm Smart wrote: Just plugged the formula in and it worked a treat, just had to use 100-n instead of n to reverse the gradient.
Sure? You asked for:
0% = Green.
100% = Red.
My formula was:
g(n)= (int) ( 255 * cos( n * pi / 200) + .5)
r(n)= (int) ( 255 * sin( n * pi / 200) + .5)
i.e. full green when n==0.
Anyway, of course, use whatever you find to fit better you needs!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
That's because you wrongly assumed I have the ability to copy your formula correctly.
If I had, then I wouldn't have needed the 100-n change. I somehow managed to switch the Cos and Sin between the Red and the Green, in which case, I needed the 100-n .
Switched them back, removed the 100-n , and as you said it would, so long ago, it worked.
Thanks for the help....again.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Malcolm Smart wrote: That's because you wrongly assumed I have the ability to copy your formula correctly.
Well, I correctly assumed that you have such ability (after all you're Malcom Smart...) since eventually you did.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hello
Can any one plz give me an algorithm to find all the elements in an array that are repeated atleast once?
Thanks in advance
Rocky
|
|
|
|
|
Rocky71 wrote: Can any one plz give me an algorithm to find all the elements in an array that are repeated atleast once?
brute force: read all, check for match on all.
Now if you want minimal search, now you are talking fun....
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Just add a sort pass. With potential duplicates adjacent to each other an O(n) detection routine is trivial.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
dan neely wrote: Just add a sort pass.
true, it said nothing about order.
There you go, two algorithms, issue solved.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
yea i guess there's no other option but to use brute force
|
|
|
|
|
well, what did you expect ?
Here are two approaches without any visible sorting:
1.
just enter the numbers one by one in a hashtable; use the numbers as the key,
and their multiplicity as the value.
So to add a[i], check for presence of key a[i]; if not, add the pair (a[i], 1),
else replace (a[i], value) by (a[i], value+1).
When done, enumerate the keys with value>=2
2.
Since you are not interested in actual multiplicity values, you could try
two simple lists: one for "seen just once", the other for "seen more than once".
Now for each a[i] first test the "more than once", if not present, the "just once",
and move/add the item appropriately.
Dont be surprised if this takes longer, for new numbers you are searching two lists
(albeit they both are smaller).
For both of the above methods, here is a big optimization:
just do it for all numbers but the last one.
If these all appear more than once, there is no need to read the last number at all.
|
|
|
|
|
If you want the elements themselves simply sort your list. If you also need the original index values you will have to sort element numbers along with the elements.
After sorting the problem becomes trivial.
|
|
|
|
|
Math Magic on Yahoo[^]
Anybody see the "trick"?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Careful - some educator may adopt it into 'New Math'. For those who haven't heard the Tom Lehrer song
New Math[^]
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
haha,
I think i'd rather just stick with my calculator .
Mark.
|
|
|
|
|
And how do you think your calculator performs its magic ?
|
|
|
|
|
hmmm...
Is it a small black box which houses a microscopic chinese guy inside who is able to almost instantanously solve any mathematical equation you throw at him?
|
|
|
|
|
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
|
is that a regular Polish guy or a reverse Polish?
Apathy Rules - I suppose...
|
|
|
|
|
Trick? What trick? It's the same as usual, but maybe helps some people keep the columns aligned properly.
|
|
|
|
|
PIEBALDconsult wrote: It's the same as usual
Yes it is. Just a different twist to it.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
The previous one was done with sticks, this one just makes it easier for the layman to understand.
"This perpetual motion machine she made is a joke. It just keeps going faster and faster. Lisa, get in here! In this house, we obey the laws of thermodynamics!" - Homer Simpson
Web - Blog - RSS - Math - LinkedIn - BM
|
|
|
|