# Calculus Buddy

A personal voice assistant that could assist you with any math problems you have, including high level math problems in calculus and beyond.

BeginnerShowcase (no instructions)2 hours936

## Things used in this project

### Hardware components

 Amazon Alexa Amazon Echo
×1

### Software apps and online services

 Amazon Alexa Alexa Skills Kit
 Heroku

## Code

### server.js

JavaScript
```var wajs = require('wajs');
var waClient = new wajs("WOLFRAM-ALPHA-KEY-HERE");

var queryString = 'indefinite integral of open paren ten x squared plus sin x squared close paren plus five x';
var queryString2 = 'first derivative of open paren ten x squared plus sin x squared close paren plus five x';
var queryString3 = 'open paren ten x squared plus sin x squared minus eleven x squared close paren plus five x';

String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
};

var unenglishify = function(text) {
return  text.replaceAll("open paren ", "(").replaceAll(" close paren", ")").replaceAll(" squared", "^2").replaceAll(" cubed", "^3")
.replaceAll(" plus ", "+").replaceAll(" minus ", "-").replaceAll(" times ", "*").replaceAll(" divided ", "/").replaceAll(" equals ", "=")
.replaceAll("zero", "0").replaceAll("one", "1").replaceAll("two", "2").replaceAll("three", "3").replaceAll("four", "4")
.replaceAll("five", "5").replaceAll("six", "6").replaceAll("seven", "7").replaceAll("eight", "8").replaceAll("nine", "9")
.replaceAll("ten", "10").replaceAll("eleven", "11").replaceAll("twelve", "12").replaceAll("thirteen", "13")
.replaceAll("fourteen", "14").replaceAll("fifteen", "15").replaceAll("sixteen", "16").replaceAll("seventeen", "17")
.replaceAll("eighteen", "18").replaceAll("nineteen", "19");
}

var englishify = function(text) {
return  text.replaceAll("~~", " approximately equals ").replaceAll("\n", " ")
.replaceAll("  ", " ").replace(/_\((.+)\)\^/g, " from \$1 to ");
}

var alexa = require('alexa-utils');
const PORT = process.env.PORT || 8080;

var app = alexa.app("CalculusBuddy")
.onLaunch(function(req, res) {
res.prompt("Hello there. What would you like me to solve?")
.reprompt("What would you like me to solve?")
.endSession(false)
.send();
})
.onIntent("SolveQuestion", function(req, res) {
var input = req.intent.slot("input");

if (input) {
waClient.query(input).then(function(qr) {
var pods = JSON.parse(qr.toJson());

var resultObj = {};

for (var i = 0; i < pods.pod.length; i++) {
var pod = pods.pod[i];
var podTitle = pod.title;

if (podTitle.toLowerCase().includes("plot") || podTitle === "Alternate forms") {
continue;
}

var subPodTexts = [];

for (var j = 0; j < pod.subpod.length; j++) {
var subPodTitle = pod.subpod[j].title.trim();
var subPodText = pod.subpod[j].plaintext[0].trim();

subPodTexts.push((subPodTitle ? subPodTitle + " equals " : "") + englishify(subPodText));
}

if (subPodTexts.length) {
resultObj[podTitle] = subPodTexts;
}
}

console.log(JSON.stringify(resultObj, null, 2));
var keys = Object.keys(resultObj);
var response = "<speak>Here are some answers and information: ";

for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var values = resultObj[key];
response += "<s>The " + key + ((values.length > 2) ? " are " : " is ");

for (var j = 0; j < values.length; j++) {
var value = values[j];
if (value === "") value = "unknown";
response += value;

if ((j + 1) < values.length) {
response += ", and ";
} else {
if ((i + 1) < keys.length) {
response += ".</s>";
}
}
}
}

response += ".</s></speak>";
console.log(response);

res.prompt(response).endSession(true).send();
})
.catch(function(err) {
console.log(err);
})
} else {
res.prompt("I didn't quite hear what you wanted me to compute. Could you repeat your command again?")
.endSession(false)
.send();
}
})
.onIntent("AMAZON.StopIntent", function(req, res) {
res.prompt("All right, goodbye!").endSession(true).send();
})
.onIntent("AMAZON.CancelIntent", function(req, res) {
res.prompt("All right, goodbye!").endSession(true).send();
})
.onIntent("AMAZON.HelpIntent", function(req, res) {
var prompt = "You can ask me to do any math function, such as 'intergrate x squared plus five', or 'find the roots of x squared minus two x plus one'. You can also say stop or cancel if you are done.";
res.prompt(prompt).endSession(false).send();
})
.onSessionEnd(function(req, res) {
res.prompt("All right, goodbye!")
.endSession(true)
.send();
})
.host("/solve", PORT, false, true);

console.log("Server started on port " + PORT);
```

### Intent Schema

JSON
```{
"intents": [
{
"intent": "SolveQuestion",
"slots": [
{
"name": "input",
"type": "AMAZON.LITERAL"
}
]
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "AMAZON.CancelIntent"
}
]
}
```

### Sample Utterances

snippets
```SolveQuestion to help me solve this problem {integrate x squared plus five minus sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five minus sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five minus sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five minus sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five minus sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five minus sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared plus five sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five minus sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five minus sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five minus sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five minus sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five minus sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five minus sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared minus five sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five minus sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five minus sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five minus sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five minus sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five minus sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five minus sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x squared times five sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x plus five minus sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x plus five minus sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x plus five minus sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x plus five minus sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x plus five minus sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x plus five minus sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x plus five sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x plus five sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x plus five sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x plus five sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x plus five sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x plus five sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x minus five minus sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x minus five minus sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x minus five minus sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x minus five minus sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x minus five minus sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x minus five minus sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x minus five sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x minus five sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x minus five sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x minus five sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x minus five sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x minus five sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x times five minus sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x times five minus sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x times five minus sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x times five minus sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x times five minus sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x times five minus sine x divided by seven x dx|input}
SolveQuestion to help me solve this problem {integrate x times five sine x minus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x times five sine x minus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x times five sine x plus seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x times five sine x plus seven x dx|input}
SolveQuestion to help me solve this problem {integrate x times five sine x divided by seven x squared dx|input}
SolveQuestion to help me solve this problem {integrate x times five sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five minus sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five minus sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared plus five sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five minus sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five minus sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared minus five sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared times five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared times five minus sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared times five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared times five minus sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared times five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared times five minus sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared times five sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared times five sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared times five sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared times five sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x squared times five sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x squared times five sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x plus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x plus five minus sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x plus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x plus five minus sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x plus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x plus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x plus five sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x plus five sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x plus five sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x plus five sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x plus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x plus five sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x minus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x minus five minus sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x minus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x minus five minus sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x minus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x minus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x minus five sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x minus five sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x minus five sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x minus five sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x minus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x minus five sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x times five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x times five minus sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x times five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x times five minus sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x times five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x times five minus sine x divided by seven x dx|input}
SolveQuestion to solve this problem {differentiate x times five sine x minus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x times five sine x minus seven x dx|input}
SolveQuestion to solve this problem {differentiate x times five sine x plus seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x times five sine x plus seven x dx|input}
SolveQuestion to solve this problem {differentiate x times five sine x divided by seven x squared dx|input}
SolveQuestion to solve this problem {differentiate x times five sine x divided by seven x dx|input}
SolveQuestion to solve this {x squared plus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this {x squared plus five minus sine x minus seven x dx|input}
SolveQuestion to solve this {x squared plus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this {x squared plus five minus sine x plus seven x dx|input}
SolveQuestion to solve this {x squared plus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x squared plus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this {x squared plus five sine x minus seven x squared dx|input}
SolveQuestion to solve this {x squared plus five sine x minus seven x dx|input}
SolveQuestion to solve this {x squared plus five sine x plus seven x squared dx|input}
SolveQuestion to solve this {x squared plus five sine x plus seven x dx|input}
SolveQuestion to solve this {x squared plus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x squared plus five sine x divided by seven x dx|input}
SolveQuestion to solve this {x squared minus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this {x squared minus five minus sine x minus seven x dx|input}
SolveQuestion to solve this {x squared minus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this {x squared minus five minus sine x plus seven x dx|input}
SolveQuestion to solve this {x squared minus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x squared minus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this {x squared minus five sine x minus seven x squared dx|input}
SolveQuestion to solve this {x squared minus five sine x minus seven x dx|input}
SolveQuestion to solve this {x squared minus five sine x plus seven x squared dx|input}
SolveQuestion to solve this {x squared minus five sine x plus seven x dx|input}
SolveQuestion to solve this {x squared minus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x squared minus five sine x divided by seven x dx|input}
SolveQuestion to solve this {x squared times five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this {x squared times five minus sine x minus seven x dx|input}
SolveQuestion to solve this {x squared times five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this {x squared times five minus sine x plus seven x dx|input}
SolveQuestion to solve this {x squared times five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x squared times five minus sine x divided by seven x dx|input}
SolveQuestion to solve this {x squared times five sine x minus seven x squared dx|input}
SolveQuestion to solve this {x squared times five sine x minus seven x dx|input}
SolveQuestion to solve this {x squared times five sine x plus seven x squared dx|input}
SolveQuestion to solve this {x squared times five sine x plus seven x dx|input}
SolveQuestion to solve this {x squared times five sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x squared times five sine x divided by seven x dx|input}
SolveQuestion to solve this {x plus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this {x plus five minus sine x minus seven x dx|input}
SolveQuestion to solve this {x plus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this {x plus five minus sine x plus seven x dx|input}
SolveQuestion to solve this {x plus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x plus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this {x plus five sine x minus seven x squared dx|input}
SolveQuestion to solve this {x plus five sine x minus seven x dx|input}
SolveQuestion to solve this {x plus five sine x plus seven x squared dx|input}
SolveQuestion to solve this {x plus five sine x plus seven x dx|input}
SolveQuestion to solve this {x plus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x plus five sine x divided by seven x dx|input}
SolveQuestion to solve this {x minus five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this {x minus five minus sine x minus seven x dx|input}
SolveQuestion to solve this {x minus five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this {x minus five minus sine x plus seven x dx|input}
SolveQuestion to solve this {x minus five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x minus five minus sine x divided by seven x dx|input}
SolveQuestion to solve this {x minus five sine x minus seven x squared dx|input}
SolveQuestion to solve this {x minus five sine x minus seven x dx|input}
SolveQuestion to solve this {x minus five sine x plus seven x squared dx|input}
SolveQuestion to solve this {x minus five sine x plus seven x dx|input}
SolveQuestion to solve this {x minus five sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x minus five sine x divided by seven x dx|input}
SolveQuestion to solve this {x times five minus sine x minus seven x squared dx|input}
SolveQuestion to solve this {x times five minus sine x minus seven x dx|input}
SolveQuestion to solve this {x times five minus sine x plus seven x squared dx|input}
SolveQuestion to solve this {x times five minus sine x plus seven x dx|input}
SolveQuestion to solve this {x times five minus sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x times five minus sine x divided by seven x dx|input}
SolveQuestion to solve this {x times five sine x minus seven x squared dx|input}
SolveQuestion to solve this {x times five sine x minus seven x dx|input}
SolveQuestion to solve this {x times five sine x plus seven x squared dx|input}
SolveQuestion to solve this {x times five sine x plus seven x dx|input}
SolveQuestion to solve this {x times five sine x divided by seven x squared dx|input}
SolveQuestion to solve this {x times five sine x divided by seven x dx|input}
```

### Calculus-Buddy

A github repository

## Credits

### Tejas Shah

2 projects • 4 followers