User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion

Reply
Thread Tools Display Modes
Unread 23 Sep 2004, 18:27   #1
JammyJim
Godfather
 
JammyJim's Avatar
 
Join Date: May 2000
Location: England
Posts: 5,185
JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
ASP Again - this time its more difficult

A challenge if you will :



I have a variable with a value of say 100

This figure has to be split between 4 people with set percentages.
However the user has the ability to either remove or add another person.

So the percentages change.

When removing a user they remove the person with the smallest percentage.
When adding a user the percentages of the total have to change to allow for this new person.




A maximum of 4 can be added (but not at once)
and a maximum of 4 can be removed (not at once)

You can only add one per turn and only remove one per turn. (there are 4 turns).


If someone is removed and then someone new is added in the same turn, the new person will always have a higher percentage than the last person.


The original 4 people have the names:


JJ
JT
LK
IH


When adding another person the name must be unique. for example. If you remove someone and then choose to add someone in the next turn the name cant be the same as the original name added. It has to be different.
e.g.


Turn 1 :
JJ (40%)
JT (30%)
LK (20%
IH - (10%) Remove him....


Turn 2 :

JJ (42%)
JT (33%)
LK (25%)

(nothing done)


Turn 3 :
JJ (35%)
JT (20%)
LK (15%)
NG - (30%) (not the same as the original '4th person')


now how in the hell do i program this? Obviously ill need a database but its got me truly stumped.
__________________
Forum Administrator
Mail : [email protected] // IRC : #forums
__________________
It's not personal, it's just business.
JammyJim is offline   Reply With Quote
Unread 23 Sep 2004, 18:27   #2
JammyJim
Godfather
 
JammyJim's Avatar
 
Join Date: May 2000
Location: England
Posts: 5,185
JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: ASP Again - this time its more difficult

oh im programming in ASP but this is a concept...
i dont necessarily need code to do this but i need the idea as to how to do it.


Thanks in advance
__________________
Forum Administrator
Mail : [email protected] // IRC : #forums
__________________
It's not personal, it's just business.
JammyJim is offline   Reply With Quote
Unread 23 Sep 2004, 19:14   #3
TheRat
Retired
 
Join Date: Dec 2000
Location: Rogaland, Norway
Posts: 642
TheRat has much to be proud ofTheRat has much to be proud ofTheRat has much to be proud ofTheRat has much to be proud ofTheRat has much to be proud ofTheRat has much to be proud ofTheRat has much to be proud ofTheRat has much to be proud of
Re: ASP Again - this time its more difficult

Why on earth would you need a db on that? I dont know vb (thank god) but I could do it in php or C#
__________________
Of all the things I've lost I miss my mind the most

-Elysium Officer
[1up] Senior MO
Retired
TheRat is offline   Reply With Quote
Unread 23 Sep 2004, 19:29   #4
queball
Ball
 
queball's Avatar
 
Join Date: Oct 2001
Posts: 4,410
queball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so littlequeball contributes so much and asks for so little
Re: ASP Again - this time its more difficult

I'd do something like...

Dim names() As String
names(0)="JJ"
names(1)="JT"
names(2)="LK"
names(3)="IH"
names(4)="NG"
names(5)="CM"
names(6)="NE"
names(7)="RH"
usednames=4

Dim shares() As Integer
shares(0)=40
shares(1)=30
shares(2)=20
shares(3)=10
shares(4)=0
shares(5)=0
shares(6)=0
shares(7)=0

Function LowestShare()
index = -1
value = 100
For i = 0 To 7
If shares(i) <> 0 And shares(i) < value Then index = i : value = shares(i)
Next
LowestShare = index
End Function

Sub recruit()
newshare = 10 'I don't know how you calculate this

total = newshare
factor = (100.0 - newshare) / 100.0
For Each share In shares
share = share * factor 'Should round down
total = total + share
Next
shares(LowestShare()) = shares(LowestShare()) + 100 - total

share(usednames) = newshare
usednames = usednames + 1
End Sub

Sub fire()
factor = 100.0 / (100.0 - shares(LowestShare()))
shares(LowestShare()) = 0

total = 0
For Each share In shares
share = share * factor
total = total + share
Next

If total <> 0 Then shares(LowestShare) = shares(LowestShare) + 100 - total
EndSub


then to print

For i = 0 to 7
If shares(i)<>0 Then Print names(i) & " (" & shares(i) & ")"
End For
queball is offline   Reply With Quote
Unread 23 Sep 2004, 20:29   #5
JetLinus
Friendly geek of GD :-/
 
JetLinus's Avatar
 
Join Date: Nov 2000
Location: On my metal roid
Posts: 923
JetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud ofJetLinus has much to be proud of
Arrow Re: ASP Again - this time its more difficult

  • Your names must be "unique". What does that mean? Does the name have to be different from the names already in the list, or must one name that has been used never appear again?
    Anyway, if all your names are only 2 letters, that'd be 26² = 676 in total. You have to make sure the program doesn't crash then (possible DoS).

  • Is there a maximum of allowed people (in total, at one time, whatever)?

  • How do the percentages get distributed? Are there rules? Or is it user input? I mean, HOW exactly do they have to change? How "important" is a new user, i.e. how many shares does he get? Does the old ratio have to remain the same?

  • How often does it happen? Does performance matter? If so, you could pre-calculate all possible values / calculations or at least do some lookup-tables to speed up a bit....


Anyway, I strongly recommend a Datatype before doing anything else
Code:
Type typUser
    UserName As String ' * 2   ' if fixed sized
    UserShare As Single  ' or As Long if integers are ok
End Type
Then preserve memory ofc.
Code:
Dim User(1 to MAXUSERCOUNT) As typUser
This'll be your main-working-array. You don't need a database at all.
Everything you do is going to happen in that User-List.

A real nice and useful trick, to prevent it from getting "holes" (i.e. keeping it unfragmented):
Everytime you delete a user, put the last one from the list in the new empty slot. So the list remains one block.
I know you lose your sorting-order in this progress, but if that's important to you, store it in a variable "UserPos As Long" the user-datatype.


And now, before I can give additional help:
  • What's the whole thing for?
__________________
[»] Entropy increases! :-/
JetLinus is offline   Reply With Quote
Unread 23 Sep 2004, 21:10   #6
JammyJim
Godfather
 
JammyJim's Avatar
 
Join Date: May 2000
Location: England
Posts: 5,185
JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: ASP Again - this time its more difficult

Its part of a larger program that deals with a set of accounts.

to answer a few questions first tho :

"Your names must be "unique". What does that mean? Does the name have to be different from the names already in the list, or must one name that has been used never appear again?
Anyway, if all your names are only 2 letters, that'd be 26² = 676 in total. You have to make sure the program doesn't crash then (possible DoS)."

- Not necessarily unique. you only need a maximum of 8 names in total. 4 to start with and then 4 additional presuming they add one every turn. so infact these can just be 'stored' somewhere or written in etc...



"Is there a maximum of allowed people (in total, at one time, whatever)?"

your only allowed to add one per quarter or reduce one per quarter. so yes..kinda..


"How do the percentages get distributed? Are there rules? Or is it user input? I mean, HOW exactly do they have to change? How "important" is a new user, i.e. how many shares does he get? Does the old ratio have to remain the same?"

Percentages are set for the original 4. They then vary accordingly depending on whether the person brought in is new etc.


"How often does it happen? Does performance matter? If so, you could pre-calculate all possible values / calculations or at least do some lookup-tables to speed up a bit...." it happens once every quarter on a single page. the resutls dont have to be saved. just shown.



Basically what im displaying is a large set of accounts per quarter. I want to be able to add/subtract a salesperson to these accounts and then allocate a '%' of sales to them. (the increase/decrease in sales resulting from hiring/firing of people has already been calculated)

So we start with 4 salespeople and then each quarter you can add/subtract or fire the 'crap guy' and hire someone new.
(hence the 'if someone is fired then a new guy hired then the % should increase')

Now. i wanted a really easy way to just do this on screen without a huge amount of hassle or complicated maths. Im not the greatest coder in the world and ill freely admit to 'knowing what i need to know but not much else' so im contemplating merely storing every possible combination somewhere and then picking the correct one based on which things have been chosen and when....which is a pain in the ass but would solve the problem.




I cant say precisely what the entire thing is for because of client confidentiality. (tis a big client). however that should be enough for just this section of the project to give you an understanding.
__________________
Forum Administrator
Mail : [email protected] // IRC : #forums
__________________
It's not personal, it's just business.
JammyJim is offline   Reply With Quote
Unread 27 Sep 2004, 00:25   #7
Add
Registered User
 
Join Date: Feb 2001
Posts: 442
Add will become famous soon enoughAdd will become famous soon enough
Re: ASP Again - this time its more difficult

Code:
<?

$variable = 100; // to be split

if (!isset($currentnames) { // sent via post/get/session whatever
	$currentnames = array('JJ' => 0.25, 'JT' => 0.25, 'LK' => 0.25, 'IH' => 0.25);
}
if (!isset($usednames) { //sent via post/get/session whatever
	$usednames = array('JJ', 'JT', 'LK', 'IH');
}

if (form_submitted) {
	if (!isset($turn)) { // sent via post/get/session whatever
		$turn = 0; //current turn
	}
	else {
		$turn++;
	}
	if ($turn >=5) {
		die 'max turns exceeded';
	}

	if (isset($removeuser)) {
		asort($currentnames); // http://uk.php.net/manual/en/function.asort.php
		$removedname = array_pop($currentnames);
	}

	if (isset($adduser)) {
		if (in_array($newusername, $usednames)) {
			die 'user has already been in our system';
		}
		$newuserpercent = preg_replace('![^\d.]!', '', $newuserpercent); // remove crap
		$newuserpercent = $newuserpercent / 100;

		$whatsleft = 1 - $newuserpercent; // how much the others have got to share
		while (list($key, $val) = each($currentusers)) {
			$currentusers[$key] = ($val / $whatsleft) * 100; // it's late, i think that's the right way around
		}
		$currentusers[$newusername] = $newuserpercent;
		array_push($usednames, $newusername);
	}
}

$testtotal = 0;
while (list($key, $val) = each($currentusers)) {
	$testtotal = $testtotal + $val;
}
echo $testtotal; // should echo 1 if everything is correct...

?>
um, i think it's more of a maths problem than a programming one, i've done it in psuado php 'cause i prefer it and im not getting paid to write in asp, i havnt tested it and only think it might work...
__________________
Trust in my Instinct

Last edited by Add; 27 Sep 2004 at 00:46.
Add is offline   Reply With Quote
Unread 28 Sep 2004, 14:56   #8
JammyJim
Godfather
 
JammyJim's Avatar
 
Join Date: May 2000
Location: England
Posts: 5,185
JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.JammyJim has ascended to a higher existance and no longer needs rep points to prove the size of his e-penis.
Re: ASP Again - this time its more difficult

Code:
<%
'3 arrays....1 for new names and one for used names, one for percentages.
fired = 1

Dim oldnames()
dim pc()
Dim newnames(0)


ReDim oldnames(3)
oldnames(0) = "JJ"
oldnames(1) = "JT"
oldnames(2) = "PT"
oldnames(3) = "JP"


'Only need one new name per time. so this will change on the next quarters page.
newnames(0) = "PS"

'Remove name from the array.

If fired = 1 then 
ubound(oldnames) = ""
end if

'Add a new array to the oldnames array if they employ someone else.

if employ = 1 then
strincreasesize = ubound(oldnames) + 1
Redim oldnames (strincreasesize)
UBound(oldnames) - LBound(oldnames) + 1 = newnames(0)
end if


'Get size of Array after its been changed.
iArraySize = (UBound(oldnames) - LBound(oldnames)) + 1
iArraySize2 = (UBound(newnames) - LBound(newnames)) + 1

'Get how many names there are currently
iTotalArray = iArraySize + iArraySize2

if itotalarray = 1 then
Redim pc(0)
pc(0) = 100/1
end if
if itotalarray = 2 then
Redim pc(1)
pc(0) = 100/0.6 * totalsales
pc(1) = 100/0.4 * totalsales
end if
if itotalarray = 3 then
Redim pc(2)
pc(0) = 100/0.5 * totalsales
pc(1) = 100/0.3 * totalsales
pc(2) = 100/0.2 * totalsales
end if
if itotalarray = 4 then
Redim pc(3)
pc(0) = 100/0.4 * totalsales
pc(1) = 100/0.3 * totalsales
pc(2) = 100/0.2 * totalsales
pc(3) = 100/0.1 * totalsales
end if
if itotalarray = 5 then
Redim pc(4)
pc(0) = 100/0.3 * totalsales
pc(1) = 100/0.3 * totalsales
pc(2) = 100/0.2 * totalsales
pc(3) = 100/0.1 * totalsales
pc(4) = 100/0.1 * totalsales
end if 
if itotalarray = 6 then
Redim pc(5)
pc(0) = 100/0.3 * totalsales
pc(1) = 100/0.2 * totalsales
pc(2) = 100/0.2 * totalsales
pc(3) = 100/0.1 * totalsales
pc(4) = 100/0.1 * totalsales
pc(5) = 100/0.1 * totalsales
end if
if itotalarray = 7 then
Redim pc(6)
pc(0) = 100/0.2 * totalsales
pc(1) = 100/0.2 * totalsales
pc(2) = 100/0.2 * totalsales
pc(3) = 100/0.1 * totalsales
pc(4) = 100/0.1 * totalsales
pc(5) = 100/0.1 * totalsales
pc(6) = 100/0.1 * totalsales
end if
if itotalarray = 8 then
Redim pc(7)
pc(0) = 100/0.2 * totalsales
pc(1) = 100/0.2 * totalsales
pc(2) = 100/0.1 * totalsales
pc(3) = 100/0.1 * totalsales
pc(4) = 100/0.1 * totalsales
pc(5) = 100/0.1 * totalsales
pc(6) = 100/0.1 * totalsales
pc(7) = 100/0.1 * totalsales
end if 

ShowArrayInTable(oldnames)
ShowArrayInTable(pc)



%>






arrayemployed = arrayemployed + 1
end if

response.write names(arraysemployed)

%>
obviously its just the 'barebones' and its not getting any information atm. ive hardcoded the 'fired = 1' thing in just to see if it works...


however im getting a 'ubound is not a valid whatnot' error.....

can anyone help with the code?
__________________
Forum Administrator
Mail : [email protected] // IRC : #forums
__________________
It's not personal, it's just business.
JammyJim is offline   Reply With Quote
Unread 1 Oct 2004, 08:34   #9
SYMM
Love's Sweet Exile
 
SYMM's Avatar
 
Join Date: May 2001
Location: Living on a Stair (Now Sword-less)
Posts: 2,371
SYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better placeSYMM single handedly makes these forums a better place
Re: ASP Again - this time its more difficult

One time you use "ubound", another time "UBound". Not knowing ASP, I'm not sure if this is an issue...
[edit] Again, not knowing anything about ASP, but
UBound(oldnames) - LBound(oldnames) + 1 = newnames(0)
looks wrong...assignment generally needs to be the other way round...(a=B+C)
__________________
--SYMM--
Ba Ba Ti Ki Di Do

Last edited by SYMM; 3 Oct 2004 at 14:51.
SYMM is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Forum Jump


All times are GMT +1. The time now is 12:49.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018