글쓴이 보관물: μ†Œμž₯ 마

μ–‘μ˜ 유리수λ₯Ό μ„Έ 어라 5 4/1: 6 3/2: 7 2/3: 8 1/4: 9 1/5: 10 2/4:

μ–‘μ˜ μœ λ¦¬μˆ˜λŠ” λ‹€μŒκ³Ό 같은 κ³Όμ •μœΌλ‘œ 계산할 수 μžˆμŠ΅λ‹ˆλ‹€.

  1. 0은 μ„œμˆ˜ 0을 κ°–μŠ΅λ‹ˆλ‹€.
  2. ν–‰ a, μ—΄ b에 a / bκ°€ ν¬ν•¨λ˜λ„λ‘ κ·Έλ¦¬λ“œμ— λ‹€λ₯Έ 숫자λ₯Ό μ •λ ¬ν•˜μ‹­μ‹œμ˜€.
  3. λŒ€κ°μ„  μ§€κ·Έμž¬κ·Έλ₯Ό 였λ₯Έμͺ½ μƒλ‹¨μ—μ„œ μ™Όμͺ½ ν•˜λ‹¨μœΌλ‘œ ν”Œλ‘œνŒ…
  4. μ§€κ·Έμž¬κ·Έλ₯Ό 따라 λ°œμƒν•˜λŠ” 고유 번호의 λˆ„μ  집계

μ§€κ·Έμž¬κ·Έ 사진은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

1/1μ—μ„œ μ‹œμž‘ν•˜μ—¬ 초기 이동 였λ₯Έμͺ½

λ”°λΌμ„œ μˆ«μžλŠ” μˆœμ„œλŒ€λ‘œ

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
}