দীর্ঘতম অ-পুনরাবৃত্তি সাবস্ট্রিং


33

ইনপুট হিসাবে একটি স্ট্রিং দেওয়া দীর্ঘতম সুসংগত সাবস্ট্রিং সন্ধান করুন যার দু'বার বা তার বেশি অক্ষর নেই। যদি এমন একাধিক সাবস্ট্রিং থাকে তবে আপনি আউটপুটও করতে পারেন। আপনি ধরে নিতে পারেন ইনপুটটি প্রিন্টযোগ্য এএসসিআইআই রেঞ্জের মধ্যে রয়েছে যদি আপনি চান।

স্কোরিং

উত্তরগুলি প্রথমে তাদের নিজস্ব দীর্ঘতম অ-পুনরাবৃত্ত সাবস্ট্রিংয়ের দৈর্ঘ্য এবং তারপরে তাদের মোট দৈর্ঘ্য অনুসারে স্থান পাবে। লোয়ার স্কোর দুটি মানদণ্ডের জন্য আরও ভাল হবে। ভাষার উপর নির্ভর করে এটি সম্ভবত উত্স সীমাবদ্ধতার সাথে চ্যালেঞ্জের মতো অনুভব করবে ।

ক্ষুদ্রতা

কিছু ভাষায় 1, x (ল্যাঙ্গুয়েজ) বা 2, এক্স (মস্তিষ্ক-ফ্লাক এবং অন্যান্য টিউরিং টারপাইটস) এর স্কোর অর্জন করা বেশ সহজ, তবে এমন আরও কিছু ভাষা রয়েছে যেখানে দীর্ঘতম পুনরাবৃত্তি না করা স্ট্রস্ট্রিংকে হ্রাস করা একটি চ্যালেঞ্জ। হাসকেলে আমি 2 টি স্কোর পেয়ে অনেক মজা পেয়েছিলাম, তাই আমি আপনাকে ভাষাটি অনুসন্ধান করতে উত্সাহিত করি যেখানে এই কাজটি মজাদার।

পরীক্ষার মামলা

"Good morning, Green orb!" -> "ing, Gre"
"fffffffffff" -> "f"
"oiiiiioiiii" -> "io", "oi"
"1234567890"  -> "1234567890"
"11122324455" -> "324"

স্কোরিং জমা

আপনি নিম্নলিখিত স্নিপেট ব্যবহার করে আপনার প্রোগ্রামগুলি স্কোর করতে পারেন:


প্রস্তাবিত পরীক্ষার কেস: 11122324455জোনাথন অ্যালান বুঝতে পেরেছিলেন যে আমার প্রথম সংশোধনটি এটি সঠিকভাবে পরিচালনা করে না।
ডেনিস

@ ডেনিস টেস্ট কেস যুক্ত হয়েছে। আমি কী কৌতূহল করছি কিভাবে এটি ঘটেছে।
গম উইজার্ড

2
আমি সমস্ত সাবস্ট্রিং তৈরি করেছি (ইতিমধ্যে দৈর্ঘ্য অনুসারে বাছাই করা), তারপরে সাবস্ট্রিংগুলি প্রতিলিপি এবং সেগুলি সাবস্ট্রিংগুলি রেখেছি। দুর্ভাগ্যক্রমে, এটি আদেশ পরিবর্তন করে; 11122ocurrs পরে 324, কিন্তু প্রতিলিপি হয়ে যায় 12
ডেনিস

আমি ভাবছি সাদা জায়গাটির উত্তর কোথায়।
ম্যাজিক অক্টোপাস উরন

উত্তর:


13

সি, স্কোর 2,  747   720  662 বাইট

L  [  1  <<  7  ]  ,  *  q  ,  *  r  ,  l  ,  d  ,  i  ,  c  ,  j  ,  s  ,  t  ,  k  =  1  <<  7  ;  h  (  )  {  q  =  s  +  i  +  j  ++  ;  *  q  %  k  &&  !  L  [  *  q  %  k  ]  ++  &&  h  (  ++  c  )  ;  }  g  (  )  {  q  =  s  +  i  ;  *  q  %  k  ?  z  (  k  )  ,  h  (  j  =  c  =  0  )  ,  c  >  d  &&  (  d  =  c  )  &&  (  l  =  i  )  ,  g  (  ++  i  )  :  0  ;  }  f  (  S  ,  T  )  {  s  =  S  ;  l  =  i  =  d  =  0  ;  g  (  t  =  T  )  ;  p  (  i  =  0  )  ;  }  p  (  )  {  q  =  s  +  l  +  i  ;  r  =  t  +  i  ;  i  ++  <  d  ?  p  (  *  r  =  *  q  )  :  (  *  r  =  0  )  ;  }  z  (  i  )  {  L  [  --  i  ]  =  0  ;  i  &&  z  (  i  )  ;  }

কমপক্ষে 32-বিট MinGW এ কাজ করে (অপ্টিমাইজেশন অক্ষম সহ)। একটি কীওয়ার্ড ব্যবহার করে না।

জিসিসি এবং ঝনঝনির সাহায্যে টিআইওতে দৃশ্যত কাজ করে: এটি অনলাইনে চেষ্টা করে দেখুন! (ধন্যবাদ @ ডেনিস!)

সাথে কল করুন:

int main()
{
    char str[1024];

    f("Good morning, Green orb!", str);
    puts(str);

    f("fffffffffff", str);
    puts(str);

    f("oiiiiioiiii", str);
    puts(str);

    f("1234567890", str);
    puts(str);

    f("L  [  1  <<  7  ]  ,  *  q  ,  *  r  ,  l  ,  d  ,  i  ,  c  ,  j  ,  s  ,  t  ,  k  =  1  <<  7  ;  h  (  )  {  q  =  s  +  i  +  j  ++  ;  *  q  %  k  &&  !  L  [  *  q  %  k  ]  ++  &&  h  (  ++  c  )  ;  }  g  (  )  {  q  =  s  +  i  ;  *  q  %  k  ?  z  (  k  )  ,  h  (  j  =  c  =  0  )  ,  c  >  d  &&  (  d  =  c  )  &&  (  l  =  i  )  ,  g  (  ++  i  )  :  0  ;  }  f  (  S  ,  T  )  {  s  =  S  ;  l  =  i  =  d  =  0  ;  g  (  t  =  T  )  ;  p  (  i  =  0  )  ;  }  p  (  )  {  q  =  s  +  l  +  i  ;  r  =  t  +  i  ;  i  ++  <  d  ?  p  (  *  r  =  *  q  )  :  (  *  r  =  0  )  ;  }  z  (  i  )  {  L  [  --  i  ]  =  0  ;  i  &&  z  (  i  )  ;  }");
    puts(str);
}

আউটপুট:

সামান্য আরও পঠনযোগ্য ফর্ম্যাটিং সহ কোড:

L[1<<7],
*q, *r, l, d, i, c, j, s, t, k=1<<7;

h()
{
    q = s+i+j++;
    *q%k && !L[*q%k]++ && h(++c);
}

g()
{
    q = s+i;
    *q%k ? z(k), h(j=c=0), c>d && (d=c) && (l=i), g(++i) : 0;
}

f(S, T)
{
    s = S;
    l = i = d = 0;
    g(t=T);
    p(i=0);
}

p()
{
    q = s+l+i;
    r = t+i;
    i++<d ? p(*r=*q) : (*r=0);
}

z(i)
{
    L[--i] = 0;
    i && z(i);
}

এবং এটি স্কোর 2 সহ ফর্ম্যাটিংয়ে পেতে যথাযথ ব্যবধান তৈরি করতে ব্যবহার করা যেতে পারে: অনলাইনে চেষ্টা করে দেখুন!


সি, স্কোর 3, 309 বাইট

i
,
j
,
l
,
c
,
d
;
f
(
\
c\
\
h\
\
a\
\
r
*
s
)
{
\
f\
\
o\
\
r
\
(
i
=
l
=
d
=
0
;
s
[
i
]
;
c
>
d
&&
(
d
=
c
)
&&
(
l
=
i
)
,
++
i
)
\
f\
\
o\
\
r
(
\
c\
\
h\
\
a\
\
r

L
[
\
1\
\
2\
\
8
\
]
=
{
j
=
c
=
0
}
;
s
[
i
+
j
]
&&
!
L
[
s
[
i
+
j
++
]
]
++
;
++
c
)
;
\
w\
\
r\
\
i\
\
t\
\
e
(
1
,
s
+
l
,
d
)
;
}

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


10

হাস্কেল , স্কোর 2, 492 ... 307 224 212 209 207 বাইট

((yy:yyy))??ss|ss==yy  =  ""  |  yy==yy=yy:yyy??ss
ss??sss=ss
ss""=""

ss((ff:fff))  =  ff  :  ss  fff??ff
ff""=""

ff((xxx:xx))  =  ss((xxx:xx))##ff  xx
xx##xxx  |  ((((xx>>xx))<))  $  xxx>>xx=xxx|xx==xx=xx

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

থেকে বাইট ধন্যবাদ আক্ষরিক Golfed শত শত ডব্ল্যু এবং Orjan Johansen !

ব্যাখ্যা

ফাংশনটি (??)একটি অক্ষর cএবং একটি স্ট্রিং নেয় sএবং এতে থাকা দীর্ঘতম উপসর্গটি sদেয় না c। অসমাপ্ত এবং স্কোরের জন্য অনুকূলিত করা হয়নি:

c ?? (y:s)  
    | c==y = ""
    | True = y : c ?? s
c ?? s = s

ফাংশনটি প্রদত্ত স্ট্রিংয়ের অনন্য চরিত্রের দীর্ঘতম উপসর্গ সন্ধান করতে ssব্যবহার (??)করে:

ss (x:r) = x : (x ?? ss r)
ss "" = ""

(##)এটি একটি ফাংশন যা দুটি স্ট্রিং নেয় এবং দীর্ঘতরটি প্রদান করে। দৈর্ঘ্য তুলনা স্ট্রিং পুনরাবৃত্তি করে কাজ করে xযতবার xদীর্ঘ ( x>>y) এবং যেমন y(হয় দীর্ঘ y>>x) এবং পরীক্ষণ যা ফলে স্ট্রিং lexicographically বড়।

x ## y
  | (x>>x) < (y>>x) = y
  | True = x

অবশেষে ffইনপুট স্ট্রিংয়ের উপর ssপুনরাবৃত্তি ঘটে, এর সাথে দীর্ঘতম উপসর্গ উত্পন্ন করে , পুনরাবৃত্তভাবে স্ট্রিংয়ের লেজের দীর্ঘতম অ-পুনরাবৃত্তিযুক্ত স্তরটি নির্ধারণ করে এবং এর সাথে দু'টির দীর্ঘতর প্রত্যাবর্তন করে (##):

ff "" = ""
ff (x:r) = ss(x:r) ## ff r

4
224 , প্রধানত মধ্যবর্তী তালিকা দূরীকরণের মাধ্যমে।
র্জন জোহানসেন

2
আমি এই উত্তরটি আগে একবার চ্যাটে পোস্ট করেছি তার সাথে মিলিয়ে 216 পেয়েছি ।
গম উইজার্ড

3
209 জিনিসগুলিকে পুনরায় অর্ডার করে।
janrjan জোহানসেন

3
অনুগ্রহের ঘোষণার সাথে আমি আরও একবার নজর দিয়েছি এবং বুঝতে পারি যে @কৌশলটি 2 টি বাইট মাত্র ?দুটি চর তৈরির চেয়ে বেশি ব্যয় করেছে : 207
Ørjan জোহানসেন

5

লুয়া, স্কোর 3, 274 বাইট

g='g'..'s'..'u'..'b'  _G  [  'l'..'o'..'a'..'d'  ](  g[g  ](  "s  =...f  o  r d = # s - 1 , 0 , - 1 d  o f  or r = 1 , # s - d d  o t = s :s  ub  (r  ,r  +d  )i  f n  ot t:  fi  nd  '(  .)  .*  %1  't  he  n p  ri  nt  (t  )r  et  ur  n en  d e  n  d e  nd  ","  ",""))(...)

দ্রষ্টব্য: লুয়া 5.2 বা লুয়া 5.3 প্রয়োজন

ব্যবহার:

$ lua lnrs.lua "Good morning, Green orb!"
ing, Gre
$ lua lnrs.lua "fffffffffff"
f
$ lua lnrs.lua "oiiiiioiiii"
oi
$ lua lnrs.lua "1234567890"
1234567890
$ lua lnrs.lua "11122324455"
324

মূল ধারণা: সবকিছু ফাঁকা করে সন্নিবেশ করান " " দীর্ঘ শনাক্তকারীদের বিভক্ত করতে ফাঁকা (দুটি স্পেস)

অবরুদ্ধ কোড:

g = "gsub"
_G["load"](
   g[g](      -- g[g] == string.gsub - a function for substitution of substrings
      "The source of actual program, but two-space sequences were inserted in some places", 
      "  ",   -- we are replacing all two-space substrings
      ""      -- with an empty string
   )
)(...)

আসল প্রোগ্রাম (সমস্ত জোড়া স্পেস সরানোর পরে):

s = ...
for d = #s - 1, 0, -1 do
   for r = 1, #s - d do
      t = s:sub(r, r+d)
      if not t:find"(.).*%1" then
         print(t)
         return
      end
   end
end

বিটিডাব্লু, স্কোর গণনার জন্য জেএস স্নিপেটটি আমার কোডটিতে ব্যর্থ।


4

রেটিনা 0.8.2 , 37 বাইট, স্কোর 9

.
$&$'¶
(.)(?<=\1.+).*

O#$^`
$.&
1G`

এটি অনলাইন চেষ্টা করুন! রেটিনা 1-এর এই উত্তরের সরাসরি অনুবাদ Nপরিবর্তে ব্যবহার করে একটি বাইট সংরক্ষণ করে O#। যাইহোক, আপনি যদি নির্লজ্জভাবে গল্ফ দিয়ে রেটিনা 1 উত্তরটি 28 বাইটে নামিয়ে দেন তবে এর স্কোরটি 10 ​​টিতে পৌঁছে যাবে! ব্যাখ্যা:

.
$&$'¶

ইনপুটটির সমস্ত প্রত্যয় তৈরি করুন।

(.)(?<=\1.+).*

প্রতিটি প্রত্যয়টির জন্য প্রথম সদৃশ চরিত্রের উপসর্গ গ্রহণ করুন।

O#$^`
$.&

অবশিষ্ট স্ট্রিংগুলি দৈর্ঘ্যের বিপরীত ক্রমে বাছাই করুন (যেমন দীর্ঘতম প্রথম)।

1G`

দীর্ঘতম নিন।


4

জেলি , স্কোর 2, 14 বাইট

Ẇµµff  Q  €  Ṫ

স্কোর -1, +7 বাইট এবং একটি বাগ লক্ষ্য করার জন্য @ জোনাথন অ্যালানকে ধন্যবাদ

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

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

Ẇµµff  Q  €  Ṫ  Main link. Argument: s (string)

Ẇ               Window; yield all substrings of s, sorted by length.
 µ              Begin a new chain. Argument: A (array of substrings)
  µ             Begin a new chain. Argument: A (array of substrings)
   f            Filter A by presence in itself. Does nothing.
       Q  €     Unique each; deduplicate all strings in A.
    f           Filter A by presence in the array of deduplicated substrings,
                keeping only substrings composed of unique characters.
             Ṫ  Tail; take the last (longest) kept substring.

4

পরিষ্কার , 7 5, 276 বাইট স্কোর

@[ss:s]=rr(pp[][ss:s])((@s))
@s=s
ee x[rr:xx]|e x rr=True=ee x xx
ee x xx=f
f=e'e'' '
e::!  Char  !  Char  ->Bool
e  _ _=  code  {

eqC
}
pp p[r:rr]|ee r p=p=pp(a r p)rr
pp a _=a
a  x[ll:l]=[ll:a x  l]
a l ll=[l]
l[]rr=e'l''l'
l ff[]=f

l[r:rr][ss:ll]=l rr ll
rr x y|l x y=y=x

এটি অনলাইন চেষ্টা করুন! @ Οurous কে আমাকে দেখানোর জন্য ধন্যবাদ যে ক্লিনের মধ্যে থেকে সরাসরি এবিসি মেশিন কোড কল করা সম্ভব। এটি আগের বোতল-ঘাড় থেকে মুক্তি পেতে দেয় importযা সর্বনিম্ন স্কোরটি 7 এ codeসেট করে তবে কীওয়ার্ডের প্রয়োজন যা এই পদ্ধতির জন্য সর্বনিম্ন স্কোর 5 এ সেট করে।

উপরের কোডটির একটি নিরবচ্ছিন্ন এবং স্কোর-অনুকূলিত সংস্করণটি এখানে পাওয়া যাবে: এটি অনলাইনে চেষ্টা করুন!


স্কোর 7, 158 154 130 বাইট সহ পূর্ববর্তী সংস্করণ

import  StdEnv  
@[xx:rr]=c(%[][xx:rr])(@rr)
@e=e
c s b|  length  s<  length  b=b=s
%s[xx:r]|  isMember xx s=s= %(s++[xx])r
%r _=r

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

সঙ্গে importস্কোর আমদানি ছাড়াই 7. নিচের চলতে পারে না কোনো লাইব্রেরি ফাংশন যা ছাড়া স্ট্রিং বা অক্ষর উপর সমতা বাস্তবায়ন করতে হবে সম্ভবত না সম্ভব, উপরের হিসাবে নতুন সংস্করণে দেখা যায়।


1
আপনি প্রকৃতপক্ষে ইনলাইন এবিসি ব্যবহার করে সাম্যতা প্রয়োগ করতে পারেন, যা স্কোর হ্রাস করা উচিত। আপনি আগ্রহী হলে আমি আজই একটি প্রস্তাবিত পরিবর্তন নিয়ে ফিরে আসব।
15urous

উদাহরণস্বরূপ: চর সমতা: tio.run/##S85JTcz7/…
Feburous

@ অররাস A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!( ক্লোগল থেকে ) অবশ্যই আমন্ত্রণ জানায়। আমি আগামীকাল এটি সন্ধান করব, পরামর্শের জন্য ধন্যবাদ!
লাইকনি

1
@ Ousurous আবারও ধন্যবাদ, আপনার চর সমতা পরীক্ষা দিয়ে স্কোর এখন 5 এ
লাইকোনি

ঘটনাচক্রে, আপনার কোনও -ILপতাকা লাগবে না , যেহেতু কিছুই আমদানি করা হচ্ছে না।
26urous

3

পাইথন 3 , স্কোর 4, 155 বাইট

exec(('l=la''mbd''a f'',e=en''ume''rat''e:m''ax''([f[ j  :k]  for  j,i in e ( f)f''or  k,i in e ( f )if  len  ( { *''f[j'':k]''})==k-''j],''key''=le''n)'))

এটি একটি ফাংশন সংজ্ঞায়িত করে l

@ এক্সনোরকে 3 ইঞ্চি দৈর্ঘ্যের স্ট্রিং 32 স্কোর বাড়াতে স্কোর বাড়াবে না বলে ধন্যবাদ জানাতে ধন্যবাদ।

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


স্ট্রিং 3 এর অংশ হতে পারে, তাই না?
xnor

@ এক্সনর ফাংশনটির নাম পরিবর্তন করছেন indeed ধন্যবাদ!
ডেনিস

3

ব্র্যাচেল্যাগ , স্কোর 2, 19 বাইট

s  ᶠ  l  ᵒ  ≠  ˢ  t

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

একটি বিরক্তিকর পুরানো "স্পেস সবকিছু আউট" উত্তর " কমপক্ষে আমি শিখেছি যে মেটাপ্রেডিকেটগুলি পূর্বাভাসগুলি থেকে দূরে থাকতে পারে এবং এখনও কাজ করতে পারে (এবং (প্যারামেট্রিক) সাবস্ক্রিপ্ট এবং সুপারস্ক্রিপ্টগুলি পারে না)।

s ᶠ - প্রদত্ত স্ট্রিংয়ের সমস্ত সাবস্ট্রিংগুলি সন্ধান করুন

l ᵒ - তাদের দৈর্ঘ্য অনুসারে অর্ডার করুন (ডিফল্ট অনুসারে আরোহণ)

≠ ˢ - সমস্ত স্বতন্ত্র উপাদান আছে তাদের নির্বাচন করুন

t - এর লেজ (শেষ উপাদান) পান - সবচেয়ে বড় দৈর্ঘ্যের সাথে একটি



2

হুস্ক , স্কোর 2, 10 বাইট

►IIËII≠IIQ

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

ব্যাখ্যা

প্রোগ্রামটি এর সমতুল্য:

►Ë≠Q  Implicit input.
   Q  List of substrings.
►     Find one that maximizes:
 Ë    all ordered pairs
  ≠   are inequal.

অন্তর্নির্মিত তার তর্কযুক্ত সমস্ত আদেশযুক্ত জোড়গুলির Ëমূল্যায়ন করে xএবং length(x)+1যদি প্রতিটি ফলাফল সত্যবাদী হয় তবে তা ফিরিয়ে দেয়0. When we maximize this, we find the longest string that has no repeated characters.

জমা দেওয়ার ক্ষেত্রে, আমি কেবল Iপ্রতিটি ফাংশনের মধ্যে দু'বার পরিচয় ফাংশন সন্নিবেশ করি । যেহেতু একই Ë, I≠একই রকম এবং তাই, এটি শব্দার্থবিজ্ঞানের কোনও পরিবর্তন করে না। একমাত্র বিপদটি হ'ল উচ্চতর অর্ডার ফাংশনটি এর একটিকে Iতার যুক্তি হিসাবে ব্যবহার করার সিদ্ধান্ত নিতে পারে তবে ভাগ্যক্রমে এটি আমাদের প্রোগ্রামে একটি ধরণের ত্রুটির দিকে পরিচালিত করে, তাই এটি ঘটে না।


2

Clojure, score 4

#(  let  [N  (fn  [[_ & r]] r) R  (fn  R [f v c]  (if  c (R f (f v (  nth  c 0))  ( N  c)) v)) C  (fn  C  (  [i]  (C (  seq  i) 0)) ( [i  n]  (if i (C ( N  i )  (  inc n)) n)))  J  (fn  [c  i]  (assoc c (C  c) i)) I  (fn  F [f i n R]  (if ( =  (C  R) n) R (F f (f  i) n ( J  R (f  i)))))] ( apply  str  (R ( fn  [a  b] ( if  (< (C  a)  (C  b)) b a )) "" (  for  [k  (I N % (C  % ) [])]  (R  ( fn [ t  c ] ( if ( or ( = t (  str t) ) ((  set t)c))(apply  str t) ( J  t c)))[]k)))))

Oh man this was painful! N implements next, R is reduce, C is count, J is conj (works only for vectors) and I is iterate. apply str is there twice because otherwise "aaaa" input wouldn't return a string but a vector [\a]. Luckily I got to use apply and assoc, I didn't know you could assoc one index beyond a vector's last element :o


I shaved off some space: Try it online!
Ørjan Johansen


1

Python 3, score 4, 317 bytes

exec(('%s'  *58  %(  's=','in','pu','t(',');','pr','in','t(','so','rt','ed','((s','[i',':j',']f','or',' j',' i','n ','ra','ng','e(','1,','le','n(','s)','+1',')f','or',' i',' i','n ','ra','ng','e(','j)','if',' l','en','(s','et','(s','[i',':j',']))','==l','en','(s','[i',':j',']))',',k','ey','=l','en',')[','-1','])')))

Try it online!

Unexeced code:

s=input();print(sorted((s[i:j]for j in range(1,len(s)+1)for i in range(j)if len(set(s[i:j]))==len(s[i:j])),key=len)[-1])

lambda a contains mbda which has score 5, and a function needs return which apparently can't be execed (so takes a score of at least 5 for eturn), so a full program was necessary. It's probably possible to golf down the unexeced code size quite a bit, but I can't see a quick clear improvement.


1

Alice, 40 bytes

/ii..nn$$@@BBww..DD~~FF..!!nn$$KK??oo@@

(Trailing newline)

Try it online!

The instruction pointer moves diagonally in ordinal mode, so only every other character is executed.

i.n$@Bw.D~F.!n$K?o@

i     take input
.n$@  terminate if empty
B     push all nonempty substrings, with the longest on the top of the stack
w     push return address (start main loop)
.     make copy of current substring
D     deduplicate characters
~     swap: this places the original above the deduplicated copy
F     Push the original string if it is a substring of the deduplicated copy
      (which can only happen if they're equal); otherwise push empty string
.!    place a copy on the tape
n$K   if the empty string was pushed, return to start of loop
o     output
@     terminate

1

Perl 6, score: 15 10 8, length: 46 55 62 bytes

{~m:ov/(.+)<!{$0.comb.repeated}>/.max(&chars)}

Test it

{~m:ov/(..*)<!{(($0)).comb.repeated}>{{}}/.max(&chars)}

Test it

{m:ov:i/(..*)<!{(($0)).comb.repeated}>{{}}/.max((&chars)).Str}

Test it

Expanded:

{    # bare block lambda with implicit parameter 「$_」

    m                          # match (implicitly against 「$_」)
    :overlap                   # in every single way possible
    :ignorecase                # add a 「:」 to break up substring
    /

      (..*)                    # match at least one character

      <!{
        (($0)).comb.repeated  # backtrack if there were repeats
      }>

      {{}}                    # anon hash in code block (no-op)
    /

    .max((&chars))            # get the longest

    .Str                      # coerce to a Str (from a Match object)
}

Score of 5 for 88 bytes. There might be a few places to golf bytes though
Jo King

1

Java 8, score 9 (384 B) 7 (401 B)

S -> { int s = 0 , e = 0 , l = 0 , x = 0 , y = 0 , b [ ] = new int [ 256 ] ; for ( ; x <S.  length  & y <S.  length  & l <S.  length  - x ; x ++ ) { b [S[x]] = 1 ; for ( y ++ ; y <S.  length  && b [S[y]] < 1 ; b [S[y ++]] = 1 ) ; if ( l < y - x ) { s = x ; e = y ; l = y - x ; } for ( ; y <S.  length  && x < y & S[x] != S[y  ];)b [S[x ++]] = 0 ; }  String g=""; for( ; s<e ; g+= S[s++]);  return  g;}
  • Initial version. Will go down from here. Score is 9 due to "ubstring ", so substring will be the first part to replace.
  • Score is now 7 due to " length", which I probably won't be able to reduce further.. I doubt it is possible to drop the four uses of length. If it is possible, " eturn" (6) might lower the score by 1 as final improvement, but I guess this is it (except maybe a small reduce in byte-count..)

Try it online.



0

Mathematica, score 11 9

Length@Last@Select[Subsequences[Characters@#],#==DeleteDuplicates  @#&]&

Shaving a couple of bytes off of the longest nonrepeating string by obscuring the function's name:

Length@Last@Select[Subsequences[Characters  @#],#==(  ToExpression@ 
StringJoin@@FromCharacterCode@{{68},{101},{108},{101},{116},{101},{68},{117},
{112},{108},{105},{99},{97},{116},{101},{115}}))@#&]&

0

Kotlin, score: 11 10 9 bytes, length: 227 246 245 bytes

indices
  .flatMap { p -> indices . map { p to p + it } }
  .  filter { (r,i) -> i < length  }
  .map { ( s , a )->substring  (  s,  a  ) }
  .  filter { it  .  groupBy  { it } .  none { ( k , v )->v . size>1 } }
  .maxBy { it.length }

The longest is ubstring, which is 9 chars

It is called like this:

val c = "Good morning, Green orb!"

fun String.c(): String? = indices
    .flatMap { p -> indices . map { p to p + it } }
    .  filter { (r,i) -> i < length  }
    .map { ( s , a )->substring  (  s,  a  ) }
    .  filter { it  .  groupBy  { it } .  none { ( k , v )->v . size>1 } }
    .maxBy { it.length }

fun main(args: Array<String>) {
    val text = """indices
    .flatMap { p -> indices . map { p to p + it } }
    .  filter { (r,i) -> i < length  }
    .map { ( s , a )->substring  (  s,  a  ) }
    .  filter { it  .  groupBy  { it } .  none { ( k , v )->v . size>1 } }
    .maxBy { it.length }"""
    val message = text.c()!!
    println(message)
    println(text.length)
    println(message.length)
    println(c.c())
}

Aren't you able to reduce it to 10 by adding an additional space between roupingBy and {?
Kevin Cruijssen

1
Nice find, I changed the other 11s and and got down to 10
jrtapsell

It is 10 chars, but the longest substring isn't roupingBy (which is 9 chars) but eachCount (with trailing space).
Erik the Outgolfer

roupingBy has a trailing space (visible in the markdown, but the renderer seems to strip it)
jrtapsell

Managed to reduce it to 9, fixing the trimming issue
jrtapsell


0

05AB1E, 22 bytes | Score: 2

Œ  ʒ  D  Ù  Q  }  é  ¤

-1 score + 7 bytes thanks to HeebyJeeby

Try it online!


05AB1E, 15 bytes | Score: 3

Œ ʒ D Ù Q } é ¤

Try it online!


05AB1E, 8 bytes | Score: 8

ŒʒDÙQ}é¤

Try it online!


05AB1E can actually do something rather cheap... adding whitespace into 05AB1E does nothing.

If there is a rule against this, I can also use ´ and like 7 other chars.


1
@HeebyJeebyMan because I'm a moron, got a problem with that?
Magic Octopus Urn

@HeebyJeebyMan kidding haha, thanks for the idea.
Magic Octopus Urn
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.