No xadrez, um cavaleiro na grade (x, y) pode se mover para (x-2, y-1), (x-2, y + 1), (x-1, y-2), (x-1, y + 2), (x + 1, y-2), (x + 1, y + 2), (x + 2, y-1), (x + 2, y + 1) em uma etapa. Imagine um tabuleiro de xadrez infinito com apenas um cavaleiro ligado (0, 0):
Quantos passos são necessários para mover um Knight de (0, 0) para (t x , t y )?
Entradas
Dois inteiros: t x , t y ;
-100 <t x <100, -100 <t y <100
Saída
Etapas mínimas necessárias para mover um Cavaleiro de (0, 0) para (t x , t y ).
Regras
- código de golfe
Casos de teste
x y -> out
0, 0 -> 0
0, 1 -> 3
0, 2 -> 2
1, 1 -> 2
1, 2 -> 1
3, 3 -> 2
4, 0 -> 2
42, 22 -> 22
84, 73 -> 53
45, 66 -> 37
99, 99 -> 66
-45, -91 -> 46
-81, 1 -> 42
11, -2 -> 7
document.write('<div>');[..."EFEDEDCDCBCBCBCBCBCBCBCBCBCBCBCBCBCDCDEDEFE;FEDEDCDCBCBABABABABABABABABABABABCBCDCDEDEF;EDEDCDCBCBABABABABABABABABABABABABCBCDCDEDE;DEDCDCBCBABA9A9A9A9A9A9A9A9A9A9ABABCBCDCDED;EDCDCBCBABA9A9A9A9A9A9A9A9A9A9A9ABABCBCDCDE;DCDCBCBABA9A9898989898989898989A9ABABCBCDCD;CDCBCBABA9A989898989898989898989A9ABABCBCDC;DCBCBABA9A98987878787878787878989A9ABABCBCD;CBCBABA9A9898787878787878787878989A9ABABCBC;BCBABA9A989878767676767676767878989A9ABABCB;CBABA9A98987876767676767676767878989A9ABABC;BABA9A9898787676565656565656767878989A9ABAB;CBA9A989878767656565656565656767878989A9ABC;BABA98987876765654545454545656767878989ABAB;CBA9A987876765654545454545456567678789A9ABC;BABA98987676565454343434345456567678989ABAB;CBA9A987876565454343434343454565678789A9ABC;BABA98987676545434323232343454567678989ABAB;CBA9A987876565434323232323434565678789A9ABC;BABA98987676545432341214323454567678989ABAB;CBA9A987876565434321232123434565678789A9ABC;BABA98987676545432323032323454567678989ABAB;CBA9A987876565434321232123434565678789A9ABC;BABA98987676545432341214323454567678989ABAB;CBA9A987876565434323232323434565678789A9ABC;BABA98987676545434323232343454567678989ABAB;CBA9A987876565454343434343454565678789A9ABC;BABA98987676565454343434345456567678989ABAB;CBA9A987876765654545454545456567678789A9ABC;BABA98987876765654545454545656767878989ABAB;CBA9A989878767656565656565656767878989A9ABC;BABA9A9898787676565656565656767878989A9ABAB;CBABA9A98987876767676767676767878989A9ABABC;BCBABA9A989878767676767676767878989A9ABABCB;CBCBABA9A9898787878787878787878989A9ABABCBC;DCBCBABA9A98987878787878787878989A9ABABCBCD;CDCBCBABA9A989898989898989898989A9ABABCBCDC;DCDCBCBABA9A9898989898989898989A9ABABCBCDCD;EDCDCBCBABA9A9A9A9A9A9A9A9A9A9A9ABABCBCDCDE;DEDCDCBCBABA9A9A9A9A9A9A9A9A9A9ABABCBCDCDED;EDEDCDCBCBABABABABABABABABABABABABCBCDCDEDE;FEDEDCDCBCBABABABABABABABABABABABCBCDCDEDEF;EFEDEDCDCBCBCBCBCBCBCBCBCBCBCBCBCBCDCDEDEFE"].forEach(c=>document.write(c==';'?'<br>':`<span class="d-${c}">${c}</span>`));
document.write('<style>body{line-height:16px;color:rgba(255,255,255,0.2);}span{display:inline-block;width:16px;font-size:16px;text-align:center;}div{white-space:pre;}');[...'0123456789ABCDEF'].map((c,i)=>document.write(`.d-${c}{background:hsl(${60-4*i},80%,${65-2*i}%)}`));
OEIS relacionado
Aqui estão alguns OEIS para leitura adicional
- A018837 : Número de etapas para o cavaleiro alcançar (n, 0) no tabuleiro de xadrez infinito.
- A018838 : Número de etapas para o cavaleiro alcançar (n, n) no tabuleiro de xadrez infinito.
- A065775 : Matriz T lida pelas diagonais: T (i, j) = menor número de movimentos do cavaleiro em um tabuleiro de xadrez (infinito em todas as direções) necessário para se mover de (0,0) para (i, j).
- A183041 : Menor número de movimentos do cavaleiro de (0,0) para (n, 1) no tabuleiro de xadrez infinito.
x+yi
?