Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 28, 2019 05:19 pm GMT

Daily Challenge 100 - Round Up

We started our daily challenge series on June 28th and it has been an amazing experience seeing your comments, suggestions, and solutions these past few months. In this post, I've collected some of our most popular challenges. If you have any of these challenges in your reading list, maybe try your hand at them!


Our first challenge post asked users to simply remove the first and last characters off a string. You all gave a variety of answers in CSS, Ruby, and Javascript!

@alvaromontoro got the most popular comment on this post with 43 hearts. He's been a great help to many around our community, you'll see his comments on a lot of our challenge posts.

CSS

Just add the class removeFirstAndLastLetter to a tag, and see the first and last letter "removed" from the text

.removeFirstAndLastLetter {  background: #fff;  font-family: monospace;  white-space: nowrap;  position: relative;  display: inline-block;}.removeFirstAndLastLetter::before,.removeFirstAndLastLetter::after {  content: "\00a0";  background: #fff;  top: 0;  display: block;  position: absolute;  height: 100%;  width: auto;}.removeFirstAndLastLetter::after {  right: 0;}

And as an extra, it can be stylized and animated, so you can see the letters fade out:


We really thought this post would be trickier, but a lot of really short, thoughtful answers came in. Daily Challenge #48 asked users to write a function that mimics the syntax common on Facebook.

@alvaromontoro got the most popular comment again, even 47 posts later! @avalander also gave a great answer using Haskell and got 15 hearts:

Some simple pattern matching with Haskell.

likes :: [String] -> Stringlikes []        = "no one likes this"likes [a]       = a ++ " likes this"likes [a, b]    = a ++ " and " ++ b ++ " like this"likes [a, b, c] = a ++ ", " ++ b ++ " and " ++ c ++ " like this"likes (a:b:xs)  = a ++ ", " ++ b ++ " and " ++ (show $ length xs) ++ " others like this"

Daily Challenge #31 prompted users to return the number of IP addresses between a starting point and an ending point.

@phallstrom found a cheeky solution by using Ruby's IPAddr class. @kerrishotts went above and beyond and made the function work if the points were reversed, great work!

Here's mine! I extended it a little to work if the start and end were reversed.

const convertIPStringToNumber = ipString => ipString.split(".")    .reduce((acc, part) => (acc << 8) | Number(part), 0);const ipsBetween = (start, finish) =>     Math.abs(convertIPStringToNumber(finish) - convertIPStringToNumber(start));

Gist: gist.github.com/kerrishotts/797450...


Our 60th challenge asked users to write a function that takes an array of consecutive letters as input and that returns the missing letter in the array.

@citizen428 offered some improvements on a Go answer left by @dak425, and even left his own answer in F#!

Time to Go find the missing letter!

missing_letter.go

package find// MissingLetter indicates what the missing character is in a ordered sequence of charactersfunc MissingLetter(chars []rune) rune {    var last int    for _, r := range chars {        if last != 0 && int(r)-last > 1 {            return rune(r - 1)        }        last = int(r)    }    return rune(last)}

missing_letter_test.go

package findimport "testing"type testCase struct {    description string    input       []rune    expected    rune}func TestMissingLetter(t *testing.T) {    testCases := []testCase{        {            "two characters",            []rune{'A', 'C'},            'B',        },        {            "dev-to example one",            []rune{'a', 'b', 'c', 'd', 'f'},            'e',        },        {            "dev-to example two",            []rune{'O', 'Q', 'R', 'S'},            'P',        },    }    for _, test := range testCases {        if result := MissingLetter(test.input); result != test.expected {            t.Fatalf("FAIL: %s - MissingLetter(%+v): %v - expected %v", test.description, test.input, result, test.expected)        }        t.Logf("PASS: %s", test.description)    }}

The Caesar Cipher is a well-known challenge for beginner programmers to start thinking about larger concepts like data encryption. Daily Challenge #42 asked users to work with the cipher, gave a shift key and a string and asked for the plain text.

@ynndvn used the brute force method on this challenge post back in August and I have seen them commenting their solutions on our latest challenges. Awesome work!

Here we go:

f=(s)=>[...Array(26)].map((_,i)=>26-i).map(n=>`key: ${26-n}\ncipher: ${s}\nplain: ${[...s].map(l=>(a=l.charCodeAt(0),String.fromCharCode(a<123&&a>96?97+((a-97+n)%26):a))).join('')}`).join`\n---\n`

Without any proper dictionary, I guess I'll stick to the "bruteforce" method! Here's how it works:

  • First, build an Array containing numbers from 26 to 1 ([...Array(26)].map((_,i)=>26-i))
  • Print the current index (26-n) and the cipher (s)
  • Build the associated original text: For each character, if its charCode is between 97 and 122 (hence, if it is a valid lowercase character), add the current index to it, else just return it.
  • Finally, print the complete result
f('dwwdfn iurp wkh zrrgv dw gdzq');"key: 0cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: dwwdfn iurp wkh zrrgv dw gdzq---key: 1cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: cvvcem htqo vjg yqqfu cv fcyp---key: 2cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: buubdl gspn uif xppet bu ebxo---key: 3cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: attack from the woods at dawn---key: 4cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: zsszbj eqnl sgd vnncr zs czvm---key: 5cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: yrryai dpmk rfc ummbq yr byul---key: 6cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: xqqxzh colj qeb tllap xq axtk---key: 7cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: wppwyg bnki pda skkzo wp zwsj---key: 8cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: voovxf amjh ocz rjjyn vo yvri---key: 9cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: unnuwe zlig nby qiixm un xuqh---key: 10cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: tmmtvd ykhf max phhwl tm wtpg---key: 11cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: sllsuc xjge lzw oggvk sl vsof---key: 12cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: rkkrtb wifd kyv nffuj rk urne---key: 13cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: qjjqsa vhec jxu meeti qj tqmd---key: 14cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: piiprz ugdb iwt lddsh pi splc---key: 15cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: ohhoqy tfca hvs kccrg oh rokb---key: 16cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: nggnpx sebz gur jbbqf ng qnja---key: 17cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: mffmow rday ftq iaape mf pmiz---key: 18cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: leelnv qczx esp hzzod le olhy---key: 19cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: kddkmu pbyw dro gyync kd nkgx---key: 20cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: jccjlt oaxv cqn fxxmb jc mjfw---key: 21cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: ibbiks nzwu bpm ewwla ib liev---key: 22cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: haahjr myvt aol dvvkz ha khdu---key: 23cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: gzzgiq lxus znk cuujy gz jgct---key: 24cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: fyyfhp kwtr ymj bttix fy ifbs---key: 25cipher: dwwdfn iurp wkh zrrgv dw gdzqplain: exxego jvsq xli asshw ex hear"

Thank you to CodeWars for allowing redistribution under the 2-Clause BSD License.

Special thanks to @peledzohar and @aminnairi for contributing to the series. Want to propose a challenge for a future post? Email [email protected] with your suggestions!


Original Link: https://dev.to/thepracticaldev/daily-challenge-100-round-up-5km

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To