Posts: 5356
Threads: 178
Joined: June 28, 2015
Reputation:
35
RE: Here's a simple programming problem for you to solve
April 27, 2016 at 4:37 am
(April 27, 2016 at 4:35 am)Alex K Wrote: (April 27, 2016 at 2:17 am)pool the great Wrote: I can't C your response,Tibby.
Of course not, in Python it's basically
"
begin program
dothethingIwant();
end program
"

Lol!! So I guess python has a function for everything? That's no fun!
Posts: 15352
Threads: 119
Joined: January 13, 2014
Reputation:
116
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 4:48 am
(This post was last modified: April 28, 2016 at 4:53 am by SteelCurtain.)
Code: // *********************Pool's Homework****************
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//initialize variables
string str;
int integ, len, iter, count;
//get the string and the length of output
cout << "Input the string: " << endl;
cin >> str;
cout << "Input an integer: " << endl;
cin >> integ;
iter = 1; //iterator for exponent
count = 0; //iterator for number of combinations
len = str.length(); // how many letters
const int COMB = pow(len, integ); //number of combinations
string solutions[COMB]; //an array of strings to concatenate the solutions into
for (int i = 0; i < integ; i++)
{
while (count <= COMB-1)
{
for(int j = 0; j < len; j++) //ab
{
for(int k = 0; k < pow(len,(integ-iter)); k++)
{
solutions[count] += str[j];
count++;
}
}
}
iter++;
count = 0;
}
//print solutions
cout << endl << endl << "There are " << COMB << " string combinations." << endl;
cout << "String Combinations:" << endl;
for (int i = 0; i < COMB; i++)
cout << solutions[i] << endl;
return 0;
}
You're welcome. You can PayPal me the $2k we agreed upon.
http://cpp.sh/2vh7d
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Posts: 31840
Threads: 205
Joined: July 19, 2011
Reputation:
141
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 7:33 am
That, sir, is not C.
Posts: 18544
Threads: 131
Joined: January 19, 2014
Reputation:
90
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 7:39 am
But very nearly
The fool hath said in his heart, There is a God. They are corrupt, they have done abominable works, there is none that doeth good.
Psalm 14, KJV revised edition
Posts: 9147
Threads: 83
Joined: May 22, 2013
Reputation:
45
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 7:47 am
(This post was last modified: April 28, 2016 at 8:02 am by bennyboy.)
My contribution. I can't be bothered with pure c either, but I wanted to show pool some recursion:
Code: // ********************* If you're gonna cheat, might as well go for 25 points! ****************
#include <iostream>
#include <string>
using namespace std;
string str;
int digits;
int counter = 0;
// The following appends a series of single characters to whatever comes in-- originally an empty string; so each call will add a new digit //
void printStrings(string curStr, int curDigit){
for (int i = 0; i < str.length(); i++){
string newStr = curStr + str[i];
if (curDigit < digits -1) printStrings (newStr, curDigit +1); // If we aren't on the last digit, keep recursing (i.e. add another digit) //
else { // If we ARE on the last digit, we can just go ahead and print each string //
counter++;
cout << endl << newStr;
}
}
}
int main()
{
cout << "Input some unique characters: " ;
cin >> str ;
cout << "Max length: ";
cin >> digits ;
cout << endl << "Created following strings:" << endl;
printStrings("", 0); // Starts the recursive routine here
cout << endl << endl << "(" << counter << " total)";
return 0;
}
http://cpp.sh/5lfu
PS It's the one time I'm proud to say: SteelCurtain, mine's smaller than yours!
Posts: 15352
Threads: 119
Joined: January 13, 2014
Reputation:
116
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 7:56 am
He can figure it out. The algorithm is there.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Posts: 15352
Threads: 119
Joined: January 13, 2014
Reputation:
116
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 8:01 am
(April 28, 2016 at 7:47 am)bennyboy Wrote: PS It's the one time I'm proud to say: SteelCurtain, mine's smaller than yours! 
Bastard!
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Posts: 5356
Threads: 178
Joined: June 28, 2015
Reputation:
35
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 8:31 am
Let's see if what you sissies posted works *cracks knuckles*
Posts: 31840
Threads: 205
Joined: July 19, 2011
Reputation:
141
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 8:35 am
Let's see if pool can solve the problem in Brainfuck.
Posts: 5356
Threads: 178
Joined: June 28, 2015
Reputation:
35
RE: Here's a simple programming problem for you to solve
April 28, 2016 at 9:14 am
(April 28, 2016 at 4:48 am)SteelCurtain Wrote: Code: // *********************Pool's Homework****************
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//initialize variables
string str;
int integ, len, iter, count;
//get the string and the length of output
cout << "Input the string: " << endl;
cin >> str;
cout << "Input an integer: " << endl;
cin >> integ;
iter = 1; //iterator for exponent
count = 0; //iterator for number of combinations
len = str.length(); // how many letters
const int COMB = pow(len, integ); //number of combinations
string solutions[COMB]; //an array of strings to concatenate the solutions into
for (int i = 0; i < integ; i++)
{
while (count <= COMB-1)
{
for(int j = 0; j < len; j++) //ab
{
for(int k = 0; k < pow(len,(integ-iter)); k++)
{
solutions[count] += str[j];
count++;
}
}
}
iter++;
count = 0;
}
//print solutions
cout << endl << endl << "There are " << COMB << " string combinations." << endl;
cout << "String Combinations:" << endl;
for (int i = 0; i < COMB; i++)
cout << solutions[i] << endl;
return 0;
}
You're welcome. You can PayPal me the $2k we agreed upon.
http://cpp.sh/2vh7d
I give thumbs down for SC.
My input: AB
My input: 2
Output:
AA
BB
AB
AB
|