I have noticed that there isn't a thread where you are given puzzles.

So i going to change that!

Your puzzle is to make an exacutable c++ program that outputs "hello world" 20 times (try to be exciting).

Rules:
it has to be c++
it has to work

I look forward to your answers.
:)

Recommended Answers

All 9 Replies

Is this a "clever" trick to get us to do your assignment? This should only be like 3 lines, right?

They're out there, you just need to know what to look for. Try this one on for size...

#include <iostream>

template < int N > struct S : S<N-1>
{
   S() { if( std::cout << N << ". Hello World\n" ) {} }
};

template <> struct S<0> {} ;

int main()
{
  S< sizeof("twenty Hello Worlds") >() ;
}

> Try this one on for size...

That's trivial too; reduces to computing Euler's totient function.
http://en.wikipedia.org/wiki/Euler's_totient_function

int eulers_totient_function( int number )
{
  if( number < 1 ) return 1 ;

  int totient = 1 ;

  for( int factor = 2; number != 1; ++factor )
  {
    int power = 1 ;
    while( number%factor == 0 )
    {
      number /= factor;
      power *= factor ;
    }
    totient *= ( power - (power/factor) ) ;
  }
  return totient ;
}

@yup790: Try this code, and you can hand it in as is:

#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

const char hello_world[] = {0x49,0x20,0x61,0x6D,0x20,0x61,0x20,0x63,0x68,0x65,0x61,0x74,0x65,0x72,0x21,0x00};

struct printOutFunctionObject {
  void operator () (int) {
    cout << hello_world << endl;
  };
};

struct null_iterator {
  bool operator !=(const null_iterator& iter) const { return true; };
  null_iterator operator ++() { return *this; };  
  int operator *() { return 0; };
};

int main() {
  for_each(null_iterator(),null_iterator(),printOutFunctionObject());
  return 0;
};

Muhahahahahaa

#include <iostream> 
using namespace std;
#define SAY std::cout <<  
#define startProg int main(){ int i = 0;
#define endProg return 0;}
#define FOR(MAX) for(i = 0; i != MAX; ++i){
#define ENDFOR }

startProg
 FOR(20)
	 SAY "hello world\n";
 ENDFOR
endProg

Hey i think you got the wrong idea!

This isn't for an assignment, Its a fun puzzle incase you lot are board.

Is this a "clever" trick to get us to do your assignment? This should only be like 3 lines, right?

No. It's so you can have fun

No. It's so you can have fun

Well, if you look at our posts, we have been having fun with this.

I think the problem got turned into: What is the most weird, convoluted and elaborate way to simply print "Hello World!" 20 times?

>>I think the problem got turned into: What is the most weird, convoluted and elaborate way to simply print "Hello World!" 20 times?

Thats how I have fun :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.