Every day on Twitter, I post coding puzzles. These are quick coding challenges that increase in difficulty across the span of the week -- with Mond...
For further actions, you may consider blocking this person and/or reporting abuse
Wednesday
Array.diff (6 KYU):
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
CodeWars
Ruby
Ah, cannot
unseethis answer... πSimilar effort when done in APL! :)
That's amazing!
Thursday
Scramblies (5 KYU):
Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false
CodeWars
F#
Edit: I had previously posted a version that had ever-so-slightly more performance but was more code. I'm also including that version below since it solves the problem differently.
Here are the tests (console).
Nice! yeah -- I only sometimes think about the efficiencies of these. They're contrived and we're doing them for fun. Part of me cares, part of me doesn't haha
I agree. I would have posted a much more expressive version, but you beat me to it! I did find an alternative way of solving the problem that was a little more expressive and nearly the same perf. I updated my post to include it.
Go
Rust
Tuesday
Product of Array Items (7 KYU):
Calculate the product of all elements in an array.
CodeWars
F#
I probably wouldn't define a separate function for this in actual code.
Does F# require you to name the
arrparameter explicitly or can you simply do the following:I've been curious about F# for some time but haven't really done a deep dive.
Yes, you can do that in F#. (You probably know this, but for the sake of onlookers) it is called point-free notation. It can be handy for small functions like this. But I noticed when I use it too much, my code can become hard to understand.
Especially for code examples, I rarely use it because it can confuse readers.
I decided to not use reduce so that I could return early if I hit a zero.
Javascript
Friday
The Last Word (CodeJam):
You are the next contestant on this show, and the host has just showed you the string S. What's the winning last word that you should produce?
CodeJam
F#
Testing it (console)
Awesome -- this one (for me) was a lot easier than they made it sound!
Same here. The hard part was understanding the problem. (It felt very much like "A train leaving SF at 50kph ..." word problems.) But after that the code wasn't so bad.
I think the possible "gotcha" here is that they do not want a reverse alphabetically sorted string, which, if you're not careful about the requirements, could be what you try to build and have it trip you up.
Rust
usage:
last_word(.exe) < small.in > small.txtMeta!
Ooh. I tried to do Advent of Code in Go last year, but AoC was probably too steep a challenge for a language I didn't know at all. This is a much more manageable entrypoint. Thanks for this! π€
For sure! I may try and incorporate those next month! We'll see! Go is so much fun, I should do more with it!
Possibly dumb question - what does KYU stand for?
That's a great question -- I'm not totally sure, but it's the ranking system CodeWars uses, so I include it -- 8 KYU are the most beginner friendly, 1 KYU takes a really long time.
KYU is used for grading the difficulty levels, or degree of proficiency or experience.
Wiki
Monday
Number Drills: Blue and red marbles (8 KYU):
You've decided to write a function, guess_blue() to help automatically calculate whether you should guess "blue" or "red". The function should take four arguments.
CodeWars
Go
Common Lisp
the fun of a language with rationals:
Rust
Python!
JS Solution: Takes two arrays, returns a single array with all of the items from array A, which do not exist in array B.
Just realized @thesoreon posted almost the same solution already. Oh well, I guess great minds think alike π
That's nice! When i made this solution i was curious and searched for another approches and found the exact same solution on stack overflow π
For thos who are looking for solution in C#
using System;
using System.Collections.Generic;
public class Kata
{
public static int[] ArrayDiff(int[] a, int[] b) {
}
}