Task: Eban numbers



C#: using System;

namespace EbanNumbers {
    struct Interval {
        public int start, end;
        public bool print;

        public Interval(int start, int end, bool print) {
            this.start = start;
            this.end = end;
            this.print = print;
        }
    }

    class Program {
        static void Main() {
            Interval[] intervals = {
                new Interval(2, 1_000, true),
                new Interval(1_000, 4_000, true),
                new Interval(2, 10_000, false),
                new Interval(2, 100_000, false),
                new Interval(2, 1_000_000, false),
                new Interval(2, 10_000_000, false),
                new Interval(2, 100_000_000, false),
                new Interval(2, 1_000_000_000, false),
            };
            foreach (var intv in intervals) {
                if (intv.start == 2) {
                    Console.WriteLine("eban numbers up to and including {0}:", intv.end);
                } else {
                    Console.WriteLine("eban numbers between {0} and {1} (inclusive):", intv.start, intv.end);
                }

                int count = 0;
                for (int i = intv.start; i <= intv.end; i += 2) {
                    int b = i / 1_000_000_000;
                    int r = i % 1_000_000_000;
                    int m = r / 1_000_000;
                    r = i % 1_000_000;
                    int t = r / 1_000;
                    r %= 1_000;
                    if (m >= 30 && m <= 66) m %= 10;
                    if (t >= 30 && t <= 66) t %= 10;
                    if (r >= 30 && r <= 66) r %= 10;
                    if (b == 0 || b == 2 || b == 4 || b == 6) {
                        if (m == 0 || m == 2 || m == 4 || m == 6) {
                            if (t == 0 || t == 2 || t == 4 || t == 6) {
                                if (r == 0 || r == 2 || r == 4 || r == 6) {
                                    if (intv.print) Console.Write("{0} ", i);
                                    count++;
                                }
                            }
                        }
                    }
                }
                if (intv.print) {
                    Console.WriteLine();
                }
                Console.WriteLine("count = {0}\n", count);
            }
        }
    }
}






VB: Module Module1

    Structure Interval
        Dim start As Integer
        Dim last As Integer
        Dim print As Boolean

        Sub New(s As Integer, l As Integer, p As Boolean)
            start = s
            last = l
            print = p
        End Sub
    End Structure

    Sub Main()
        Dim intervals As Interval() = {
            New Interval(2, 1_000, True),
            New Interval(1_000, 4_000, True),
            New Interval(2, 10_000, False),
            New Interval(2, 100_000, False),
            New Interval(2, 1_000_000, False),
            New Interval(2, 10_000_000, False),
            New Interval(2, 100_000_000, False),
            New Interval(2, 1_000_000_000, False)
        }
        For Each intv In intervals
            If intv.start = 2 Then
                Console.WriteLine("eban numbers up to and including {0}:", intv.last)
            Else
                Console.WriteLine("eban numbers between {0} and {1} (inclusive):", intv.start, intv.last)
            End If

            Dim count = 0
            For i = intv.start To intv.last Step 2
                Dim b = i \ 1_000_000_000
                Dim r = i Mod 1_000_000_000
                Dim m = r \ 1_000_000
                r = i Mod 1_000_000
                Dim t = r \ 1_000
                r = r Mod 1_000
                If m >= 30 AndAlso m <= 66 Then
                    m = m Mod 10
                End If
                If t >= 30 AndAlso t <= 66 Then
                    t = t Mod 10
                End If
                If r >= 30 AndAlso r <= 66 Then
                    r = r Mod 10
                End If
                If b = 0 OrElse b = 2 OrElse b = 4 OrElse b = 6 Then
                    If m = 0 OrElse m = 2 OrElse m = 4 OrElse m = 6 Then
                        If t = 0 OrElse t = 2 OrElse t = 4 OrElse t = 6 Then
                            If r = 0 OrElse r = 2 OrElse r = 4 OrElse r = 6 Then
                                If intv.print Then
                                    Console.Write("{0} ", i)
                                End If
                                count += 1
                            End If
                        End If
                    End If
                End If
            Next
            If intv.print Then
                Console.WriteLine()
            End If
            Console.WriteLine("count = {0}", count)
            Console.WriteLine()
        Next
    End Sub

End Module