/*
This code will be my step by step figuring out of an algorithm to suggest best investing practices, given the valuations and times of the valuations. For example, if stock 1 does well on the first day, while stock 2 does poorly, and stock 2 does well the next day and stock one does poorly. The algorithm will suggest buying shares in the first stock the first day, selling them to buy stock 2 the second day.
Essentially it will follow the logic: calculate which stock has the highest rate of growth between given moments. Since there is no cost to sell and no cost to buy (in this early step), All shares should be sold to purchase the stock which will have the highest rate of growth. The program should accept the following inputs: the value of stock 1 on day one, day two, day three, and the value of stock 2 on day one, day two, and day three. The program will set a variable to represent how much money is owned.
A later update of this algorithm will return a prioritized list of what I should do next. It will prompt me to gather information about the activities, such as what I can gain in return for doing them, when I will get the return, the amount of time which will be spent (it will multiply this by the current hourly work worth
*/
var s1d1 = prompt("what is the value of stock one on day one? ");
var s1d2 = prompt("what is the value of stock one on day two? ");
var s1d3 = prompt("what is the value of stock one on day three?");
var s2d1 =prompt("what is the value of stock two on day one?");
var s2d2 =prompt("what is the value of stock two on day two?");
var s2d3 =prompt("what is the value of stock two on day three?");
if (s1d2/s1d1 >= s2d1/s2d2)
var answer = "Buy stock 1 for day one. "
else if (s1d2/s1d1 <= s2d1/s2d2)
var answer = "Buy stock 2 for day one. "
if (s1d2/s1d1 >= s2d1/s2d2)
answer += "Buy stock 1 for day two. "
else if (s1d2/s1d1 <= s2d1/s2d2)
answer += "Buy stock 2 for day two. "
if (s1d2/s1d1 >= s2d1/s2d2)
answer += "Buy stock 1 for day three. "
else if (s1d2/s1d1 <= s2d1/s2d2)
answer += "Buy stock 2 for day three. "
console.log(answer);
Tuesday, September 22, 2015
Tuesday, September 15, 2015
creating random rhythms
/*
Public notes: This program generates rhythmic note lengths with 1-9 beat durations. The order is randomly generated. The note durations do not repeat.
Personal Notes: I will code a program which generates a random pattern of K*** and R*** k. K represents the note, R represents a rest. I want this program to generate in a random pattern of all the nojte durations that could occur. But it will only give them once each time it is run, not more than once.
Here is my strategy, first I will set variables.
The string will be stored in a variable called rhythm.
rhythm will be set as the first value. then concated with additional randomly generated values.In between the concatenation there will be an "K" concatenated as well. This will be the first program.
NExt program will take the random value generated and store it in a variable before concatenating with rhythm. Whatever the value of the variable, there will be a designated variable created to confirm that the value has not already been concatenated with rhythm. So the program will set the value equal to the randomly generated value, if the value is equal to for example 5, check if the variable five = 5 and if it does, start loop over again. if the variable five = null, then set variable five = to 5, concatenate to rhythm and then run the loop over again. Set a counter so that the loop does not time out when it hits all the values.
*/
// Here is version two... in progress.
var zero = null;
var one = null;
var two = null;
var three = null;
var four = null;
var five = null;
var six = null;
var seven = null;
var eight = null;
var rhythm = "";
var lights = null;
for (var counter = 0; counter < 9;)
{
random = Math.round(Math.random() * 8);
var lights = 1;
if (random === 0)
{if (zero === 0)
lights = 0;
else
{zero = 0;
counter++;
}
}
else if (random === 1)
{if (one === 1)
lights = 0;
else
{one = 1;
counter++;
}
}
else if (random === 2)
{if (two === 2)
lights = 0;
else
{two = 2;
counter++;
}
}
else if (random === 3)
{if (three === 3)
lights = 0;
else
{three = 3;
counter++;
}
}
else if (random === 4)
{if (four === 4)
lights = 0;
else
{four = 4;
counter++;
}
}
else if (random === 5)
{if (five === 5)
lights = 0;
else
{five = 5;
counter++;
}
}
else if (random === 6)
{if (six === 6)
lights = 0;
else
{six = 6;
counter++;
}
}
else if (random === 7)
{if (seven === 7)
lights = 0;
else
{seven = 7;
counter++;
}
}
else if (random === 8)
{if (eight === 8)
lights = 0;
else
{eight = 8;
counter++;
}
}
if (lights ===1)
{rhythm += "R";
for (var counter3 = 0; counter3 < random; ++counter3)
rhythm += "*";
}
}
console.log(rhythm);
Public notes: This program generates rhythmic note lengths with 1-9 beat durations. The order is randomly generated. The note durations do not repeat.
Personal Notes: I will code a program which generates a random pattern of K*** and R*** k. K represents the note, R represents a rest. I want this program to generate in a random pattern of all the nojte durations that could occur. But it will only give them once each time it is run, not more than once.
Here is my strategy, first I will set variables.
The string will be stored in a variable called rhythm.
rhythm will be set as the first value. then concated with additional randomly generated values.In between the concatenation there will be an "K" concatenated as well. This will be the first program.
NExt program will take the random value generated and store it in a variable before concatenating with rhythm. Whatever the value of the variable, there will be a designated variable created to confirm that the value has not already been concatenated with rhythm. So the program will set the value equal to the randomly generated value, if the value is equal to for example 5, check if the variable five = 5 and if it does, start loop over again. if the variable five = null, then set variable five = to 5, concatenate to rhythm and then run the loop over again. Set a counter so that the loop does not time out when it hits all the values.
*/
// Here is version two... in progress.
var zero = null;
var one = null;
var two = null;
var three = null;
var four = null;
var five = null;
var six = null;
var seven = null;
var eight = null;
var rhythm = "";
var lights = null;
for (var counter = 0; counter < 9;)
{
random = Math.round(Math.random() * 8);
var lights = 1;
if (random === 0)
{if (zero === 0)
lights = 0;
else
{zero = 0;
counter++;
}
}
else if (random === 1)
{if (one === 1)
lights = 0;
else
{one = 1;
counter++;
}
}
else if (random === 2)
{if (two === 2)
lights = 0;
else
{two = 2;
counter++;
}
}
else if (random === 3)
{if (three === 3)
lights = 0;
else
{three = 3;
counter++;
}
}
else if (random === 4)
{if (four === 4)
lights = 0;
else
{four = 4;
counter++;
}
}
else if (random === 5)
{if (five === 5)
lights = 0;
else
{five = 5;
counter++;
}
}
else if (random === 6)
{if (six === 6)
lights = 0;
else
{six = 6;
counter++;
}
}
else if (random === 7)
{if (seven === 7)
lights = 0;
else
{seven = 7;
counter++;
}
}
else if (random === 8)
{if (eight === 8)
lights = 0;
else
{eight = 8;
counter++;
}
}
if (lights ===1)
{rhythm += "R";
for (var counter3 = 0; counter3 < random; ++counter3)
rhythm += "*";
}
}
console.log(rhythm);
Sunday, September 13, 2015
//Here is some code that helps you write code: helps the user define a variable in javascript.
var variablename = "number";
var varName = prompt("What would you like to name your variable?");
var varValue = prompt("What would you like to set as the value of your variable?");
alert("var " + varName + " = " + varValue + ";");
Wednesday, September 9, 2015
Based on equity goals, this tells you whether to accept or refuse funding.
/*
USER NOTE: this assumes the person wants to leave proportionate equity for a number of categories: coFounder, uncle, option pool, angel investors, employee number 1, Venture Capitalists, IPO,
USER NOTE: this assumes the person wants to leave proportionate equity for a number of categories: coFounder, uncle, option pool, angel investors, employee number 1, Venture Capitalists, IPO,
Inputs
investor
type
percent
requested
process
and defaults
investor
type intro percents
output
yes
is percentreq < investortype introper
no
is percentreq > investortype perc
*/
var
investorType = prompt("Who is the new investor? (options:
coFounder, uncle, optionPool, angel, employee1, VC, IPO");
var
requestedEquity = prompt("What percent of the company are they
seeking? 0-1");
var
dilutionModel = prompt("Would you like to use the dilution
model? (yes or no)");
var
sRatio = (100 - prompt("What percent would you like to retain?
(0-100)"))
/ 82.4;
if
(dilutionModel == "yes") {
if
(investorType == "coFounder") maxAllowance = .5 * sRatio;
else
if (investorType == "uncle") maxAllowance = .05 * sRatio;
else
if (investorType == "optionPool") maxAllowance = .2 *
sRatio;
else
if (investorType == "angel") maxAllowance = .167 * sRatio;
else
if (investorType == "employee1") maxAllowance = .018 *
sRatio;
else
if (investorType == "VC") maxAllowance = .333 * sRatio;
else
if (investorType == "IPO") maxAllowance = .083 * sRatio;
}
else if (dilutionModel = "no") {
if
(investorType == "coFounder") maxAllowance = .176 * sRatio;
else
if (investorType == "uncle") maxAllowance = .024 * sRatio;
else
if (investorType == "optionPool") maxAllowance = .1245 *
sRatio;
else
if (investorType == "angel") maxAllowance = .095 * sRatio;
else
if (investorType == "employee1") maxAllowance = .017 *
sRatio;
else
if (investorType == "VC") maxAllowance = .305 * sRatio;
else
if (investorType == "IPO") maxAllowance = .083 * sRatio;
};
if
(maxAllowance >= requestedEquity) {
alert("go
for it! They are requesting less than " + maxAllowance);
var
valuation = prompt("what is your company worth in dollars?");
alert("You
will get " + valuation * maxAllowance);
}
else alert("wait..They should request less than " +
maxAllowance);
Wednesday, August 26, 2015
Here is my second attempt at making the chessboard. I think this code is a little bit simpler and it has a prompt so it is a bit more user friendly than the previous version.
var givenNum = Number(prompt("give a number, make a chessboard!"));
for (var firstLine = "#";firstLine.length <=givenNum ; firstLine+="#")
{
if (firstLine.length == givenNum)
break;
firstLine += " ";
if (firstLine.length == givenNum)
break;
}
for (var secLine = " ";secLine.length <=givenNum ; secLine+=" ")
{
if (secLine.length == givenNum)
break;
secLine += "#";
if (secLine.length == givenNum)
break;
};
var counter = 1;
var theLine = firstLine
while (counter <=givenNum)
{
theLine += "\n" + secLine;
counter++;
if (counter ==givenNum)
break;
theLine += "\n" + firstLine;
counter++;
if (counter == givenNum)
break;
};
console.log(theLine);
var givenNum = Number(prompt("give a number, make a chessboard!"));
for (var firstLine = "#";firstLine.length <=givenNum ; firstLine+="#")
{
if (firstLine.length == givenNum)
break;
firstLine += " ";
if (firstLine.length == givenNum)
break;
}
for (var secLine = " ";secLine.length <=givenNum ; secLine+=" ")
{
if (secLine.length == givenNum)
break;
secLine += "#";
if (secLine.length == givenNum)
break;
};
var counter = 1;
var theLine = firstLine
while (counter <=givenNum)
{
theLine += "\n" + secLine;
counter++;
if (counter ==givenNum)
break;
theLine += "\n" + firstLine;
counter++;
if (counter == givenNum)
break;
};
console.log(theLine);
Tuesday, July 28, 2015
Eloquent Javascript
Currently reading "Eloquent Javascript" by Marijn Haverbeke.
One of the exercises in "Eloquent Javascript" called for writing code for creating a chessboard pattern of hashtags and spaces for a square shape in the console.
One of the exercises in "Eloquent Javascript" called for writing code for creating a chessboard pattern of hashtags and spaces for a square shape in the console.
Here is my code (it seems to work)
var number = 13;
var computerN = number * number + number - 1;
var string = ' ';
while (string.length < computerN)
{
if (number % 2 === 0)
{
string = string + '#';
if (string.length === computerN)
{
break;
}
else if ((string.length - number) % (number + 1) === 0)
{
string = string + '\n#';
}
string = string + ' ';
if (string.length === computerN)
{
break;
}
else if ((string.length - number) % (number + 1) === 0)
{
string = string + '\n ';
}
}
else
{
if (string.length === computerN)
{
break;
}
else if ((string.length - number) % (number + 1) === 0)
{
string = string + '\n# ';
}
string = string + '#';
if (string.length === computerN)
{
break;
}
else if ((string.length - number) % (number + 1) === 0)
{
string = string + '\n #';
}
string = string + ' ';
}
}
console.log(string);
Subscribe to:
Posts (Atom)