AdventOfCode2017 Day 5 and 6

Another two days down, no sweat (minus a segfault on day 6, but shhhh.)

Day 5’s challenge was to take a list of jump offsets and determine how many jumps you need to take before exiting the block of code (modifying the jump offsets each time)

Day 6’s challenge was to take a list of memory banks, run through a balancing algorithm regarding allocations, and count how many steps until an infinite loop.

Let’s take a look at the code, as they clock in at <40 lines apiece.

Continue reading

Advertisements

AdventOfCode2017 – Day 4

Hooray, another easy one.  After Day number 3, I could certainly use it.  This challenge involved taking a list of passphrases, and counting up the number of passphrases that had no duplicate words.   This seems simple, just a split, sort and application of std::unique.

Part 2 had me check for anagrams rather than duplicate words.  This was also easy, as I could map over a sort function to each word in the passphrase, and then check for uniqueness.

Let’s look at the code


#include <algorithm>
#include <iostream>
#include <string>

#include "algo.h"
#include "input.h"

std::string sortString(std::string s) {
    std::sort(s.begin(), s.end());
    return s;
}

bool isUnique(const std::string& passphrase) {
    auto words = algo::map(input::split(passphrase), sortString);
    std::sort(words.begin(), words.end());
    return words.end() == std::unique(words.begin(), words.end());
}

int main() {
    auto passPhrases = input::readMultiLineFile("input/input04.txt");
    auto count = std::count_if(passPhrases.begin(), passPhrases.end(), isUnique);
    std::cout << count << "\n";
    return 0;
}

Super straight forward.  I think the trickiest thing was std::unique, because I didn’t realize it returned the end iterator of the range.  But once I figured that out, this wasn’t so bad.

Stay tuned for day 5!

AdventOfCode2017 Day 3

So this day was a tad bit rougher.  I wasn’t expecting the sudden difficulty increase on day 3.  The problems were straight-forward enough, but I didn’t want to brute force my way through them.  Unfortunately, I didn’t get the math worked out, so brute force became one of my last options

However, on the bright side, I got to play with std::optional, so I got that going for me.

 

I’m going to have a tough time explaining the problem any better than advent of code, so I’m just going to link you there instead

Continue reading

AdventOfCode2017 Days 1 and 2

It’s December and you know what that means!  Advent Of Code is back!.

This year, I’m not going to try the 25 languages in 25 days, but instead focus on my C++ skills.  More specifically, here are the constraints I am putting on myself.

  • Use C++17 where I can if it makes sense
  • Avoid raw loops on containers unless I have a performance concern
  • If there are any raw loops needed, see if it can be abstracted into a generic algorithm

So Challenge 1: here we go. Continue reading

Building a Development Community In Your Workplace

So for DevSpace in October, I was happy to present my first soft skills talk: Building a Development Community in your Workplace.

I got a lot of good feedback on it, and some people were asking for some more background information on it.  It’s tough to condense a 1 hour talk into a blog post and not bore the heck out of you, so I’ll make you a deal.  I’ll distill it into my core talking points, and if you’re interested in a specific part of it, let me know and I’ll write a more in-depth blog post.

 

It all started back at PyTennessee 2015.  This was my first conference, and I was floored at what this sort of environment offered.  I got to talk with great people, learn awesome stuff, and just generally have a good time.  But as soon as Monday rolled around the next week, I didn’t feel that great.  I chalked it up to being tired from a conference, and having to go back to work after a great weekend.

A few months later, I had the privilege to go to StrangeLoop in St. Louis.  This was a much bigger affair, and we had talks from senior engineers from Twitter, Microsoft, and Mastercard there.  I loved being there, but another strange thing happened.  Even before the conference ended, I was feeling that same “down” feeling that reminded me of PyTennessee.  I wasn’t quite sure what it was.  It stuck with me longer too.

Continue reading

Launching Tech Talks in your Workplace

It’s no secret that I’ve really loved conferences as of late.  Ever since I went to PyTennessee in 2015, I’ve really felt a renewed encouragement to further my own knowledge. I read software books for a long time, but was starting to peter out on them because I felt like a lot of what I was reading was broadly applicable, but I needed to take deeper dives on certain topics.

I started reading through HackerNews, and started finding blogs I enjoyed, but it still wasn’t enough.  But once I went to a conference, I realized just how much more I could learn.  I saw great presentations, great content, and got to talk to a lot of smart people.

That all happened in February.  That started getting some gears spinning for me.  I wanted to get the conference mindset at ADTRAN, where I work.  I wanted for us to create a culture where we could share all the great thing we knew.  So by July of that same year, I had created Tech Talks.   Continue reading

The State of C++17

Whelp, I haven’t written in a while (I knew this would happen), but it’s okay.  Nothing like a dev conference to get me writing again.

 

I had been selected for two talks for DevSpace2017, which is going on as I write this.  My two talks are “C++17: Not Your Father’s C++” and “Building a Development Community In Your Workplace”

 

I delivered the C++ talk this morning, and I thought it went quite well.  What I want to address in this blog post is the state of C++, with respects to C++17.  C++11 was a huge impact to the C++ community.  We got Lambda’s, Type Inference, Variadic Templates, Smart Pointers, Type Traits, Constexpr, and a bunch of other game-changers.

 

Around the community, I’ve heard some conversations about if C++17 is a bust.  Is it a joke?  I think the reason for this is that people measure C++17 against C++11.  But this isn’t necessarily correct.  C++11 had 7 or 8 years to get moving and to introduce it’s ideas.  It came all at once, and compilers had to play catch up to deliver all these cool new features.

 

But the C++ committee realized this was subpar.  It was too much all at once.  So now they are doing something a bit different.  Smaller releases, more frequent.  (Of course I like this idea, it’s much closer to a continuous integration mindset – and yes I know that 3 years between releases is not continuous, but for compiler releases, I’ll take it).

 

So instead, I measure C++ 17 against C++14.  C++14 gave me a few things like make_unique and auto parameters in lambdas, but this wasn’t a game changer for me.  They were quality of life improvements.  C++17 on the other hand, has variants (Type-safe unions), optional, parallel algorithms, std::byte, string_view, fold expressions, plus a whole bunch of quality of life improvements.

 

People also complain about features that aren’t in the standard (concepts, ranges, modules, reflection, etc.).  I agree, it stinks that these didn’t make it.  But let’s not judge C++17 by what didn’t make it in, but instead, let’s look at what did.  When I look at it this way, I consider C++17 a great improvement to the language.