Sha256: 868418679502ad1031cf62d5b4775b08382b654052188dd1f5e7f317a1c1b520

Contents?: true

Size: 638 Bytes

Versions: 396

Compression:

Stored size: 638 Bytes

Contents

#include "series.h"
#include <stdexcept>

using namespace std;

namespace series
{

vector<int> digits(string const& sequence)
{
    vector<int> result;
    for (const char digit : sequence) {
        result.push_back(digit - '0');
    }
    return result;
}

vector<vector<int>> slice(string const& sequence, int span)
{
    if (span > static_cast<int>(sequence.length())) {
        throw domain_error("Requested span too long for sequence");
    }
    vector<vector<int>> result;
    for (size_t i = 0; i < sequence.length() - (span - 1); ++i) {
        result.push_back(digits(sequence.substr(i, span)));
    }
    return result;
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.179 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.178 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.177 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.176 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.175 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.174 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.173 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.172 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.171 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.170 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.169 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.167 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.166 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.165 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.164 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.163 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.162 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.161 tracks/cpp/exercises/series/example.cpp
trackler-2.2.1.160 tracks/cpp/exercises/series/example.cpp