বিপরীতমুখী কলম্বিয়ান ফাংশন


28

আসুন একটি ক্রম সংজ্ঞায়িত করুন: n ডিজিটের যোগফল ক্রম (এন-ডিএসএস) একটি অনুক্রম যা এন দিয়ে শুরু হয় । যদি শেষ সংখ্যাটি কে হয় , তবে পরের সংখ্যাটি হল কে + ডিজিট-যোগ (কে) । এখানে প্রথম কয়েকটি এন-ডিএসএস রয়েছে:

1-DSS: 1, 2, 4, 8, 16, 23, 28, 38, 49, 62, 70...
2-DSS: 2, 4, 8, 16, 23, 28, 38, 49, 62, 70, 77...
3-DSS: 3, 6, 12, 15, 21, 24, 30, 33, 39, 51, 57...
4-DSS: 4, 8, 16, 23, 28, 38, 49, 62, 70, 77, 91...
5-DSS: 5, 10, 11, 13, 17, 25, 32, 37, 47, 58, 71...
6-DSS: 6, 12, 15, 21, 24, 30, 33, 39, 51, 57, 69...
7-DSS: 7, 14, 19, 29, 40, 44, 52, 59, 73, 83, 94...
8-DSS: 8, 16, 23, 28, 38, 49, 62, 70, 77, 91, 101...
9-DSS: 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99...

1 এর জন্য, এটি A004207 , যদিও সামান্য ভিন্ন সংজ্ঞার কারণে প্রথম কয়েকটি অঙ্ক আলাদা। 3 এর জন্য এটি A016052 ; 9 এর জন্য, A016096

আজকের চ্যালেঞ্জটি কোনও নির্দিষ্ট সংখ্যায় উপস্থিত সর্বনিম্ন অঙ্কের যোগফলের ক্রম সন্ধান করা This এটিকে " বিপরীতমুখী কলম্বিয়ান ফাংশন" বলা হয় এবং এটি A036233 । প্রথমটি বিশ টি শর্ত, 1 দিয়ে শুরু করে:

1, 1, 3, 1, 5, 3, 7, 1, 9, 5, 5, 3, 5, 7, 3, 1, 5, 9, 7, 20

অন্য কয়েকটি ভাল পরীক্ষার মামলা:

117: 9
1008: 918

আপনাকে কেবল 0 এর চেয়ে বড় পূর্ণসংখ্যাকে পরিচালনা করতে হবে এবং আপনি কোনও মানক বিন্যাসে ইনপুট এবং আউটপুট নিতে পারেন take যথারীতি, এটি , তাই প্রতিটি ভাষার মধ্যে সংক্ষিপ্ত উত্তর।


উত্তর:


12

হাস্কেল , 104 64 63 বাইট

(-26 এইচ.পি.উইজকে ধন্যবাদ, অতিরিক্ত -১14 শ্রীওচিলিজম ও'জাইককে ধন্যবাদ, অতিরিক্ত -১ ধন্যবাদ কোলে ধন্যবাদ)

এটি একটি ফাংশন।

f x=[y|y<-[1..],x==until(>=x)(foldr((+).read.pure)<*>show)y]!!0

এটি অনলাইন চেষ্টা করুন!


ব্যাখ্যা:

(foldr((+).read.pure)<*>show)

যৌগিক ফাংশনগুলির ক্রম যা y + ডিজিটাল যোগফল y দেয় returns প্রথমে স্ট্রিংয়ে রূপান্তরিত হয়, তারপরে কিছু মনড জিমন্যাস্টিক্স অক্ষরের যোগফল এবং মূল সংখ্যা (কোলের জন্য ধন্যবাদ) পেতে দেয়।

<*>এই প্রেক্ষাপটে অপারেটর ধরন এবং সংজ্ঞা হয়েছে

(<*>) :: (a -> b -> c) -> (a -> b) -> c
f <*> g = \x -> f x (g x)

সুতরাং আমরা উপরের হিসাবে লিখতে পারেন

\x -> foldr ((+) . read . pure) x (show x)

এটি একটি সংখ্যায় read . pureরূপান্তরিত করে Char, তাই (+) . read . pure :: Char -> Int -> Intসঞ্চিত মানটিতে একটি অঙ্ক যোগ করে। এই মানটি ভাঁজটিতে প্রদত্ত সংখ্যায় শুরু করা হয়।

until (>=x) {- digital sum function -} y

untilবারবার তার ফলাফলের জন্য কোনও ক্রিয়া প্রয়োগ করে (এই ক্ষেত্রে, y + ডিজিটাল যোগ y) যতক্ষণ না এটি প্রথম যুক্তিতে কোনও ফাংশন দ্বারা নির্দিষ্ট করা প্রয়োজন পূরণ করে। এটি সবচেয়ে ছোট Y-DSS উপাদান দেয় যা x এর চেয়ে বড় বা সমান।

[y | y<-[1..]; x == {- smallest y-DSS element >= x -} ]

সর্বনিম্ন y-DSS উপাদান> = x আসলে x এর মতো y এর অসীম অলস তালিকা। হাস্কেলের তালিকা বোঝার স্বীকৃতি (যা আমি পুরোপুরি ভুলে গেছি, সমস্ত ধন্যবাদ) ব্যবহার করে।

f x = {- aforementioned list -} !! 0

সেই তালিকার প্রথম উপাদান, যা চ্যালেঞ্জের প্রয়োজনীয়তা পূরণ করে এমন ক্ষুদ্রতম y।


1
এখানে আমি এটি গল্ফ করেছিলাম।
এইচ.পি.উইজ

1
@ এইচপিউইজ এটি কি একই হওয়া উচিত? আমিও তাই fmapভাবব তবে প্রথমে আপনার ব্যবহার আমাকে কিছুটা বিভ্রান্ত করেছে।
গম উইজার্ড

1
ঠিক আছে এতে প্রচুর ফেনাংলিং লেগেছিল তবে আমি একক বাইট ছাঁটাই করতে পাঠক মনাদকে গালি দিয়েছি। ওহু পয়েন্টফ্রি কোড! টিআইও
কোলে

@ শ্রুতচিলিজম ও'জাইক শীতল আমি কেবল কোডটি যান্ত্রিকভাবে গল্ফ করেছি, এটি সম্পর্কে চিন্তা না করেই
এইচ.পি.উইজ

1
মোবাইলে কীভাবে অনুরোধ সম্পাদনা করবেন তা নিশ্চিত নয় তাই আমি কেবল আমার কোডের ব্যাখ্যায় সম্পাদনা করেছি - নির্দ্বিধায় পরিবর্তন করতে বা ফিরে যেতে।
কোলে


4

পার্ল 6 , 44 বাইট

->\a{+(1...{a∈($_,{$_+.comb.sum}...*>a)})}

এটি অনলাইন চেষ্টা করুন!

নিষ্কলুষ সমাধান যা প্রতিটি ক্রম চেক করে যতক্ষণ না এটি ইনপুটযুক্ত কোনও সন্ধান করে

ব্যাখ্যা:

->\a{                                    }  # Anonymous code block taking input as a
     +(1...{                           })   # Find the first number
            a∈(                       )     # Where the input is an element of
                                ...         # The sequence
               $_,                          # Starting with the current number
                  {            }   # Where each element is
                   $_+             # Is the previous element plus
                      .comb.sum    # The digit sum
                                   *>a      # Until the element is larger than the input



3

এমএটিএল , 18 বাইট

`@G:"ttFYAs+]vG-}@

এটি অনলাইন চেষ্টা করুন! অথবা প্রথম 20 টি মানটি যাচাই করুন

ব্যাখ্যা

iইনপুটটির জন্য , -পরিক্রমের nপ্রথম iশর্তাদি nঅন্তর্ভুক্ত হওয়া পর্যন্ত এটি বাড়তে থাকে iiপ্রতিটি সিকোয়েন্সের জন্য শর্তাদি পরীক্ষা করা যথেষ্ট কারণ ক্রমটি ক্রমবর্ধমান is

`         % Do...while
  @       %   Push iteration index, n. This is the firsrt term of the n-th sequence
  G:      %   Push [1 2 ... i], where i is the input
  "       %   For each (i.e., do the following i times)
    tt    %     Duplicate twice
    FYA   %     Convert to digits
    s     %     Sum
    +     %     Add to previous term. This produces a new term of the n-th sequence
  ]       %   End
  v       %   Concatenate all terms into a column vector
  G-      %   Subtract i, element-wise. This is the do...while loop condition (*).
}         % Finally (this is executed right before exiting the loop)
  @       %   Push current n. This is the output, to be displayed
          % End (implicit). A new iteration will start if all terms of (*) are nonzero
          % Display (implicit)

3

ফোর্থ (গফোর) , 106 বাইট

: f
>r 0 begin 1+ dup begin dup i < while dup begin 10 /mod >r + r> ?dup 0= until repeat i = until rdrop
;

এটি অনলাইন চেষ্টা করুন!

কোড ব্যাখ্যা

: f                \ start a new word definition
  >r               \ store the input on the return stack for easy access
  0                \ set up a counter
  begin            \ start an indefinite loop
    1+ dup         \ add 1 to the counter and duplicate
    begin          \ start a 2nd indefinite loop
      dup i <      \ check if current value is less than the input value
    while          \ if it is, continue with the inner loop
      dup          \ duplicate the current value
      begin        \ innermost loop, used to get the digit-wise sum of a number
        10 /mod    \ get quotient and remainder of dividing by 10
        >r + r>    \ add remainder to current list value
        ?dup 0=    \ check if quotient is 0
      until        \ end the innermost loop if it is
    repeat         \ go back to the beginning of the 2nd loop
    i =            \ check if the "last" value of the current list = the input value
  until            \ if it does, we're done
  rdrop            \ remove the input value from the return stack
;                  \ end the word definition    

3

পাইথ , 13 বাইট

fqQ.W<HQ+ssM`

এটি এখানে চেষ্টা করুন বা পরীক্ষার স্যুটটি দেখুন


কিভাবে এটা কাজ করে

fqQ.W<HQ+ssM`     Full program. Takes input Q from STDIN, writes to STDOUT.
f{...}            Loop over 1,2,3,... and find the first number to yield truthy results when
                     applying the function {...} (whose variable is T = the current integer).
 qQ.W<HQ+ssM`     The function {...}, which will be analysed separately.
   .W             Functional while. While condition A is true, do B.
     <HQ          Cond. A (var: H - starts at T): Checks if H is less than Q.
        +ssM`     Func. B (var: G - G & H are the same): If A, G & H become G+digit sum(G)
                  The last value of this functional while will be the least possible number N
                  in the T-DSS that is greater than or equal to Q.
                  If N = Q, then Q ∈ T-DSS. Else (if N > Q), then Q ∉ T-DSS.
 q                That being said, check whether N == Q. 

বেশিরভাগ ভাষায়, প্রাকৃতিক সংখ্যার সেটে লুপ করা সহজ হবে , ডিএসএসের প্রথম পদগুলি সন্ধান করুন (কারণ অঙ্কের যোগফল সর্বদা সর্বনিম্ন তাই এই ধরণের পরিমাণের পুনরাবৃত্ত সংযোজন ফলাফল হতে পারে না চেয়ে ছোট একটি মান ) এবং ডিএসএস- এর প্রথম পদগুলির মধ্যে কিনা তা পরীক্ষা করুন । পাইথের ক্ষেত্রে, উপলভ্য নিয়ন্ত্রণ-প্রবাহ কাঠামোগুলি একটি নির্দিষ্ট সংখ্যক শর্তের পরিবর্তে নির্দিষ্ট শর্ত পূরণ না হওয়া অবধি শর্তাদি উত্পন্ন করা সহজ করে তোলে।nk1nnnk


1
খুব সুন্দরভাবে সম্পন্ন হয়েছে, আমার fqQ.W<HQ+sjZ1014 বছরের জন্য ছিল an আমি পূর্ণসংখ্যার থেকে অঙ্ক পাওয়ার উপায় হিসাবে `এবং গুলি ভুলে যেতে থাকি!
সোক

3

জেলি , 9 বাইট

DS+)i$ƬṖṪ

একটি মোনাডিক লিঙ্ক একটি ধনাত্মক পূর্ণসংখ্যা গ্রহণ করে nযা ইতিবাচক পূর্ণসংখ্যার ফল দেয় a(n), এর বিপরীত কলম্বিয়ান n

এটি অনলাইন চেষ্টা করুন! অথবা পরীক্ষা-স্যুটটি দেখুন

কিভাবে

কার্যকরভাবে আমরা পিছনের দিকে কাজ করি, বারবার আমরা যে মূল্যটি যুক্ত করেছিলাম তার সন্ধান করি যতক্ষণ না আমরা একটি খুঁজে পাই:

DS+)i$ƬṖṪ - Link: integer n
      Ƭ   - Repeat until a fixed point, collecting up:
     $    -   last two links as a monad - f(n):
   )      -     left links as a monad for each - [g(x) for x in [1..n]]:
D         -       decimal digits of x
 S        -       sum
  +       -       add x
    i     -     first (1-indexed) index of n in that list, or 0 if no found
       Ṗ  - pop of the rightmost value (the zero)
        Ṫ - tail

13উদাহরণ হিসাবে ব্যবহার করা হচ্ছে ...

D  )  = [[1],[2],[3],[4],[5],[6],[7],[8],[9],[1,0],[1,1],[1,2],[1,3]]
 S    = [  1,  2,  3,  4,  5,  6,  7,  8,  9,    1,    2,    3,    4]
  +   = [  2,  4,  6,  8, 10, 12, 14, 16, 18,   11,   13,   15,   17]
    i 13 = .......................................... 11
    i 11 = .................................... 10
    i 10 = ............... 5
    i 5 = not found = 0 
    i 0 = not found = 0
    Ƭ -> [13, 11, 10, 5, 0]
    Ṗ =  [13, 11, 10, 5]
    Ṫ =               5

2

পাইথন 2 , 85 বাইট

f=lambda n,a=[]:n in a and a.index(n)or f(n,[k+sum(map(int,`k`))for k in a]+[len(a)])

এটি অনলাইন চেষ্টা করুন!

এটি অবশ্যই সমস্ত পরীক্ষার ক্ষেত্রে, এবং ওইআইএস-এ প্রদত্ত 1.88 টি এন্ট্রিগুলির জন্যও কাজ করে; তবে তবুও আমি নিশ্চিত নই যে এটি কার্যকরভাবে সঠিক। (চার্চ অফ ইউনিট টেস্টিং সম্পর্কিত এটি আমার একটি অভিযোগ :))।


d(x)xCi(s)isCi(0)=i;Ci(s)=Ci(s1)+Σd(Ci(s1))x>1ed(x)(e1)ed(x)(e0)Σd(x)1

S(i)Ci(S(i))=nΣd(Ci(s1))1i<inS(i),S(i)S(i)S(i)iiinia.index(n)

@ ভ্যালু কালি: রজার! এটি সম্পূর্ণরূপে কাজ করে। ধন্যবাদ!
চাস ব্রাউন


2

ম্যাথগল্ফ , 13 বাইট

╒môk(É∙Σ+=k/)

এটি অনলাইন চেষ্টা করুন!

দুর্দান্ত চ্যালেঞ্জ! এটি আমাকে ম্যাথগল্ফের অন্তর্নিহিত পপ আচরণের মধ্যে কয়েকটি বাগ খুঁজে পেয়েছিল, যা সমাধানে 1-2 বাইট যুক্ত করেছে।

3

╒               range(1,n+1) ([1, 2, 3])
 mô             explicit map using 6 operators
   k(           push input-1 to TOS
     É          start block of length 3 (repeat input-1 times)
      ∙Σ+       triplicate TOS, take digit sum of top copy, and add that to second copy
                This transforms the array items to their respective sequences instead
                Array is now [1, 2, 4, 2, 4, 8, 3, 6, 12]
         =      get index of element in array (the index of 3 is 6)
          k/    divide by input (gives 2)
            )   increment (gives the correct answer 3)

এটি সর্বদা কার্যকর হবে তা প্রমাণ করার জন্য এটি দেখতে সহজ n <= input, কারণ তম অনুক্রমের inputপ্রথম উপাদান input। আমি প্রযুক্তিগতভাবে প্রমাণ করি নি যে এই সমাধানটি সর্বদা বৈধ, তবে আমি পরীক্ষিত প্রতিটি পরীক্ষার ক্ষেত্রে এটি পাস করে।



1

পরিষ্কার , 86 বাইট

import StdEnv
$n=hd[i\\i<-[1..]|n==while((>)n)(\j=j+sum[toInt d-48\\d<-:toString j])i]

এটি অনলাইন চেষ্টা করুন!

সম্প্রসারিত:

$ n                    // function `$` of `n` is
 = hd [                // the first
   i                   // integer `i`
  \\                   // for
   i <- [1..]          // each integer from 1 upwards
  |                    // where 
   n ==                // `n` is equal to
   while ((>) n) (     // the highest value not more than `n` from
    \j = j + sum [     // `j` plus the sum of
      toInt d - 48     // the digital value
     \\                // for each
      d <-: toString j // digit in the string form of `j`
     ]                 // where `j` is the previous term
    )                  // of the sequence
   i                   // starting with term `i`
  ]

এটি আমাকে digitToInt dদীর্ঘস্থায়ী করে তোলেtoInt d-48



1

জাভাস্ক্রিপ্ট, 65 বাইট

n=>eval('for(i=p=1;n-p;p=p>n?++i:p)for(j=p;j;j=j/10|0)p+=j%10;i')

এটি অনলাইন চেষ্টা করুন!


এটি সি হিসাবেও কাজ করে তবে আরও একটি বাইট খরচ হয়

সি (জিসিসি) , 66 বাইট

i,p,j;f(n){for(i=p=1;n-p;p=p>n?++i:p)for(j=p;j;j/=10)p+=j%10;n=i;}

এটি অনলাইন চেষ্টা করুন!


1


@ এক্সপায়ার্ডডাটা হ্যাঁ আমি কীভাবে আক্ষরিক মান x ব্যবহার করতে ভুলে গিয়েছিলাম)
ইনাত 3

1

জাপট , 15 14 বাইট

যে ঘটনাগুলি input=outputআমাকে বিরক্ত করছে সেখানে পরিচালনার তিনটি অংশ !

@Ç?X±ìx:XÃøU}a

চেষ্টা করে দেখুন

@Ç?X±ìx:XÃøU}a     :Implicit input of integer U
@                  :A function taking an integer X as its argument
 Ç                 :  Map each Z in the range [0,U)
  ?                :    If Z>0
   X±              :      Increment X by
     ì             :      Convert X to digit array
      x            :      Reduce by addition
       :X          :    Else X
         Ã         :  End map
          øU       :  Contains U
            }      :End function
             a     :Return the first integer that returns true when passed through that function

1

cQuents , 18 বাইট

#|1:#bN;A
=A?Z+UDZ

এটি অনলাইন চেষ্টা করুন!

ব্যাখ্যা

=A?Z+UDZ      second line - helper function
               first input = A
               second input = n
=A            first term is A
  ?           mode=query, return true if n in sequence, false if n not in sequence
              each term in the sequence equals
   Z+          previous term +
     U   )                     sum (                          )
      D )                            digits (               )
       Z                                      previous term

#|1:#bN;A     main program
               first input = A  (user input)
               second input = n
#|1           n = 1
   :          mode=sequence, return the nth term in the sequence
    #     )   conditional - next term equals next N that evaluates to true
              N increments, any terms that evaluate to true are added to the sequence
               conditional (                      )
     b   )                   second line (      )
      N;A                                  N, A

1

ফোরথ (গফার্থ) , 99 বাইট

: f >r 0 begin 1+ dup begin dup i < while dup 20 for 10 /mod >r + r> next + repeat i = until r> . ;

এটি অনলাইন চেষ্টা করুন!

মূলত অনুরূপ reffu এর জমা (106 বাইটস) । গল্ফযুক্ত অংশগুলি হ'ল:

  • অঙ্ক অঙ্কের গণনা (-6)
  • স্টাডাউটে কিছু আবর্জনা মুদ্রণ করে ফাইনাল ক্লিনআপ (-1)। (কোনও সমস্যা নেই কারণ ফলাফলটি স্ট্যাকের শীর্ষে ফিরে এসেছে))

কিভাবে এটা কাজ করে

: dsum ( n -- n+digitsum ) \ Sub-function. Given n, add its digit sum to n.
  dup                      \ Copy n to form ( n m ) -> extract digits from m and add to n
  20 for                   \ Repeat 20 times (a 64-bit int is at most 20 digits)
    10 /mod >r + r>        \   n += m%10, m = m/10
  next + ;                 \ End loop and discard 0

: f ( n -- ans )    \ Main function.
  >r                \ Move n to the return stack, so it can be referenced using `i`
  0 begin 1+        \ Initialize counter and loop starting from 1
    dup begin       \   Copy the counter (v) and loop
      dup i < while \     break if v >= n
      dsum          \     v += digit sum of v
    repeat          \   End loop
  i = until         \ End loop if n == v
  r> . ;            \ Cleanup the return stack so the function can return correctly
                    \ `r> .` is one byte shorter than `rdrop`

0

কাঠকয়লা , 26 বাইট

NθW¬№υθ«UMυ⁺κΣκ⊞υ⊕Lυ»I⊕⌕υθ

এটি অনলাইন চেষ্টা করুন! লিঙ্কটি কোডটির ভার্জোজ সংস্করণ। @ চ্যাসব্রাউন এর অ্যালগরিদম ব্যবহার করে। যদি এটি অবৈধ হয়ে যায়, তবে 29 বাইটের জন্য:

NθW¬№υθ«≔⊕LυηW‹ηθ≧⁺Σηη⊞υη»ILυ

এটি অনলাইন চেষ্টা করুন! লিঙ্কটি কোডটির ভার্জোজ সংস্করণ। কম সংখ্যার চেয়ে কম প্রতিটি সংখ্যার যোগফল ক্রমের প্রথম সদস্য গণনা করে কাজ করে n। ব্যাখ্যা:

Nθ

ইনপুট n

W¬№υθ«

লুপ যতক্ষণ না রয়েছে আমরা একটি সংখ্যার যোগফলের ক্রমটি পাই n

≔⊕Lυη

পরবর্তী ক্রমটি এখন পর্যন্ত সিক্যুয়েন্সের সংখ্যার চেয়ে আরও একটি দিয়ে শুরু হয়।

W‹ηθ

লুপটি যখন সিকোয়েন্সের সদস্যের চেয়ে কম হয় n

≧⁺Σηη

ক্রমের পরবর্তী সদস্য পেতে অঙ্কের যোগ যোগ করুন।

⊞υη

চূড়ান্ত সদস্যকে তালিকায় ঠেলাও।

»ILυ

গণনা করা তালিকার সংখ্যা মুদ্রণ করুন যতক্ষণ না আমরা একটি সমন্বিত পেয়েছি n




0

গাইয়া , 16 বাইট

1⟨⟨:@<⟩⟨:Σ+⟩↺=⟩#

এটি অনলাইন চেষ্টা করুন!

সবচেয়ে ছোট সংখ্যার পূর্ণসংখ্যার তালিকা উপস্থিত করে।

1⟨	      ⟩#	% find the first 1 positive integers where the following is truthy:
	     =		% DSS equal to the input?
  	    ↺		% while
  ⟨:@<⟩			% is less than the input
       ⟨:Σ+⟩		% add the digital sum to the counter

গাইয়া , 16 বাইট

1⟨w@⟨:):Σ++⟩ₓĖ⟩#

এটি অনলাইন চেষ্টা করুন!

মিঃ এক্সকোডার দ্বারা তৈরি পর্যবেক্ষণ ব্যবহার করুন । এটি অন্যটির চেয়ে কম নয়, তবে এটি একটি আকর্ষণীয় পদ্ধতির।

1⟨	      ⟩#	% find the first 1 integers z where:
  	     Ė		% the input (n) is an element of
  w@⟨:):Σ++⟩ₓ		% the first n terms of the z-th Digital Sum Sequence

গাইয়া , 16 বাইট

┅ẋ⟨@⟨:):Σ++⟩ₓĖ⟩∆

এটি অনলাইন চেষ্টা করুন!

তৃতীয় পদ্ধতিটি ব্যবহার না করে N-find, #তবে এখনও মধ্য পদ্ধতির মতো একই পর্যবেক্ষণের উপর নির্ভর করে। তালিকার চেয়ে পূর্ণসংখ্যা ফেরত দেয়।


0

ক্লোজার , 106 বাইট

#(loop[j 1 i 1](if(= j %)i(if(< j %)(recur(apply + j(for[c(str j)](-(int c)48)))i)(recur(inc i)(inc i)))))

এটি অনলাইন চেষ্টা করুন!

এটি 99 বাইট তবে বৃহত ইনপুটগুলিতে স্ট্যাক ওভারফ্লোতে ফলাফল (সম্ভবত জেভিএম টুইট করা সাহায্য করবে):

#((fn f[j i](if(= j %)i(if(< j %)(f(apply + j(for[c(str j)](-(int c)48)))i)(f(inc i)(inc i)))))1 1)



0

কালি , 130 127 বাইট

-(l)
+(i)[+]->l
*(w)[{i}]
~temp n=w
-(o){n<i:
~n+=s(n)
->o
}{n>i:->w}{w}
==function s(n)
{n>9:
~return n%10+s(n/10)
}
~return n

এটি অনলাইন চেষ্টা করুন!

  • -3 bytes সম্পূর্ণ প্রোগ্রামে রূপান্তর করে যা অ্যানারি ইনপুট নেয়।

গল্ফযোগ্য না হওয়ার জন্য এটি বেশ দীর্ঘ সময় অনুভব করে।

Ungolfed

// This program takes unary input. It passes through the same choice prompt as long as it recieves 1, and execution begins when it recieves 2
-(input_loop)
+(input_value)[+] -> input_loop                 // When this option (option 1) is selected, its read count is incremented. We can access this via the "input_value" variable. We then return to the prompt by going back to the "input_loop" gather
*(which_sequence)[{i}]                          // When this option (option 2) is selected, execution begins. Its read count also serves to keep track of which DSS we're checking.
~temp current_value = which_sequence            // The initial value for the n-DSS is n, of course.
-(sequence)                                     //
{current_value < input_value:                   // If we're still below the value we're looking for, we might find it.
    ~ current_value += digit_sum(current_value) // To get the next number, we add the current number's digit sum
    -> sequence                                 // Then we loop
}
{n > i: -> which_sequence}                      // If we get here, we're at or above our target number. If we're above it, we know it's the wrong sequence and move on to the next one by going back up to option 2. This increments its read count.
{which_sequence}                                // If we get here, we've found the target number, so we output the sequence's number.
// End of main stitch, program ends.

// A function to calculate the digit sum of a number
== function digit_sum(n) ==
{n > 9: // If given a number greater than 9, recurse
    ~ return (n % 10) + digit_sum(n / 10)
}
~ return n // Otherwise, return the input (it's a single digit)

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.