Skip to content

Instantly share code, notes, and snippets.

MATCH
1
2
3
4
5
6
7
8
9

Range compression

Write a function compress_ranges that receives an array of integers, and returns a string where consecutive integers are replaced with a range showing the first and last number in that run.

You can assume the array only contains distinct integers, and is always sorted in ascending order.

Test cases

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Launcher</title>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
var receiver;
-userId: (4 or 1073 or 1184 or 2926 or 3239 or 3423 or 3447 or 3620 or 3671 or 3708 or 3718 or 3748 or 3753 or 3754 or 3755 or 3766 or 3793 or 3847 or 3848 or 3854 or 4146 or 4147 or 4160 or 4230 or 4231 or 4337 or 4561 or 4568 or 4569 or 4579 or 4586 or 4641 or 4649 or 4701 or 4703 or 4704 or 4705 or 4706 or 4707 or 4708 or 4732 or 4735 or 4736 or 4741 or 4771 or 4772 or 4790 or 4840 or 4841 or 4845 or 4850 or 4851 or 5094 or 5097 or 5101 or 5210 or 5215 or 5217 or 5222 or 5224 or 5226 or 5818 or 5972 or 5974 or 6099 or 6103 or 6116 or 6122 or 6123 or 6126 or 6136 or 6140 or 6141 or 6146 or 6148 or 6338 or 6339 or 6342 or 6343 or 6344 or 6345 or 6346 or 6347 or 6348 or 6350 or 6351 or 6383 or 6558 or 6562 or 6563 or 6658 or 6659 or 6660 or 6661 or 6662 or 6663 or 6878 or 7040 or 7046 or 7386 or 7387 or 7412 or 7419 or 7420 or 7429 or 7433 or 7434 or 7435 or 7436 or 7438 or 7439 or 7443 or 7444 or 7531 or 7532 or 7533 or 7538 or 7540 or 7556 or 7557 or 7562 or 7564 or 7567 or 7568 or 7569 or 7570 or 7572 or 7
@gareth
gareth / loggable.rb
Created May 6, 2015 14:09
Simple Ruby module to add configurable, class/instance level logging to any class
require 'logger'
# Adds configurable logger functionality to a class
#
# class Foo
# include Loggable
#
# def complicated_method
# logger.debug("Foo") { "Beginning long method" }
# sleep(2)
@gareth
gareth / keybase.md
Created September 28, 2014 19:51
Keybase.io verification

Keybase proof

I hereby claim:

  • I am gareth on github.
  • I am garethadams (https://keybase.io/garethadams) on keybase.
  • I have a public key whose fingerprint is 6CA8 8151 9967 9822 D3E5 69D4 0E9F C2A0 95EC 3DDD

To claim this, I am signing this object:

@gareth
gareth / gbot.rb
Last active December 22, 2015 06:08
class GBot < RTanque::Bot::Brain
NAME = 'GBot'
include RTanque::Bot::BrainHelper
TickReflection = Struct.new(:reflection, :tick, :position, :direction)
def known_bots
@known_bots ||= Hash.new { |hsh, name| hsh[name] = TickReflection.new }
end
<div class="left-main">
<p class="original-site">RECENT DESIGNS</p>
<% @articles.each.with_index do |article, i| %>
<% if i % 4 == 0 %>
<%= link_to(image_tag(article.main_image_url.to_s), article, {:class => 'dock-item'}) %>
<% else %>
<%= link_to(image_tag(article.main_image_url.to_s), article, {:class => 'dock-item2'}) %>
<% end %>
<% end %>
</div>
require 'json'
require 'eventmachine'
require 'sinatra/async'
class Main
register Sinatra::Async
def self.handleMessage(channel, message)
puts "Handling message for channel #{channel}: #{message}"
end
@gareth
gareth / gist:2146018
Created March 21, 2012 10:22
Problems with `brew install ack`
➜ local git:(master) brew install ack
==> Downloading https://github.com/petdance/ack/tarball/1.96
######################################################################## 100.0%
==> pod2man ack ack.1
==> Build Environment
CPU: quad-core 64-bit nehalem
MacOS: 10.6.8-i386
Xcode: 4.0
CC: /usr/bin/llvm-gcc => /usr/llvm-gcc-4.2/bin/llvm-gcc-4.2