New answers tagged

2

Java 8, 50 bytes a->b->a.map(v->v-1).sum()%9==b.map(v->v-1).sum()%9 Inputs in uppercase as character-Streams. Port of @fireflame241's Jelly answer, so make sure to upvote him! Try it online. Explanation: a->b-> // Method with two IntStream parameters & boolean return-type a.map(v-> // Map over ...


0

Pyth, 12 bytes }5[sQaFQ+4l{ Try it online! }5[sQaFQ+4l{ }5[sQaFQ+4l{Q) // Implicit input and closed brace [ ) // Create an array of the following: sQ // Sum of input aFQ // Absolute difference of input +4l{Q // Length of unique values in input, + 4 }5 // Is '5' in the array?


1

C (gcc), 67 bytes Takes two lowercase strings and returns 0 if they match, non-zero otherwise. Uses the method from @fireflame241's answer. i;g(char*s){for(i=0;*s;i+=(2+*s++)%9+1);s=i%9;}f(s,t){s=g(s)-g(t);} Try it online!


0

Desmos, 90 bytes A pretty straightfoward solution, could definitely by golfed further: f(a,b)=\left\{a+b=5:0,1\right\}\left\{\left|a-b\right|=5:0,1\right\}\left\{a=b:0,1\right\} Try It On Desmos! 0 is true, and 1 is false.


3

Perl 5 -MList::Util=sum -p, 61 bytes y/a-z/1-91-91-8/;s|\d+|sum$&=~/./g|ge while/\d\d/;$_=/(.) \1/ Try it online!


2

Haskell, 44 bytes a#b=o a-o b o s=sum[fromEnum c-1|c<-s]`mod`9 Try it online! Infix function expecting two UPPERCASE strings: returns 0 if compatible or any value if not. Inspired by @fireflame241 insights: https://codegolf.stackexchange.com/a/215456/84844


4

K (oK), 10 9 bytes =/9!+/'3+ Try it online! Another port of fireflame241's answer.


2

Scala, 27 bytes Uses fireflame241's approach. _.map(_.map(3+).sum%9).size Try it online! Accepts input as a Set of lowercase strings. Returns 2 if inputs are not compatible, 1 if they are. I'll probably go to hell for my abuse of the rules here.


4

Wolfram Language (Mathematica), 32 27 bytes 9∣(#-#2&@@FromDigits/@#)& Try it online! Takes a list containing two strings. Inspired by Neil's Charcoal solution: FromDigits still recognizes a=10, b=11, etc., even if those digits are not present in the base (by default, it interprets its input base 10).


3

Python 2, 61 \$\cdots\$ 53 51 bytes Saved a byte thanks to ovs!!! Saved 2 bytes thanks to Dingus!!! lambda t:len({sum(ord(c)+3for c in w)%9for w in t}) Try it online! Inputs a tuple of two strings in lowercase and returns \$1\$ if they are compatible or \$2\$ otherwise.


4

Husk, 11 8 bytes -7 bytes after looking at fireflame241's answer -3 bytes thanks to Dominic van Essen Ëo%9ṁo←c Try it online! Needs the input a list of uppercase words. Ëo%9ṁo←c ṁ Map each word and sum the results c Get integer value of character o← And decrement ȯ%9 Take that modulo 9 Ë Check if they're equal


2

Ruby 2.7, 89 \$\cdots\$ 55 52 41 bytes Saved a whooping 34 bytes, thanks to fireflame241's answer! Saved extra 11 bytes, thanks to Dingus! ->w{!w.map{|s|s.bytes.sum{_1-6}%9}.uniq!} Try it online! This outputs with the boolean values swapped! In Ruby 2.7, we can use _1 in place of |c|c to save 2 bytes.


2

Charcoal, 13 bytes ¬﹪⁻⍘S³⁷⍘S³⁷¦⁹ Try it online! Link is to verbose version of code. Takes input in lower case. Outputs a Charcoal boolean, i.e. - for compatible, nothing if not. Explanation: S First input string ⍘ ³⁷ Interpret as base 37 ⁻ Subtract ⍘S³⁷ Second input string as base 37 ﹪ ⁹ Reduced ...


1

JavaScript (ES6),  80 79 65  63 bytes Saved 14 bytes by using @fireflame241's insight Saved 2 more bytes thanks to @Neil Expects (a)(b). Returns a Boolean value. a=>b=>(g=s=>[...s].map(c=>t+=parseInt(c,36),t=0)&&t%9)(a)==g(b) Try it online!


3

Retina 0.8.2, 31 30 bytes +T`_l`dl . $* 1{9}|(1*)¶\1 ^$ Try it online! Takes input on separate lines, but link includes header which lowercases the test suite and splits on , for convenience. Explanation: +T`_l`dl Retina 0.8.2 doesn't have Y, but fortunately we can just repeatedly transliterate 9 digits at a time, shuffling the letters back 9 places in ...


12

Jelly, 6 bytes O’§%9E Try it online! All Tests. We take input in capital letters. The key insight here is to note (ref. en.wikipedia.org/wiki/Digital_root that the digital root of \$n>0\$ is \$n\mod 9\$ except if \$n\$ is a multiple of 9, at which case it is 9. However, we only care if the digital roots are equal, so we can treat the digital root as \$n\...


1

Wolfram Language (Mathematica), 66 bytes SameQ@@(Tr@*IntegerDigits~FixedPoint~Tr@#&/@LetterNumber@#~Mod~9)& Try it online! thanks @att


2

Retina, 31 bytes Y`l_`1-9 {`\d * )`_+ $.& (.) \1 Try it online! A direct implementation of the given algorithm. Outputs 0/1 indicating incompatible/compatible taking the argument in lower case. Explanation Y`l_`1-9 Transliterate cyclically the sets a-z_ to 1-9. Here, the underscore is not a real character but a dummy, not that it particularly matters. ...


4

05AB1E, 12 11 bytes Takes input as lists of lists of characters. -1 byte thanks to Kevin Cruijssen! ÇÌ9%>ΔO€S}Ë Try it online! Commented: €Ç # convert both words to codepoint lists a->97, b->98, ... Ì # add 2 to each number a->99, b->100, ... 9% # modulo 9 a-...


2

Python 3, 203 145 bytes -58 bytes thanks to @caird coinheringaahing def f(a): x,y=[sum((ord(i)-97)%9+1for i in z)for z in a] g=lambda t:sum(int(i)for i in str(t)) while x>9:x=g(x) while y>9:y=g(y) return x==y Try it online!


3

J, 15 bytes Based on fireflame241's Jelly answer. =&(9|1#.3+3&u:) Try it online! Original approach: J, 29 bytes -2 after reading ovs' answer: (x-97)|9 = (x+2)|9 =&(1(,.&.":@#.^:_)1+9|2+3&u:) Try it online! =&(1(,.&.":@#.^:_)1+9|2+3&u:) f&( g ) call g on both arguments, then call f ...


2

R, 106 105 95 bytes Edit: -10 bytes thanks to Giuseppe function(c,a,s=sapply,b=a[[which.max(colSums(s(a,'%in%',x=c)))]])c(c,b[0:-max(s(c,match,b,0))]) Try it online! How? chat= function(c,a, # c=curr_conv, a=all_conv s=sapply, # alias to sapply() function d<-colSums(sapply(a,`%in%`,x=c)) # d=number of ...


2

Ruby 2.7, 72 bytes ->(a,c,f=a.max_by{(_1&c).size}){c+f[f.rindex{(c&f).any?_1}+1..]rescue c} Try it online! TIO uses an older version of Ruby, so _1 is used in place of |i|i, saving 2 bytes, twice. Further, endless range i.. is used instead of i..-1, saving 2 more bytes.


1

Charcoal, 45 bytes Fθ⊞υΣEη∧№ικ⁼λ⌕ηκ≔§θ⌕υ⌈υθF✂θ∨⌈ΦEη⌈⊕⌕AθιιLθ⊞ηιη Try it online! Link is to verbose version of code. Feels far to long, but that's edge cases for you. Explanation: Fθ⊞υΣEη∧№ικ⁼λ⌕ηκ For each conversation, count the number of unique words that also appear in the current conversation. ≔§θ⌕υ⌈υθ Get the best match conversation. F✂θ∨⌈ΦEη⌈⊕⌕AθιιLθ⊞...


1

Scala, 190 bytes type S=Seq[String];def f(c:S,a:Seq[S])={val s=a.map(s=>(s,(s.toSet&c.toSet).size)).fold((Seq[String](),0)){(m,s)=>if(s._2>m._2)s else m}._1;c++s.slice(s.lastIndexWhere(c.toSet(_))+1,s.size)} Try it online! Same, just a little more readable: def f( c:Seq[String], a:Seq[Seq[String]] ) = { val s=a.map(s=>(s,(s.toSet&c....


7

Jelly, 17 bytes ṚfQLɗÞṪṫẹⱮFṀɗ¥Ḋ⁹; A dyadic Link accepting all_conv (a list of lists of lists of characters) on the left and curr_conv (a list of lists of characters) on the right which yields the altered curr_conv (a list of lists of characters). Try it online! Or see the test-suite. How? ṚfQLɗÞṪṫẹⱮFṀɗ¥Ḋ⁹; - Link: all, curr Ṛ - reverse (all) ...


4

Perl 5, 140 bytes sub{($C,$A,$a,@e)=@_;$$a[0]<($x=--$n+9e9*grep$_~~@$C&&!$s{$n,$_}++,@$_)and$a=[$x,@$_]for@$A;unshift@e,pop@$a until!@$a||$$a[-1]~~@$C;@$C,@e} Try it online! ungolfed: sub{ ($C,$A,$a,@e)=@_; $$a[0] < ($x = --$n + 9e9*grep$_~~@$C&&!$s{$n,$_}++,@$_) and $a = [$x,@$_] for @$A; unshift @e, pop@$a until !@$a ||...


4

Stax, 19 bytes æ;í²'^8τ}gAαögQl╝ε╟ Run and debug it(all test cases) query first, sentences last, separated by a comma. Explanation ;{x|&u%}EhcJsx|&H/HxJs+ ; Push the sentences { }E max by the following: x|& Intersection with query string u% length of all unique ...


8

05AB1E, 19 bytes δåOZDĀikèõª¹¡θ¹ìáë¹ First input is curr_conv, second input is all_conv. Try it online or verify all test cases. Explanation: δ # Apply double-vectorized on the two (implicit) inputs å # Check if the list contains the current word This results in a list of lists of truthy/falsey values, where each truthy/...


4

Python 3, 96 bytes lambda a,c:c+max([[*{*s}&{*c},s[max([-1,*map(s.index,{*s}&{*c})]):][1:]]for s in a],key=len)[-1] Try it online!


3

Jelly, 25 23 bytes ;ɓ³œ&QLƲÐṀḢṫẹⱮF©Ṁ‘ʋ¥¹®ȧ Try it online! Dyadic link that takes the current conversation as the left argument and the list of conversations as the right argument.


11

JavaScript (ES6), 109 bytes Expects (all_conv)(curr_conv). a=>c=>a.map(b=>[...b].map(w=>(l+=c[I='includes'](b.shift())&!b[I](w))>m&&(m=l,o=[...c,...b]),l=0),m=0,o=c)&&o Try it online! Commented a => c => // a[] = all_conv, c[] = curr_conv a.map(b => // for each list of words b[] in ...


1

05AB1E, 8 + 16 + 1 + 0 = 25 bytes A: ѨO©QI®Ö B: ÑæOILåPILÑ€gRć‹P C: s D:  The long parts each calculate both values, s swaps to the first one. Ñ # push list of divisors © # store this list ¨ # remove the last (largest) value O # take the sum Q # is this equal to the input (perfect) I # push the input ...


1

Jelly, 5 + 17 + 3 + 3 = 28 bytes There's already a 28-byte Jelly answer, but I have a different approach, so why not add it too? Parts The pilcrow ¶ represents a newline. A: S=¶ḍ¶ (5 bytes) B: ŒP§iⱮḶ}Ạ¶>ḶÆd$}Ạ¶ (17 bytes) C: ÆḌñ (3 bytes) D: Ædç (3 bytes) Perfect (8 bytes) S= ḍ ÆḌñ Try it online! Explanation S= Auxiliary dyadic link S Sum of items ...


1

Python 3, 26 bytes lambda n:n%4**-~(n%25<1)<1 Try it online! Using Kevin Cruijssen's Java approach. Python 3, 28 bytes lambda n:(n%100or n/100)%4<1 Try it online! Using Kevin Cruijssen's 05AB1E approach.


1

Forth (gforth), 48 39 bytes : f 'd /mod over if d>s then 4 mod 0= ; Try it online! Same as Kevin Cruijssen's 05AB1E answer. -9 bytes from Bubbler.


1

Husk, 7 bytes Λ≡gẊo±- Try it online!


1

Japt, 9 bytes Outputs false for truthy and true for falsey. äÎòÎmÊäÎd Try it (footer negates the output) or run all test cases äÎòÎmÊäÎd :Implicit input of array > [0,3,7,5,2,3,6] ä :Consecutive pairs > [[0,3],[3,7],[7,5],[5,2],[2,3],[3,6]] Î : ...


0

WebAssembly Text Format, 111 bytes (func(result i32)i32.const 0 i32.load i32.const 8 i32.load i32.add i32.const 13 i32.rem_s i32.const 7 i32.le_s) This function operates on an integer memory array, that should start pre-filled with the chosen color (in Title Case) as a list of ascii code points. (strings can't be provided as normal function arguments). The ...


0

Husk, 16 bytes £İf←LU¡λ≠⁰→↑≤⁰İf Try it online!


0

Japt, 20 bytes Êu *`q¿nwm`pÔò d@¥îX Try it Êu *`...`pÔò d@¥îX :Implicit input of string U Ê :Length u :Mod 2 * :Times `...` : Compressed string "wbunwm" p : Append Ô : Reverse ò : Partitions of ...


0

Husk, 8 bytes Λ§<→oAhḣ Try it online!


0

Stax, 6 bytes ┬$τ▀Ω♀ Run and debug it I'm not sure why 3 golflangs have an Euler Totient function, but I guess it's convenient for these challenges. 0 for reachable and 1 for non-reachable.


0

Husk, 15 bytes Λṗ§zoṁdeohḣotṫd Try it online!


3

Jelly, 26 25 bytes LḂ ¹;2ṙ1ƊÇ?µnJḂ$Ạð,µḢnÇaẠ Try it online! Input is a list of numbers: 0 = M, 1 = D, 2 (or any other number) = B. Output is a pair of 0 or 1, representing the possibility of a monad/dyad respectively. I really wanted to beat the 05AB1E submission and it seems that I succeeded. Explanation LḂ Auxiliary link L Length Ḃ Parity ¹;2ṙ1ƊÇ?...


0

Husk, 9 bytes ¬ṁ§=Oṙ2Ṗ3 Try it online! Uses 'disqualifying condition' of any subsequence mid...high...low from tsh's and Lynn's answers. ¬ṁ§=Oṙ2Ṗ3 Ṗ3 # consider all subsequences of length 3: ṙ2 # check whether rotating 2 to the left §=O # is the same as sorting; ¬ṁ # total of subsequences that satisfy this should be zero


1

Husk, 10 bytes Λo≠4Ṡ€oPOQ Try it online! Same idea as Kevin Cruijssen's answer.


2

JavaScript (ES6), 20 bytes s=>!/ro|p|c/.test(s) Try it online! How it works: Get a truthy value if ro is present, p is present, or c is present, then inverts that value so if they are present, the result is falsey, otherwise the result is truthy Look at the regex here (Regex101.com) JavaScript (ES6), 22 bytes s=>!/p|[^e]n$/.test(s) Try it online! How ...


0

MathGolf, 7 bytes mækî)%Ñ Input as a string. Try it online. Explanation: m # Map over each character of the (implicit) input-string, æ # using the following four characters as inner code-block: # (implicitly push the current character of the map) k # Push the input as an integer î # Push the 1-based map-index ) ...


1

Haskell, 53 bytes f n=foldr(\(k,_)a->10*a+mod n k)0(zip[2..]$show n)==n Try it online!


Top 50 recent answers are included