Skip to content

Instantly share code, notes, and snippets.

❯ benchstat v3.txt v4_garman_bytes.txt
name old time/op new time/op delta
Answer-8 136ns ± 0% 23ns ± 0% -83.28% (p=0.016 n=4+5)
❯ benchstat v4_fugi.txt v4_garman_bytes.txt
name old time/op new time/op delta
Answer-8 37.8ns ± 0% 22.8ns ± 0% -39.66% (p=0.008 n=5+5)
#include <cstdio>
using namespace std;
int main(int argc, char** argv) {
printf("[");
char* cur = argv[1];
int count = 1;
for (;*cur;++cur, ++count) {
if (cur[0] != cur[1]) {
printf("(\"%c\", %ld)%s", cur[0], count, cur[1] ? " ,": "");
# generated by SuperSlicer 2.3.55 on 2020-12-15 at 07:14:58 UTC
allow_empty_layers = 0
avoid_crossing_not_first_layer = 1
avoid_crossing_perimeters = 0
bed_custom_model =
bed_custom_texture =
bed_shape = 0x0,250x0,250x210,0x210
bed_temperature = 105
before_layer_gcode = ;BEFORE_LAYER_CHANGE\nG92 E0.0\n;[layer_z]\n\n
between_objects_gcode =

Pretty ugly solution, relies on knowledge about the data. Works.

@garethlewin
garethlewin / Notes.MD
Created January 3, 2016 05:06
Solution for year 32 of Human Resource Machine

This is a disgusting solution, but it works. The speed challenge wants you to take up to 393 steps (on average), this takes 81

If you know anyone that wrote code like this for a real problem, don't hire them.

Keybase proof

I hereby claim:

  • I am garethlewin on github.
  • I am garethlewin (https://keybase.io/garethlewin) on keybase.
  • I have a public key whose fingerprint is BE25 1452 D510 2D82 7EDE 7A24 55B4 5CEA 0170 E380

To claim this, I am signing this object:

void ParseHeader(const uint8_t* header,
size_t headerSize,
std::string& verb,
std::string& url,
urlParameters_t& params)
{
using std::begin;
using std::end;
using std::find;
using std::find_first_of;
TwitchAPI - GET / HTTP/1.1
Host: localhost:55542
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
DNT: 1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,he;q=0.6
//--------------------------------------------------------------------------
TTV_ErrorCode ttv::Streamer::SetIngestServer(const TTV_IngestServer* ingestServer)
{
if (ingestServer == nullptr)
{
ttv::trace::Message("Streamer", TTV_ML_ERROR, "Inside Streamer::SetIngestServer - Invalid ingest server");
return TTV_EC_INVALID_INGEST_SERVER;
}
mSelectedIngestServer = *ingestServer;
// Why does this work:
int addrInfoRet = getaddrinfo(host.c_str(), port.c_str(), &hints, &remoteHost);
auto deleter = [](addrinfo* p){ if (p) {freeaddrinfo (p);} };
std::unique_ptr<addrinfo, decltype(deleter)> remoteHostContainer(remoteHost, deleter);
// But this doesn't:
int addrInfoRet = getaddrinfo(host.c_str(), port.c_str(), &hints, &remoteHost);
std::unique_ptr<addrinfo, decltype(freeaddrinfo)> remoteHostContainer(remoteHost, freeaddrinfo);