kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Words containing _the_ substring
C++: #include <iostream>
#include <fstream>

int main() {
    std::string word;
    std::ifstream file("unixdict.txt");
 
    if (!file) {
        std::cerr << "Cannot open unixdict.txt" << std::endl;
        return -1;
    }
    while (file >> word) {
        if (word.length() > 11 && word.find("the") != std::string::npos)
            std::cout << word << std::endl;
    }
    return 0;
}

VB: Sub Main_Contain()
Dim ListeWords() As String, Book As String, i As Long, out() As String, count As Integer
    Book = Read_File("C:\Users\" & Environ("Username") & "\Desktop\unixdict.txt")
    ListeWords = Split(Book, vbNewLine)
    For i = LBound(ListeWords) To UBound(ListeWords)
        If Len(ListeWords(i)) > 11 Then
            If InStr(ListeWords(i), "the") > 0 Then
                ReDim Preserve out(count)
                out(count) = ListeWords(i)
                count = count + 1
            End If
        End If
    Next
    Debug.Print "Found : " & count & " words : " & Join(out, ", ")
End Sub
Private Function Read_File(Fic As String) As String
Dim Nb As Integer
    Nb = FreeFile
    Open Fic For Input As #Nb
        Read_File = Input(LOF(Nb), #Nb)
    Close #Nb
End Function
Task: Words containing _the_ substring
Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
    "strings"
    "unicode/utf8"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    var words []string
    for _, bword := range bwords {
        s := string(bword)
        if utf8.RuneCountInString(s) > 11 {
            words = append(words, s)
        }
    }
    count := 0
    fmt.Println("Words containing 'the' having a length > 11 in", wordList, "\b:")
    for _, word := range words {
        if strings.Contains(word, "the") {
            count++
            fmt.Printf("%2d: %s\n", count, word)
        }
    }
}

Python: import urllib.request as request

with request.urlopen("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") as f:
    a = f.read().decode("ASCII").split()

for s in a:
    if len(s) > 11 and "the" in s:
        print(s)
Task: Words containing _the_ substring
Python: import urllib.request as request

with request.urlopen("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") as f:
    a = f.read().decode("ASCII").split()

for s in a:
    if len(s) > 11 and "the" in s:
        print(s)

VB: Sub Main_Contain()
Dim ListeWords() As String, Book As String, i As Long, out() As String, count As Integer
    Book = Read_File("C:\Users\" & Environ("Username") & "\Desktop\unixdict.txt")
    ListeWords = Split(Book, vbNewLine)
    For i = LBound(ListeWords) To UBound(ListeWords)
        If Len(ListeWords(i)) > 11 Then
            If InStr(ListeWords(i), "the") > 0 Then
                ReDim Preserve out(count)
                out(count) = ListeWords(i)
                count = count + 1
            End If
        End If
    Next
    Debug.Print "Found : " & count & " words : " & Join(out, ", ")
End Sub
Private Function Read_File(Fic As String) As String
Dim Nb As Integer
    Nb = FreeFile
    Open Fic For Input As #Nb
        Read_File = Input(LOF(Nb), #Nb)
    Close #Nb
End Function
Task: Words containing _the_ substring
C: #include <stdio.h>
#include <string.h>

int main() {
    char word[128];
    FILE *f = fopen("unixdict.txt","r");
    if (!f) {
        fprintf(stderr, "Cannot open unixdict.txt\n");
        return -1;
    }
    while (!feof(f)) {
        fgets(word, sizeof(word), f);
        
        
        if (strlen(word) > 12 && strstr(word,"the"))
            printf("%s",word);
    }
    fclose(f);
    return 0;
}

C++: #include <iostream>
#include <fstream>

int main() {
    std::string word;
    std::ifstream file("unixdict.txt");
 
    if (!file) {
        std::cerr << "Cannot open unixdict.txt" << std::endl;
        return -1;
    }
    while (file >> word) {
        if (word.length() > 11 && word.find("the") != std::string::npos)
            std::cout << word << std::endl;
    }
    return 0;
}
Task: Words containing _the_ substring
C: #include <stdio.h>
#include <string.h>

int main() {
    char word[128];
    FILE *f = fopen("unixdict.txt","r");
    if (!f) {
        fprintf(stderr, "Cannot open unixdict.txt\n");
        return -1;
    }
    while (!feof(f)) {
        fgets(word, sizeof(word), f);
        
        
        if (strlen(word) > 12 && strstr(word,"the"))
            printf("%s",word);
    }
    fclose(f);
    return 0;
}

Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
    "strings"
    "unicode/utf8"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    var words []string
    for _, bword := range bwords {
        s := string(bword)
        if utf8.RuneCountInString(s) > 11 {
            words = append(words, s)
        }
    }
    count := 0
    fmt.Println("Words containing 'the' having a length > 11 in", wordList, "\b:")
    for _, word := range words {
        if strings.Contains(word, "the") {
            count++
            fmt.Printf("%2d: %s\n", count, word)
        }
    }
}
Task: Words containing _the_ substring
C++: #include <iostream>
#include <fstream>

int main() {
    std::string word;
    std::ifstream file("unixdict.txt");
 
    if (!file) {
        std::cerr << "Cannot open unixdict.txt" << std::endl;
        return -1;
    }
    while (file >> word) {
        if (word.length() > 11 && word.find("the") != std::string::npos)
            std::cout << word << std::endl;
    }
    return 0;
}

Python: import urllib.request as request

with request.urlopen("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") as f:
    a = f.read().decode("ASCII").split()

for s in a:
    if len(s) > 11 and "the" in s:
        print(s)
Task: Words containing _the_ substring
Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
    "strings"
    "unicode/utf8"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    var words []string
    for _, bword := range bwords {
        s := string(bword)
        if utf8.RuneCountInString(s) > 11 {
            words = append(words, s)
        }
    }
    count := 0
    fmt.Println("Words containing 'the' having a length > 11 in", wordList, "\b:")
    for _, word := range words {
        if strings.Contains(word, "the") {
            count++
            fmt.Printf("%2d: %s\n", count, word)
        }
    }
}

VB: Sub Main_Contain()
Dim ListeWords() As String, Book As String, i As Long, out() As String, count As Integer
    Book = Read_File("C:\Users\" & Environ("Username") & "\Desktop\unixdict.txt")
    ListeWords = Split(Book, vbNewLine)
    For i = LBound(ListeWords) To UBound(ListeWords)
        If Len(ListeWords(i)) > 11 Then
            If InStr(ListeWords(i), "the") > 0 Then
                ReDim Preserve out(count)
                out(count) = ListeWords(i)
                count = count + 1
            End If
        End If
    Next
    Debug.Print "Found : " & count & " words : " & Join(out, ", ")
End Sub
Private Function Read_File(Fic As String) As String
Dim Nb As Integer
    Nb = FreeFile
    Open Fic For Input As #Nb
        Read_File = Input(LOF(Nb), #Nb)
    Close #Nb
End Function
Task: Words containing _the_ substring
C: #include <stdio.h>
#include <string.h>

int main() {
    char word[128];
    FILE *f = fopen("unixdict.txt","r");
    if (!f) {
        fprintf(stderr, "Cannot open unixdict.txt\n");
        return -1;
    }
    while (!feof(f)) {
        fgets(word, sizeof(word), f);
        
        
        if (strlen(word) > 12 && strstr(word,"the"))
            printf("%s",word);
    }
    fclose(f);
    return 0;
}

PHP: <?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";
Task: Words containing _the_ substring
C++: #include <iostream>
#include <fstream>

int main() {
    std::string word;
    std::ifstream file("unixdict.txt");
 
    if (!file) {
        std::cerr << "Cannot open unixdict.txt" << std::endl;
        return -1;
    }
    while (file >> word) {
        if (word.length() > 11 && word.find("the") != std::string::npos)
            std::cout << word << std::endl;
    }
    return 0;
}

PHP: <?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";
Task: Words containing _the_ substring
Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
    "strings"
    "unicode/utf8"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    var words []string
    for _, bword := range bwords {
        s := string(bword)
        if utf8.RuneCountInString(s) > 11 {
            words = append(words, s)
        }
    }
    count := 0
    fmt.Println("Words containing 'the' having a length > 11 in", wordList, "\b:")
    for _, word := range words {
        if strings.Contains(word, "the") {
            count++
            fmt.Printf("%2d: %s\n", count, word)
        }
    }
}

PHP: <?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";
Task: Words containing _the_ substring
Python: import urllib.request as request

with request.urlopen("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt") as f:
    a = f.read().decode("ASCII").split()

for s in a:
    if len(s) > 11 and "the" in s:
        print(s)

PHP: <?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";
Task: Words containing _the_ substring
VB: Sub Main_Contain()
Dim ListeWords() As String, Book As String, i As Long, out() As String, count As Integer
    Book = Read_File("C:\Users\" & Environ("Username") & "\Desktop\unixdict.txt")
    ListeWords = Split(Book, vbNewLine)
    For i = LBound(ListeWords) To UBound(ListeWords)
        If Len(ListeWords(i)) > 11 Then
            If InStr(ListeWords(i), "the") > 0 Then
                ReDim Preserve out(count)
                out(count) = ListeWords(i)
                count = count + 1
            End If
        End If
    Next
    Debug.Print "Found : " & count & " words : " & Join(out, ", ")
End Sub
Private Function Read_File(Fic As String) As String
Dim Nb As Integer
    Nb = FreeFile
    Open Fic For Input As #Nb
        Read_File = Input(LOF(Nb), #Nb)
    Close #Nb
End Function

PHP: <?php foreach(file("unixdict.txt") as $w) echo (strstr($w, "the") && strlen(trim($w)) > 11) ? $w : "";
Task: Chebyshev coefficients
C: #include <stdio.h>
#include <string.h>
#include <math.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

double test_func(double x)
{
	
	return cos(x);
}


double map(double x, double min_x, double max_x, double min_to, double max_to)
{
	return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to;
}

void cheb_coef(double (*func)(double), int n, double min, double max, double *coef)
{
	memset(coef, 0, sizeof(double) * n);
	for (int i = 0; i < n; i++) {
		double f = func(map(cos(M_PI*(i + .5f)/n), -1, 1, min, max))*2/n;
		for (int j = 0; j < n; j++)
			coef[j] += f*cos(M_PI*j*(i + .5f)/n);
	}
}



double cheb_approx(double x, int n, double min, double max, double *coef)
{
	double a = 1, b = map(x, min, max, -1, 1), c;
	double res = coef[0]/2 + coef[1]*b;

	x = 2*b;
	for (int i = 2; i < n; a = b, b = c, i++)
		
		res += coef[i]*(c = x*b - a);

	return res;
}

int main(void)
{
#define N 10
	double c[N], min = 0, max = 1;
	cheb_coef(test_func, N, min, max, c);

	printf("Coefficients:");
	for (int i = 0; i < N; i++)
		printf(" %lg", c[i]);

	puts("\n\nApproximation:\n   x           func(x)     approx      diff");
	for (int i = 0; i <= 20; i++) {
		double x = map(i, 0, 20, min, max);
		double f = test_func(x);
		double approx = cheb_approx(x, N, min, max, c);

		printf("% 10.8lf % 10.8lf % 10.8lf % 4.1le\n",
			x, f, approx, approx - f);
	}

	return 0;
}

Go: package main

import (
    "fmt"
    "math"
)

type cheb struct {
    c        []float64
    min, max float64
}

func main() {
    fn := math.Cos
    c := newCheb(0, 1, 10, 10, fn)
    fmt.Println("coefficients:")
    for _, c := range c.c {
        fmt.Printf("% .15f\n", c)
    }
    fmt.Println("\nx     computed    approximated    computed-approx")
    const n = 10
    for i := 0.; i <= n; i++ {
        x := (c.min*(n-i) + c.max*i) / n
        computed := fn(x)
        approx := c.eval(x)
        fmt.Printf("%.1f %12.8f  %12.8f   % .3e\n",
            x, computed, approx, computed-approx)
    }
}

func newCheb(min, max float64, nCoeff, nNodes int, fn func(float64) float64) *cheb {
    c := &cheb{
        c:   make([]float64, nCoeff),
        min: min,
        max: max,
    }
    f := make([]float64, nNodes)
    p := make([]float64, nNodes)
    z := .5 * (max + min)
    r := .5 * (max - min)
    for k := 0; k < nNodes; k++ {
        p[k] = math.Pi * (float64(k) + .5) / float64(nNodes)
        f[k] = fn(z + math.Cos(p[k])*r)
    }
    n2 := 2 / float64(nNodes)
    for j := 0; j < nCoeff; j++ {
        sum := 0.
        for k := 0; k < nNodes; k++ {
            sum += f[k] * math.Cos(float64(j)*p[k])
        }
        c.c[j] = sum * n2
    }
    return c
}

func (c *cheb) eval(x float64) float64 {
    x1 := (2*x - c.min - c.max) / (c.max - c.min)
    x2 := 2 * x1
    var s, t float64
    for j := len(c.c) - 1; j >= 1; j-- {
        t, s = x2*t-s+c.c[j], t
    }
    return x1*t - s + .5*c.c[0]
}
Task: Chebyshev coefficients
C: #include <stdio.h>
#include <string.h>
#include <math.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

double test_func(double x)
{
	
	return cos(x);
}


double map(double x, double min_x, double max_x, double min_to, double max_to)
{
	return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to;
}

void cheb_coef(double (*func)(double), int n, double min, double max, double *coef)
{
	memset(coef, 0, sizeof(double) * n);
	for (int i = 0; i < n; i++) {
		double f = func(map(cos(M_PI*(i + .5f)/n), -1, 1, min, max))*2/n;
		for (int j = 0; j < n; j++)
			coef[j] += f*cos(M_PI*j*(i + .5f)/n);
	}
}



double cheb_approx(double x, int n, double min, double max, double *coef)
{
	double a = 1, b = map(x, min, max, -1, 1), c;
	double res = coef[0]/2 + coef[1]*b;

	x = 2*b;
	for (int i = 2; i < n; a = b, b = c, i++)
		
		res += coef[i]*(c = x*b - a);

	return res;
}

int main(void)
{
#define N 10
	double c[N], min = 0, max = 1;
	cheb_coef(test_func, N, min, max, c);

	printf("Coefficients:");
	for (int i = 0; i < N; i++)
		printf(" %lg", c[i]);

	puts("\n\nApproximation:\n   x           func(x)     approx      diff");
	for (int i = 0; i <= 20; i++) {
		double x = map(i, 0, 20, min, max);
		double f = test_func(x);
		double approx = cheb_approx(x, N, min, max, c);

		printf("% 10.8lf % 10.8lf % 10.8lf % 4.1le\n",
			x, f, approx, approx - f);
	}

	return 0;
}

Java: import static java.lang.Math.*;
import java.util.function.Function;

public class ChebyshevCoefficients {

    static double map(double x, double min_x, double max_x, double min_to,
            double max_to) {
        return (x - min_x) / (max_x - min_x) * (max_to - min_to) + min_to;
    }

    static void chebyshevCoef(Function<Double, Double> func, double min,
            double max, double[] coef) {

        int N = coef.length;

        for (int i = 0; i < N; i++) {

            double m = map(cos(PI * (i + 0.5f) / N), -1, 1, min, max);
            double f = func.apply(m) * 2 / N;

            for (int j = 0; j < N; j++) {
                coef[j] += f * cos(PI * j * (i + 0.5f) / N);
            }
        }
    }

    public static void main(String[] args) {
        final int N = 10;
        double[] c = new double[N];
        double min = 0, max = 1;
        chebyshevCoef(x -> cos(x), min, max, c);

        System.out.println("Coefficients:");
        for (double d : c)
            System.out.println(d);
    }
}
Task: Chebyshev coefficients
C: #include <stdio.h>
#include <string.h>
#include <math.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

double test_func(double x)
{
	
	return cos(x);
}


double map(double x, double min_x, double max_x, double min_to, double max_to)
{
	return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to;
}

void cheb_coef(double (*func)(double), int n, double min, double max, double *coef)
{
	memset(coef, 0, sizeof(double) * n);
	for (int i = 0; i < n; i++) {
		double f = func(map(cos(M_PI*(i + .5f)/n), -1, 1, min, max))*2/n;
		for (int j = 0; j < n; j++)
			coef[j] += f*cos(M_PI*j*(i + .5f)/n);
	}
}



double cheb_approx(double x, int n, double min, double max, double *coef)
{
	double a = 1, b = map(x, min, max, -1, 1), c;
	double res = coef[0]/2 + coef[1]*b;

	x = 2*b;
	for (int i = 2; i < n; a = b, b = c, i++)
		
		res += coef[i]*(c = x*b - a);

	return res;
}

int main(void)
{
#define N 10
	double c[N], min = 0, max = 1;
	cheb_coef(test_func, N, min, max, c);

	printf("Coefficients:");
	for (int i = 0; i < N; i++)
		printf(" %lg", c[i]);

	puts("\n\nApproximation:\n   x           func(x)     approx      diff");
	for (int i = 0; i <= 20; i++) {
		double x = map(i, 0, 20, min, max);
		double f = test_func(x);
		double approx = cheb_approx(x, N, min, max, c);

		printf("% 10.8lf % 10.8lf % 10.8lf % 4.1le\n",
			x, f, approx, approx - f);
	}

	return 0;
}

Python: import math

def test_func(x):
    return math.cos(x)

def mapper(x, min_x, max_x, min_to, max_to):
    return (x - min_x) / (max_x - min_x) * (max_to - min_to) + min_to

def cheb_coef(func, n, min, max):
    coef = [0.0] * n
    for i in xrange(n):
        f = func(mapper(math.cos(math.pi * (i + 0.5) / n), -1, 1, min, max)) * 2 / n
        for j in xrange(n):
            coef[j] += f * math.cos(math.pi * j * (i + 0.5) / n)
    return coef

def cheb_approx(x, n, min, max, coef):
    a = 1
    b = mapper(x, min, max, -1, 1)
    c = float('nan')
    res = coef[0] / 2 + coef[1] * b

    x = 2 * b
    i = 2
    while i < n:
        c = x * b - a
        res = res + coef[i] * c
        (a, b) = (b, c)
        i += 1

    return res

def main():
    N = 10
    min = 0
    max = 1
    c = cheb_coef(test_func, N, min, max)

    print "Coefficients:"
    for i in xrange(N):
        print " % lg" % c[i]

    print "\n\nApproximation:\n    x      func(x)       approx      diff"
    for i in xrange(20):
        x = mapper(i, 0.0, 20.0, min, max)
        f = test_func(x)
        approx = cheb_approx(x, N, min, max, c)
        print "%1.3f %10.10f %10.10f % 4.2e" % (x, f, approx, approx - f)

    return None

main()
Task: Chebyshev coefficients
C: #include <stdio.h>
#include <string.h>
#include <math.h>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

double test_func(double x)
{
	
	return cos(x);
}


double map(double x, double min_x, double max_x, double min_to, double max_to)
{
	return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to;
}

void cheb_coef(double (*func)(double), int n, double min, double max, double *coef)
{
	memset(coef, 0, sizeof(double) * n);
	for (int i = 0; i < n; i++) {
		double f = func(map(cos(M_PI*(i + .5f)/n), -1, 1, min, max))*2/n;
		for (int j = 0; j < n; j++)
			coef[j] += f*cos(M_PI*j*(i + .5f)/n);
	}
}



double cheb_approx(double x, int n, double min, double max, double *coef)
{
	double a = 1, b = map(x, min, max, -1, 1), c;
	double res = coef[0]/2 + coef[1]*b;

	x = 2*b;
	for (int i = 2; i < n; a = b, b = c, i++)
		
		res += coef[i]*(c = x*b - a);

	return res;
}

int main(void)
{
#define N 10
	double c[N], min = 0, max = 1;
	cheb_coef(test_func, N, min, max, c);

	printf("Coefficients:");
	for (int i = 0; i < N; i++)
		printf(" %lg", c[i]);

	puts("\n\nApproximation:\n   x           func(x)     approx      diff");
	for (int i = 0; i <= 20; i++) {
		double x = map(i, 0, 20, min, max);
		double f = test_func(x);
		double approx = cheb_approx(x, N, min, max, c);

		printf("% 10.8lf % 10.8lf % 10.8lf % 4.1le\n",
			x, f, approx, approx - f);
	}

	return 0;
}

VB: 
  Dim coef(10),cheby(10)
  pi=4*Atn(1)
  a=0: b=1: n=10
  For i=0 To n-1
    coef(i)=Cos(Cos(pi/n*(i+1/2))*(b-a)/2+(b+a)/2)
  Next
  For i=0 To n-1
    w=0
    For j=0 To n-1
      w=w+coef(j)*Cos(pi/n*i*(j+1/2))
    Next
    cheby(i)=w*2/n
    If cheby(i)<=0 Then t="" Else t=" "
    WScript.StdOut.WriteLine i&" : "&t&cheby(i)
  Next
Task: Chebyshev coefficients
C++: #include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <utility>
#include <vector>

using namespace std;

static const double PI = acos(-1.0);

double affine_remap(const pair<double, double>& from, double x, const pair<double, double>& to)
{
	return to.first + (x - from.first) * (to.second - to.first) / (from.second - from.first);
}

vector<double> cheb_coef(const vector<double>& f_vals)
{
	const int n = f_vals.size();
	const double theta = PI / n;
	vector<double> retval(n, 0.0);
	for (int ii = 0; ii < n; ++ii)
	{
		double f = f_vals[ii] * 2.0 / n;
		const double phi = (ii + 0.5) * theta;
		double c1 = cos(phi), s1 = sin(phi);
		double c = 1.0, s = 0.0;
		for (int j = 0; j < n; j++)
		{
			retval[j] += f * c;
			
			const double cNext = c * c1 - s * s1;
			s = c * s1 + s * c1;
			c = cNext;
		}
	}
	return retval;
}

template<class F_> vector<double> cheb_coef(const F_& func, int n, const pair<double, double>& domain)
{
	auto remap = [&](double x){return affine_remap({ -1.0, 1.0 }, x, domain); };
	const double theta = PI / n;
	vector<double> fVals(n);
	for (int ii = 0; ii < n; ++ii)
		fVals[ii] = func(remap(cos((ii + 0.5) * theta)));
	return cheb_coef(fVals);
}

double cheb_eval(const vector<double>& coef, double x)
{
	double a = 1.0, b = x, c;
	double retval = 0.5 * coef[0] + b * coef[1];
	for (auto pc = coef.begin() + 2; pc != coef.end(); a = b, b = c, ++pc)
	{
		c = 2.0 * b * x - a;
		retval += (*pc) * c;
	}
	return retval;
}
double cheb_eval(const vector<double>& coef, const pair<double, double>& domain, double x)
{
	return cheb_eval(coef, affine_remap(domain, x, { -1.0, 1.0 }));
}

struct ChebyshevApprox_
{
	vector<double> coeffs_;
	pair<double, double> domain_;

	double operator()(double x) const { return cheb_eval(coeffs_, domain_, x); }

	template<class F_> ChebyshevApprox_
		(const F_& func,
		int n,
		const pair<double, double>& domain)
		:
		coeffs_(cheb_coef(func, n, domain)),
		domain_(domain)
	{ }
};


int main(void)
{
	static const int N = 10;
	ChebyshevApprox_ fApprox(cos, N, { 0.0, 1.0 });
	cout << "Coefficients: " << setprecision(14);
	for (const auto& c : fApprox.coeffs_)
		cout << "\t" << c << "\n";

	for (;;)
	{
		cout << "Enter x, or non-numeric value to quit:\n";
		double x;
		if (!(cin >> x))
			return 0;
		cout << "True value: \t" << cos(x) << "\n";
		cout << "Approximate: \t" << fApprox(x) << "\n";
	}
}

VB: 
  Dim coef(10),cheby(10)
  pi=4*Atn(1)
  a=0: b=1: n=10
  For i=0 To n-1
    coef(i)=Cos(Cos(pi/n*(i+1/2))*(b-a)/2+(b+a)/2)
  Next
  For i=0 To n-1
    w=0
    For j=0 To n-1
      w=w+coef(j)*Cos(pi/n*i*(j+1/2))
    Next
    cheby(i)=w*2/n
    If cheby(i)<=0 Then t="" Else t=" "
    WScript.StdOut.WriteLine i&" : "&t&cheby(i)
  Next