Skip to content

Instantly share code, notes, and snippets.

@orbitcowboy
Created September 27, 2012 19:54
Show Gist options
  • Save orbitcowboy/3796111 to your computer and use it in GitHub Desktop.
Save orbitcowboy/3796111 to your computer and use it in GitHub Desktop.
C++ Version of OEIS sequence A216983
#include <iostream>
#include <string>
// ------------------------------------------------------------------
/// Generate and print the sequence A216983 to a std::string.
/// Weblink: http://oeis.org/A216983
//
// Usage:
// ------
// unsigned int uiMax(88);
// std::cout << PrintSequnce_A216983(uiMax)) << std::endl;
//
// Output:
// -------
// $ 7, 1, 2, 3, 2, 5, 3, 7, 2, 3, 5, 1, 3, 1, 7, 5, 2, 1, 3, 1, 5,
// 7, 2, 1, 3, 5, 2, 3, 7, 1, 5, 1, 2, 3, 2, 7, 3, 1, 2, 3, 5, 1,
// 7, 1, 2, 5, 2, 1, 3, 7, 5, 3, 2, 1, 3, 5, 7, 3, 2, 1, 5, 1, 2,
// 7, 2, 5, 3, 1, 2, 3, 7, 1, 3, 1, 2, 5, 2, 7, 3, 1, 5, 3, 2, 1,
// 7, 5, 2
//
// -------------------------------------------------------------------
// Tested with gcc-4.6.3, clang-3.1 on Ubuntu Linux (64Bit)
//
// @author Martin Ettl
// @date 2012-09-27
// -------------------------------------------------------------------
/// @param max -> sequence stop at max
//
/// @return <-- the sequence as string
// -------------------------------------------------------------------
template <typename T> std::string PrintSequnce_A216983(const T &max)
{
std::string strSeq;
for(T i = 1; i < max; ++i)
{
if (i%7==1) strSeq+="7";
else if (i%5==1) strSeq+="5";
else if (i%3==1) strSeq+="3";
else if (i%2==1) strSeq+="2";
else strSeq+="1";
if(i<max-1)
strSeq+=", ";
}
return strSeq;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment