Secure Da Bag
Veteran
Time to shift my attention to data structures and algorithmsprepare for these technical interviews
A necessary evil.
Gotta get it
Anybody bother to study up on design patterns? Have you found it necessary at your jobs?
Time to shift my attention to data structures and algorithmsprepare for these technical interviews
A necessary evil.
Gotta get it
200 line genetic algorithm in c++. Type in a single phrase in all lower case and it tries to guess the target phrase in multiple generations. In each generation it gets better and better:
Code:#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cstdlib> #include <ctime> #include <cmath> #include <tuple> #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif namespace intelligence { const unsigned CHARCODE_BEGIN = 97 ; const unsigned CHARCODE_END = 122 ; class Chromosome { std::vector<char> _genes ; public : Chromosome(): _genes{} {} Chromosome( unsigned short geneSize ) { for( int i = 0 ; i < geneSize ; i++ ) _genes.push_back( CHARCODE_BEGIN + rand() % (CHARCODE_END-CHARCODE_BEGIN+1) ) ; } float calculateFitness( const std::string& target ) { float fitnessScore = 0.0f ; for( int i = 0 ; i < _genes.size() ; i++ ) { if( _genes[i] == target[i] ) fitnessScore++ ; } return pow( fitnessScore / target.length(), 2 ) ; //return fitnessScore / target.length() ; } Chromosome crossover( const Chromosome& other ) { Chromosome child ; std::vector<char> newGenes ; int midPoint = rand() % other.size() ; for( int i = 0 ; i < this->size() ; i++ ) { if( i > midPoint ) newGenes.push_back( other.getGene( i ) ) ; else newGenes.push_back( this->_genes[i] ) ; } child.setGenes( newGenes ) ; return child ; } void mutate( float mutationRate ) { std::replace_if( _genes.begin(), _genes.end(), [mutationRate]( char unused ) { return ( ((rand() % 100) * 0.01f) < mutationRate ) ; }, CHARCODE_BEGIN + rand() % (CHARCODE_END-CHARCODE_BEGIN+1) ) ; } void setGenes( const std::vector<char> genes ) { _genes = genes ; } std::vector<char> getGenes() const{ return _genes ; } char getGene( int idx ) const{ return _genes[idx] ; } unsigned int size() const{ return _genes.size() ; } } ; class Population { std::vector<Chromosome> _population ; unsigned short _generation ; unsigned short _mutationRate ; std::string _target ; public : Population( unsigned short popSize, const std::string target, unsigned short mutationRate ): _target(target), _mutationRate(mutationRate), _generation(0) { for( int i = 0 ; i < popSize ; i++ ) _population.push_back( Chromosome( target.length() ) ) ; } void acceptReject() { std::vector<Chromosome> newPopulation ; unsigned short maxFitness = getHighestFitnessScore() ; for( unsigned int i = 0 ; newPopulation.size() < _population.size() ; i++ ) { Chromosome parentA = _population[ rand() % _population.size() ] ; Chromosome parentB = _population[ rand() % _population.size() ] ; float randomScore = 0.01f + (rand() % maxFitness) * 0.01f ; float parentAScore = parentA.calculateFitness( _target ) ; float parentBScore = parentB.calculateFitness( _target ) ; if( (parentAScore > randomScore) && (parentBScore > randomScore) ) { Chromosome child = parentA.crossover( parentB ) ; child.mutate( _mutationRate ) ; newPopulation.push_back( child ) ; } } _population = newPopulation ; _generation++ ; } void run() { float bestScore = 0.0f ; std::cout << "Target: " << _target << '\n' ; while( bestScore < 1.0f ) { std::tuple<std::string, float> info ; info = getHighestFitness() ; bestScore = std::get<1>(info) ; std::cout << "Generation: " << _generation << "; Best Guess: " << std::get<0>(info) << "; Best Score: " << bestScore*100 << "%\n" ; acceptReject() ; } } unsigned getHighestFitnessScore() { float highest = 0.0f ; for( auto itr : _population ) { float fitnessScore = itr.calculateFitness( _target ) ; if( fitnessScore > highest ) highest = fitnessScore ; } return unsigned(highest * 100) ; } std::tuple<std::string, float> getHighestFitness() { std::vector<char> highestString ; float highestScore = 0.0f ; for( auto itr : _population ) { float fitnessScore = itr.calculateFitness( _target ) ; if( fitnessScore > highestScore ) { highestScore = fitnessScore ; highestString = itr.getGenes() ; } } std::string s( highestString.begin(), highestString.end() ) ; return std::make_tuple( s, highestScore ) ; } } ; } void printGenes( const std::vector<char>& genes ) { for( auto itr: genes ) std::cout << itr ; std::cout << '\n' ; } int main() { srand( time(NULL) ) ; std::string target ; std::cout << "Enter Target Phrase: " ; std::getline( std::cin, target ) ; intelligence::Population p( 1500, target, 0.05f ) ; p.run() ; return EXIT_SUCCESS ; }
Not really, but you should just in case. I don't do too much programming in this role, but when I do I try to use that as an opportunity to learn. I did some stuff with abstract classes and singletons the last time I wrote something. Learned about the Java Stream API and some stuff with reflections that allows the end user to specify a class with custom behaviors to be used at runtime.Anybody bother to study up on design patterns? Have you found it necessary at your jobs?
im actually going through the head first: design pattern book and also an udemy course. Im still a college studentAnybody bother to study up on design patterns? Have you found it necessary at your jobs?
Damn is the industry impenetrable?
Even this guy is having trouble
His resume:
owasim1/My-Resume
I haven't started job hunting yet. But unlike me this guy has a bachelor's degree and some experience. And even he can't find any work.
Damn is the industry impenetrable?
Even this guy is having trouble
His resume:
owasim1/My-Resume
I haven't started job hunting yet. But unlike me this guy has a bachelor's degree and some experience. And even he can't find any work.
Damn is the industry impenetrable?
Even this guy is having trouble
His resume:
owasim1/My-Resume
I haven't started job hunting yet. But unlike me this guy has a bachelor's degree and some experience. And even he can't find any work.
OK anything else?
Here are some free resources that are highly rated.So right now I’m taking an A+ course with udemy and also want to dab in some programming since I’m on temporary layoff with my company until July 2nd. I’m thinking of starting with python does any one have any suggestions on some good bootcamps or good source material to get started?
Here are 3 free, lifetime resources I've come across that are geared towards people wanting to learn Python:
RealPython is giving away 4 Python Courses
Enjoy Free Courses, On Us – Real Python
There is a free eBook version of a popular Python Udemy Course. (The eBook is rated 4.5 stars on Amazon and would cost $24). Here is a summary from Amazon.com
Automate the Boring Stuff with Python
The publisher Manning is giving away two Python books the are highly rated on Amazon.
Book #1:
Get Programming - Learn to Code With Python (4.5 stars on Amazon and currently costs $31)
Book #2:
The Quick Python Book: 3rd Edition (4.5 stars on Amazon and currently costs $46)
Damn is the industry impenetrable?
Even this guy is having trouble
His resume:
owasim1/My-Resume
I haven't started job hunting yet. But unlike me this guy has a bachelor's degree and some experience. And even he can't find any work.

I like the verbosity of Java. If people follow good practices, things are fun to read through.I like the detail you have to put in your Java code. It feels like I get to explain things better for some reason