μμ μ 리μλ λ€μκ³Ό κ°μ κ³Όμ μΌλ‘ κ³μ°ν μ μμ΅λλ€.
- 0μ μμ 0μ κ°μ΅λλ€.
- ν a, μ΄ bμ a / bκ° ν¬ν¨λλλ‘ κ·Έλ¦¬λμ λ€λ₯Έ μ«μλ₯Ό μ λ ¬νμμμ€.
- λκ°μ μ§κ·Έμ¬κ·Έλ₯Ό μ€λ₯Έμͺ½ μλ¨μμ μΌμͺ½ νλ¨μΌλ‘ νλ‘ν
- μ§κ·Έμ¬κ·Έλ₯Ό λ°λΌ λ°μνλ κ³ μ λ²νΈμ λμ μ§κ³
μ§κ·Έμ¬κ·Έ μ¬μ§μ λ€μκ³Ό κ°μ΅λλ€.
λ°λΌμ μ«μλ μμλλ‘
1/1, 2/1, 1/2, 1/3, 2/2, 3/1, 4/1, 3/2, 2/3, 1/4, 1/5, 2/4, 3/3, 4/2, 5/1, 6/1, 5/2, 4/3, 3/4, 2/5, 1/6, 1/7, 2/6, 3/5, 4/4, 5/3 ...
κ·Έλ¦¬κ³ λ¨μνλκ³ κ³ μ ν μ«μλ
1, 2, 1/2, 1/3, 3, 4, 3/2, 2/3, 1/4, 1/5, 5, 6, 5/2, 4/3, 3/4, 2/5, 1/6, 1/7, 3/5, 5/3, ...
λμ :
- λ κ°μ 0λ³΄λ€ ν° μ μ p λ° q κ° μ£Όμ΄μ§λ©΄ p / q μ μμλ₯Ό μΆλ ₯νμμμ€.
- pμ qλ λ°λμ 곡λ νλΌμ μΌ νμλ μμ΅λλ€
- μ΅λ¨ μ½λ μΉλ¦¬
- νμ€ νμ μ κΈμ§λμ΄ μμ΅λλ€
ν μ€νΈ μ¬λ‘ :
λ€μμ μ²μ λ°κ²¬ λ 24 κ°μ μ 리μμ κ°κ°μ λν μνλ μΆλ ₯μ λλ€.
1/1: 1
2/1: 2
1/2: 3
1/3: 4
2/2: 1
3/1: 5
4/1: 6
3/2: 7
2/3: 8
1/4: 9
1/5: 10
2/4: 3
3/3: 1
4/2: 2
5/1: 11
6/1: 12
5/2: 13
4/3: 14
3/4: 15
2/5: 16
1/6: 17
1/7: 18
2/6: 4
3/5: 19
κ·Έλ¦¬κ³ μΆκ° ν μ€νΈ μ¬λ‘μ κ²½μ° μμλλ‘ 200 κ°μ 첫 λ²μ§Έ μμ μ 리μκ° μμ΅λλ€.
1, 2, 1/2, 1/3, 3, 4, 3/2, 2/3, 1/4, 1/5,
5, 6, 5/2, 4/3, 3/4, 2/5, 1/6, 1/7, 3/5, 5/3,
7, 8, 7/2, 5/4, 4/5, 2/7, 1/8, 1/9, 3/7, 7/3,
9, 10, 9/2, 8/3, 7/4, 6/5, 5/6, 4/7, 3/8, 2/9,
1/10, 1/11, 5/7, 7/5, 11, 12, 11/2, 10/3, 9/4, 8/5,
7/6, 6/7, 5/8, 4/9, 3/10, 2/11, 1/12, 1/13, 3/11, 5/9,
9/5, 11/3, 13, 14, 13/2, 11/4, 8/7, 7/8, 4/11, 2/13,
1/14, 1/15, 3/13, 5/11, 7/9, 9/7, 11/5, 13/3, 15, 16,
15/2, 14/3, 13/4, 12/5, 11/6, 10/7, 9/8, 8/9, 7/10, 6/11,
5/12, 4/13, 3/14, 2/15, 1/16, 1/17, 5/13, 7/11, 11/7, 13/5,
17, 18, 17/2, 16/3, 15/4, 14/5, 13/6, 12/7, 11/8, 10/9,
9/10, 8/11, 7/12, 6/13, 5/14, 4/15, 3/16, 2/17, 1/18, 1/19,
3/17, 7/13, 9/11, 11/9, 13/7, 17/3, 19, 20, 19/2, 17/4,
16/5, 13/8, 11/10, 10/11, 8/13, 5/16, 4/17, 2/19, 1/20, 1/21,
3/19, 5/17, 7/15, 9/13, 13/9, 15/7, 17/5, 19/3, 21, 22,
21/2, 20/3, 19/4, 18/5, 17/6, 16/7, 15/8, 14/9, 13/10, 12/11,
11/12, 10/13, 9/14, 8/15, 7/16, 6/17, 5/18, 4/19, 3/20, 2/21,
1/22, 1/23, 5/19, 7/17, 11/13, 13/11, 17/7, 19/5, 23, 24,
23/2, 22/3, 21/4, 19/6, 18/7, 17/8, 16/9, 14/11, 13/12, 12/13,
11/14, 9/16, 8/17, 7/18, 6/19, 4/21, 3/22, 2/23, 1/24, 1/25
첫 λ²μ§Έ μμ§μμ΄ λ€μ΄ λ λ°λ μ§λ¬Έ μ μΈμΉλ©΄ λ΅λ³μ μ¬μ©νμ¬ μΆκ° ν μ€νΈ μ¬λ‘λ₯Ό μμ± ν μ μμ΅λλ€.
λ΅λ³
μ €λ¦¬ , Β 21Β 20 λ°μ΄νΈ
μ리ν μνμ μ¬μ©νμ¬ μ¬λ¬ λ°μ΄νΈλ‘ μ΄κΈΈ μ μμ΅λλ€ β¦
:g/
ΓΒ΅SRRUΔβ¬UΓeαΊΓβ¬Qi
μ [p,q]
μ§μ λ μμ°μλ₯Ό λ°ν νλ λͺ©λ‘μ μλ½νλ λͺ¨λλ λ§ν¬ p/q
.
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€! λλ ν μ€νΈ μ€μνΈλ₯Ό μ°Έμ‘°νμμμ€.
μ΄λ»κ²?
λ¨Όμ N λ²μ§Έ λκ°μ μ λΆμμ λΆλͺ¨μ ν©μ΄ N + 1 μΈ κ·Έλ¦¬λμ λͺ¨λ ν©λ¦¬μ μΈ μ«μλ₯Ό ν¬ν¨ νλ―λ‘ [p,q]
μμ κ°μ₯ κ°λ¨ν ννλ‘ μ€μ΄λ ν¨μλ₯Ό [p/gcd(p,q),q/gcd(p,q)]
μ¬μ©νλ©΄ λκ°μ μ λ§λ€ μ μμ΅λλ€. *, λͺ¨λ νλͺ©μ μ€μ΄κ³ , μ€λ³΅μ μ κ±°νκ³ λ¨μν λ μ
λ ₯μ μμΈμ μ°ΎμμΌν©λλ€.
* μ€μ λ‘ λ°μ΄νΈλ₯Ό μ μ₯νκΈ° μν΄ μ¬κΈ°μ νλ λ
:g/ - Link 1, simplify a pair: list of integers, [a, b]
/ - reduce using:
g - Greatest Common Divisor -> gcd(a, b)
: - integer division (vectorises) -> [a/gcd(a,b), b/gcd(a,b)]
ΓΒ΅SRRUΔβ¬UΓeαΊΓβ¬Qi - Main Link: list of integers, [p, q]
Γ - call last Link as a monad (simplify)
Β΅ - start a new monadic chain (call that V)
S - sum -> the diagonal V will be in plus one
R - range -> [1,2,3,...,diag(V)+1]
R - range (vectorises) -> [[1],[1,2],[1,2,3],...,[1,2,3,...,diag(V)+1]]
U - reverse each -> [[1],[2,1],[3,2,1],[diag(V)+1,...,3,2,1]]
Δβ¬ - enumerate β¬ach -> [[[1,1]],[[1,2],[2,1]],[[1,3],[2,2],[3,1]],[[1,diag(V)+1],...,[diag(V)-1,3],[diag(V),2],[diag(V)+1,1]]]
Γe - apply only to the even indexed items:
U - reverse each -> [[[1,1]],[[2,1],[1,2]],[[1,3],[2,2],[3,1]],[[4,1],[3,2],[2,3],[1,4]],...]
αΊ - tighten -> [[1,1],[2,1],[1,2],[1,3],[2,2],[3,1],[4,1],[3,2],[2,3],[1,4],...]
Γβ¬ - for β¬ach: call last Link as a monad (simplify each)
- -> [[1,1],[2,1],[1,2],[1,3],[1,1],[3,1],[4,1],[3,2],[2,3],[1,4],...]
Q - de-duplicate -> [[1,1],[2,1],[1,2],[1,3],[3,1],[4,1],[3,2],[2,3],[1,4],...]
i - index of V in that list
λ΅λ³
ν 6 , Β 94Β 90 λ°μ΄νΈ
->\p,\q{(({|(1β¦($+=2)β¦1)}β¦*)Z/(1,{|(1β¦(($||=1)+=2)β¦1)}β¦*)).unique.first(p/q,:k)+1}
{(({|(1β¦($+=2)β¦1)}β¦*)Z/(1,{|(1β¦(($||=1)+=2)β¦1)}β¦*)).unique.first($^p/$^q):k+1}
κΈ°λ³Έμ μΌλ‘ μ 체 κ° μνμ€λ₯Ό μμ±νκ³ μΌμΉνλ νλͺ©μ μ°ΎμΌλ©΄ μ€μ§ν©λλ€.
λνλ:
{ # bare block lambda with placeholder parameters $p,$q
(
( # sequence of numerators
{
|( # slip into outer sequence (flatten)
1 # start at one
β¦
(
$ # state variable
+= 2 # increment it by two each time this block is called
)
β¦
1 # finish at one
)
}
β¦ * # never stop generating values
)
Z/ # zip using &infix:Β« / Β» (generates Rats)
( # sequence of denominators
1, # start with an extra one
{
|( # slip into outer sequence (flatten)
1
β¦
(
( $ ||= 1 ) # state variable that starts with 1 (rather than 0)
+= 2 # increment it by two each time this is called
)
β¦
1
)
}
β¦ * # never stop generating values
)
).unique # get only the unique values
.first( $^p / $^q ) # find the first one that matches the input
:k # get the index instead (0 based)
+ 1 # add one (1 based)
}
({1β¦($+=2)β¦1}β¦*)
무νν λΆμ μνμ€λ₯Ό μμ±ν©λλ€ ( |(β¦)
μμμ μ¬μ©νμ¬ ννν).
(1 2 1)
(1 2 3 4 3 2 1)
(1 2 3 4 5 6 5 4 3 2 1)
(1 2 3 4 5 6 7 8 7 6 5 4 3 2 1)
(1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1)
β¦
(1,{1β¦(($||=1)+=2)β¦1}β¦*)
무ν λΆλͺ¨μ λΆλͺ¨λ₯Ό μμ±
1
(1 2 3 2 1)
(1 2 3 4 5 4 3 2 1)
(1 2 3 4 5 6 7 6 5 4 3 2 1)
(1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1)
(1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1)
β¦
λ΅λ³
νμ΄μ¬ (2) , 157 (144) 137 134 126 125 λ°μ΄νΈ
def f(p,q):a=[((j-i)/(i+1.))**(j%-2|1)for j in range(p-~q)for i in range(j)];return-~sorted(set(a),key=a.index).index(p*1./q)
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€!
Mr. Xcoder λ‘ μΈν΄ 4 λ°μ΄νΈκ° μ μ½λμμ΅λλ€ . Jonathon Frech μμ 1 λ°μ΄νΈ .
Xcoderκ° μ§μ νλ―μ΄, νμ΄μ¬ 3μμλ μ μ λλκΈ°κ° κΈ°λ³Έμ μΌλ‘ κ²°κ³Όλ₯Ό νλ‘ν
νκ³ λ μ½κ² μμΆμ ν μ μκΈ° λλ¬Έμ νμ΄μ¬ 3μμ μ‘°κΈ λ μ ν μ μμ΅λλ€ list
.
νμ΄μ¬ 3 , 117 λ°μ΄νΈ
def f(p,q):a=[((j-i)/-~i)**(j%-2|1)for j in range(p-~q)for i in range(j)];return-~sorted({*a},key=a.index).index(p/q)
λ΅λ³
νμ΄μ¬ 3 ,157, 146, 140, 133 λ°μ΄νΈ
def f(p,q):a=[(i+i-abs(j-i-i))/(abs(j-i-i+.5)+.5)for i in range(p+q)for j in range(4*i)];return sorted(set(a),key=a.index).index(p/q)
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€!
Jonathan Frech λλΆμ 11 λ°μ΄νΈ μ°μΉ
Chas Brown λλΆμ 6 λ°μ΄νΈ λ νλ ν ν 7 μ
λ΅λ³
J, 41 , 35 , 30 λ°μ΄νΈ
FrownyFrog λλΆμ -11 λ°μ΄νΈ
%i.~0~.@,@,[:]`|./.[:%/~1+i.@*
μ¨λΌμΈμΌλ‘ μ¬μ©ν΄λ³΄μμμ€!
μ€λͺ μ΄μλ μλ³Έ 41 λ°μ΄νΈ κ²μλ¬Ό
%>:@i.~[:([:~.@;[:<@|.`</.%"1 0)~(1+i.@*)
μΈ κ³¨ν
% >:@i.~ [: ([: ~.@; [: <@|.`</. %"1 0)~ 1 + i.@*
μ€λͺ
+
| Everything to the right of this
| calculates the list
p (left arg) | create the
divided by q | diagonals. yes,
(right) | +this is a +create this list
| | ++ finally rmv ^alternately |primitive ADVERB |1..(p*q), and pass
| + the index | the boxes, |box, or |in J |it as both the left
| | of that | | and remove |reverse and | |and right arg to the
| | in the | | any dups |box, each | |middle verb, where each
| | list on | | |diagonal | |element will divide the
| | the right| | | | +----------+entire list, producing
| | plus 1 | | | | | |the undiagonalized grid
| | | | | | | |
| | | | | | | |
| | + | | | | |
β+β¬ββ|βββββββββββ¬βββββββββ|βββββββββββββ|βββββββββββββ|βββββββ|ββββββββββ|ββββββββββββββ
β%βββ+ββββββββ¬βββββββ¬βββββ|βββββββββββββ|βββββββββββββ|βββββββ|βββββββββ¬β|ββββββββββββββ
β ββββββ¬ββ¬ββββ~βββ[:ββββββ|βββββββββββββ|βββββββββββββ|βββββββ|ββββββ¬ββββ+β¬ββ¬βββββββββββ
β βββ>:β@βi.ββ βββ ββββββ¬|ββββββββ¬βββββ|βββββββββββββ|βββββββ|ββββββ~βββ1β+βββββ¬ββ¬βββββ
β ββββββ΄ββ΄ββββ βββ βββ[:β+βββ¬ββ¬βββββββ¬β|βββββββββββββ|ββ¬βββββ|ββββββ βββ β ββi.β@β*ββββ
β ββββββββββββ΄ββββ βββ ββ~.β@β;βββ[:ββ|ββββββββββββ¬β+βββββ¬ββ¬+ββββββ βββ β βββββ΄ββ΄βββββ
β β ββ βββ βββββ΄ββ΄ββββ ββ+βββββββββ¬βββ/.βββ%β"β1 0ββββ βββββ΄ββ΄βββββββββββ
β β ββ βββ β ββ ββββββ¬ββ¬ββββ<ββ βββββ΄ββ΄βββββββ ββ ββ
β β ββ βββ β ββ ββββ<β@β|.ββ ββ ββ βββ ββ ββ
β β ββ βββ β ββ ββββββ΄ββ΄ββββ ββ ββ βββ ββ ββ
β β ββ βββ β ββ ββββββββββββ΄βββ ββ βββ ββ ββ
β β ββ βββ β ββ βββββββββββββββ΄ββββ βββ ββ ββ
β β ββ βββ β βββββ΄ββββββββββββββββββ΄ββββββββββββ ββ ββ
β β ββ ββββββ΄βββββββββ΄ββββββββββββββββββββββββββββββββββ ββ ββ
β β ββ βββββββββββββββββββββββββββββββββββββββββββββββββ΄βββ ββ
β β βββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββ
βββ΄ββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
λ΅λ³
νμ΄μ¬ 3, 121 λ°μ΄νΈ
import math
def o(x,y):
p=q=n=1
while x*q!=p*y:a=p+q&1;p+=1+a*~-~-(p<2);q+=1-~-a*~-~-(q<2);n+=math.gcd(p,q)<2
return n
λ΅λ³
λ Ή, 244 λ°μ΄νΈ
: λλ μΌκ°ν μ«μ μμμ μ¬μ©νμ¬ νΌμ¦μ μ μ½μμ΄ βμΌλ°βμ§κ·Έμ¬κ·Έμ βμΌλ°βμμλ₯Ό μ°Ύλ κ°λ¨ν 곡μμ λ§λ€μ΄
https://www.mathsisfun.com/algebra/triangular-numbers.html . μ΄κ²μ μ§κ·Έμ¬κ·Έκ° νΌμ¦μ κ° λκ°μ ν λ°©ν₯μ λ€μ§λ κ²μ μ€λͺ
νκΈ° μν΄ λͺ¨λλ‘ 2λ‘ μμ λμμ΅λλ€. μ΄κ²μ ν¨μ h ()μ
λλ€
κ·Έλ¦¬κ³ μ§κ·Έμ¬κ·Έ νΈλ μΌμμ 3/3 vs 1/1, 4/2 vs 2/1κ³Ό κ°μ λ°λ³΅λλ νΉμ κ°μ κ³μ°νμ§ μλ λ°©λ². 1-200 μμ λ₯Ό μ€ννκ³ μΌλ° μ§κ·Έμ¬κ·Έ μΌκ°ν μΉ΄μ΄ν°μ νΌμ¦μ΄ μνλ μΉ΄μ΄ν°μ μ°¨μ΄κ° ν¨ν΄μ μμμ μμμ΅λλ€. βλλ½ λβμ«μμ ν¨ν΄μ 5, 12, 13, 14, 23 λ±μΌλ‘ OEISμμ μ μ€νμ΅λλ€. 3/3, 4/2 λ° 1/1κ³Ό κ°μ μ«μλ₯Ό βμ€λ³΅ μ κ±°βνκΈ° μν΄ Robert A Stump ( https://oeis.org/A076537 )μ μ€λͺ λμ΄ μμ΅λλ€. μ§κ·Έμ¬κ·Έμ λͺ¨λ βμ΄μ βμμ μ€ x, y μ΄κ²μ βforβ루νμ΄κ³ gcd μΈ g ()λ gcdμ λλ€.
λλ λ΄μ₯ λ gcdλ‘ κ·Έκ²μ΄ λ 짧μμ κ²μ΄λΌκ³ μκ°νμ§λ§, λλ κ·Έκ²μ μ½κ² μ°Ύμ μ μμμ΅λλ€ (Rust and Integerμμ μλ‘μ΄ μ’ λ₯μ λλ₯Ό νΌλνμ΅λλ€). μ΄λ€ μ’ λ₯μ λ΄μ₯μ΄λ λΌμ΄λΈλ¬λ¦¬λ μμ΅λλ€.
fn f(x:i64,y:i64)->i64 {
fn h(x:i64,y:i64)->i64 {let s=x+y;(s*s-3*s+4)/2-1+(s+1)%2*x+s%2*y}
fn g(x:i64,y:i64)->i64 {if x==0 {y} else {g(y%x,x)}}
let mut a=h(x,y);
for i in 1..x+y {for j in 1..y+x {if h(i,j)<h(x,y) && g(i,j)>1 {a-=1;}}}
a
}