Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Haha, bitwise xor. Since it's immutable and commutative it'll reduce down to the stray!
I should add that this only works because it’s an odd number of elements in the array. An even number of matching elements cancel each other out to result in the “stray”.
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Lead Developer: Adobe Experience Manager. Father of one. Minnesota. Occasionally write here: ahmedmusallam.com and there: https://blogs.perficientdigital.com/author/amusallam/
@laurieontech did something really cool in JS with a bitwise XOR (her answer is above), so I figured I'd update this C++ answer with a bitwise XOR since I love it!
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Stackoverflow helped me with that one. I knew it was possible, but wasn't sure how. I actually started with the (.)\1* and iterated to the right regex from there.
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Ooh, you're right. I had it that way to start and then ran into problems with a test case that had 663. It was splitting that grouping because it hit the matching case first. But when I removed the capture group generic and made it non-digit that solved that. So can revert back. Thanks :)
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
#!/usr/bin/perlusewarnings;usestrict;sub perimeters{my($n)=@_;my@f=(1,1);my$s=0;for(0..$n){$s+=$f[0];@f=($f[1],$f[0]+$f[1]);}return4*$s}# In a good TDD tradition, I started with these lines:useTest::Moretests=>2;isperimeters(5),80;isperimeters(7),216;
Tuesday (7 KYU): Find the stray number
codewars.com/kata/57f609022f4d534f...
What is this necromancy?
Haha, bitwise xor. Since it's immutable and commutative it'll reduce down to the stray!
I should add that this only works because it’s an odd number of elements in the array. An even number of matching elements cancel each other out to result in the “stray”.
Oh my, it even works in python!
This is one of those moments when I wish gifs worked better on Dev. But yay!
They should work in normal image markdown!
Whaaa?! How did I not know this! ...game changer
Same idea in Haskell:
Well I can't think of a better answer for this particular problem domain.
XOR is a great idea, thanks!
Math for the win! :D
here my cheap solution:
or shorter and more unreadable:
in c# using linq:
or:
Thanks for this! I don't really know C++, but I figured I'd give it a shot:
@laurieontech did something really cool in JS with a bitwise XOR (her answer is above), so I figured I'd update this C++ answer with a bitwise XOR since I love it!
Looks a bit messy, but I was going for something that might not be too inefficient with a large input array
This is the first I'm finding this, excited to play along! Here is yesterday's (edited to make the colors show up):
I don't think this is better than the bitwise solution but it's a different one lol
Wednesday (6 KYU): Implement Syntax Highlighting
codewars.com/kata/roboscript-numbe...
And now with added re.sub with a callable, which I had no idea was a thing! These coding things are pretty nifty for leaning new tricks I must say!
Oooh, I like this. I was thinking about a dictionary but didn't think about a dictionary with the regex as a key!
Booo regex
Quick edit with a dictionary.
I had no idea you could use \1 in the same expression as the tagged group, never seen that before!
Stackoverflow helped me with that one. I knew it was possible, but wasn't sure how. I actually started with the (.)\1* and iterated to the right regex from there.
You should be able to simplify it a little by changing the + to a * so you don't need the second \D I think?
(\D)\1*|(\d+)
Ooh, you're right. I had it that way to start and then ran into problems with a test case that had 663. It was splitting that grouping because it hit the matching case first. But when I removed the capture group generic and made it non-digit that solved that. So can revert back. Thanks :)
The answers to this kata on codewars are blowing my mind.
Monday (8KYU): How many stairs will Suzuki climb in 20 years?
codewars.com/kata/56fc55cd1f5a93d6...
Javascript (ES6):
Not a one liner like you guys but C#:
Okay, I couldn't help myself:
My Python solution:
Practicing TypeScript for my upcoming internship. And I figured out how to add code highlighting!
Friday (CodeJam): Foregone Solution
codingcompetitions.withgoogle.com/...
brute force for me so far.
Thursday (5 KYU): Perimeter of squares in a rectangle
codewars.com/kata/559a28007caad2ac...
TypeScript. Great practice!