-1
#include <iostream>
using namespace std;



int main()
{
    int index = 0;
    int val;
    int x;

    while (val != 0)
    {

    cin >> val;



    for (index = 1; index < 32; index++)
    {
        x = val * index - index / index;
        cout << x << " " << val << " " << index << endl;
        cout << x % 4 << endl;
        cout << x % 3 << endl;
        cout << x % 2 << endl;

    }
    }


    return 0;
}

Why is it that when the input is <1, 2, 3, 4...> every 31st index is encoded in an algorithm similar to input 1, which is just index - 1; but the pattern is:

of twelves (1-12, 12 -24) [000, 111, 220, 301, 010, 121, 200, 311, 020, 101, 211, 321] , [000, 111, 220, 301, 010...repeating for input <1>;

of 31st index: [1]200, 111, 020, 301, 210, 121, 000, 311, 220, 101, 010, 321, 200...[13]

Why is the relation similar and is there a reason for this in binary?

Edit: To clarify question, when you take the remainder of a certain integer, and the relation becomes specific to each incrementation...is the reason for this because of binary and how the semantic is based on implementing a way to converge integer value to binary value? I know that high-level programming is using hash and communicating within programs...but the main idea is for the integer value to be binary specific...is this a binary specific operation or just some random algorithm that shows patterns in numbers?

mydiax
  • 41
  • 10
  • 3
    Your question makes no sense. Please clarify. – Schilcote May 30 '16 at 22:00
  • Is this relevant? http://stackoverflow.com/questions/26047196/is-there-any-way-to-write-mod-31-without-modulus-division-operators – mydiax May 30 '16 at 22:11
  • @mydiax How do you distinguish _binary input_ actually? – πάντα ῥεῖ May 30 '16 at 22:26
  • 1
    @mydiax Integer numbers are numbers, their binary representation is a totally [different kettle of fish](https://en.wiktionary.org/wiki/kettle_of_fish). – πάντα ῥεῖ May 30 '16 at 22:30
  • Could you impose that a binary function via a pointer, to a hash and an emulated integer back and forth? (edit), emulating a binary to value of integer, then back to a different binary format i.e. binary >> int a >> binary(1) >> int b[index].mod – mydiax May 30 '16 at 22:40
  • 1
    @mydiax None of this makes any sense. Not a word of it. It is all meaningless. – user207421 May 30 '16 at 23:23

1 Answers1

1

Important fact:

12 mod 2 == 12 mod 3 == 12 mod 4 == 0

Another important fact, a little more abstract:

(x + y) mod k == ((x mod k) + (y mod k)) mod k

(Assuming x, y and k are all integers.)

From the second fact, we can deduce:

(x + 12) mod k == ((x mod k) + (12 mod k)) mod k

As it happens:

(x mod k) mod k == x mod k

And so now we know that

(x + 12) mod 2 == (x mod 2) + 0 == x mod 2
(x + 12) mod 3 == (x mod 3) + 0 == x mod 3
(x + 12) mod 4 == (x mod 4) + 0 == x mod 4

So the pattern of mods will repeat in a cycle of 12.

In general, the cycle length will be the Least Common Multiple of the divisors.

rici
  • 234,347
  • 28
  • 237
  • 341
  • 2 * 3 * 4 = 24, not 12 – ajc2000 May 31 '16 at 00:06
  • @ajc2000: yeah, should have been lcm(2,3,4) but not worth the trouble explaining. Skipped directly to the mod. Thanks – rici May 31 '16 at 00:28
  • I found that when starting with and , putting them in rows and columns, each pair of any number will give the first and last array of mods. So, 1 starts with 000, ends with 200, each number is like that no matter what, whatever it started with the column, row, of and is this what you're trying to tell me? – mydiax May 31 '16 at 01:24
  • 1
    @mydiax: what i'm trying to tell you is that a little bit of arithmetic will explain what you are seeing. I encourage you to grab a pad of paper and a pencil and exercise your mathematical reasoning. – rici May 31 '16 at 01:31
  • is this a structure complex? from when you combine logarithms such as, [g] as log (2 log x^log (n)) = log (n) + log (x) = 2? (log(x) * x^2 is just X because this is pertaining to square roots because [index::25] on any input gives me the row >input1 – mydiax May 31 '16 at 01:37