9
\$\begingroup\$

In this question I defined a "chain" function as a function that:

  • is a permutation, meaning that every value maps to and is mapped to by exactly one value.

  • and allows any value can be obtained from any other value by repeated applications of the function or its inverse.

There are a lot of functions that do this and some of them are pretty simple (see the answers on that question). Now we are going to define a separate class of functions I am going to call "interwoven" functions. An interwoven function is a function on a set A, that has two infinite partitions a0 and a1 such that the function is a chain function on both a0 and a1.

This means that no value in a0 can map to a value in a1 under the function or vice versa.

Task

Your task is to write a code that performs or defines an interwoven function on the positive integers. Your function can be anything as long as it satisfies the criteria for being interwoven. You should include a explanation as to why your function is interwoven in the answer.

This is a question so answers will be scored in bytes, with less bytes being better.

\$\endgroup\$
  • \$\begingroup\$ @flawr Thanks! I was looking for that word but I couldn't think of it. \$\endgroup\$ – Wheat Wizard Aug 8 '17 at 21:14
  • \$\begingroup\$ I think this could be considered a dupe of the last challenge you linked, as you just have to make an additional transfromation, i.e. enumerating all the even and all the odd numbers seperately. I don't think any of the answers you're getting here will provide anything substantially new. \$\endgroup\$ – flawr Aug 8 '17 at 21:17
  • \$\begingroup\$ @flawr You could do that, but it wouldn't be the best way. I've done a little experimentation with this and there are some novel ways to perform these types of functions. \$\endgroup\$ – Wheat Wizard Aug 8 '17 at 21:19
2
\$\begingroup\$

Python, 46 42 37 bytes

5 bytes saved thanks to @notjagan

lambda x:1<x<4and x*2%5or x-(x&2)*4+4

Try it online!

Iterates the even and odd numbers with steps of 4 and links on 2 and 3:

=> 22 => 18 => 14 => 10 => 6 => 2 => 4 => 8 => 12 => 16 => 20 => 24 =>
=> 23 => 19 => 15 => 11 => 7 => 3 => 1 => 5 => 9 => 13 => 17 => 21 =>
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 30 24 bytes

a=>(a+=a&2?-4:4)<0?a*a:a

Sequences:

  1. ... 19 15 11 7 3 1 5 9 13 17 21 ...
  2. ... 18 14 10 6 2 4 8 12 16 20 24 ...

Code snippet

f=a=>(a+=a&2?-4:4)<0?a*a:a
console.log('23 19 15 11 7 3 1 5 9 13 17'.split` `.map(a=>f(a|0)).join` `);
console.log('22 18 14 10 6 2 4 8 12 16 20'.split` `.map(a=>f(a|0)).join` `);

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Dyalog APL, 24 22 bytes

{x*1+0>x←4+⍵-8×2|⌊⍵÷2}

Try it online!

Same chains as my python answer.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.