Skip to content

Instantly share code, notes, and snippets.

Kory Becker primaryobjects

Block or report user

Report or block primaryobjects

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
primaryobjects /
Last active Aug 15, 2019
Counting valleys hiked, a programming exercise in C# .NET.

Gary is an avid hiker. He tracks his hikes meticulously, paying close attention to small details like topography. During his last hike he took exactly steps. For every step he took, he noted if it was an uphill, , or a downhill, step. Gary's hikes start and end at sea level and each step up or down represents a unit change in altitude. We define the following terms:

A mountain is a sequence of consecutive steps above sea level, starting with a step up from sea level and ending with a step down to sea level. A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level. Given Gary's sequence of up and down steps during his last hike, find and print the number of valleys he walked through.

For example, if Gary's path is DDUUUUDD, he first enters a valley 2 units deep. Then he climbs out an up onto a mountain 2 units high. Finally, he returns to sea level and ends his hike.

Function Description

primaryobjects /
Created Aug 14, 2019
How to preview an RST document in Sublime Text.

How to Preview an RST Document in Sublime Text

  1. In Sublime Text, click Preferences->Package Control.
  2. Type install and press Enter.
  3. Type OmniMarkupPreviewer and press Enter.
  4. After installing, open a .rst file (it must be a file already saved with a .rst file extension).
  5. In Sublime Text, use the hot-key CTRL-ALT-O or click Tools->Command Palette and type preview, selecting Preview Current Markup in Browser.

Your web browser should launch on localhost and display the formatted rst file.

primaryobjects / example.png
Last active Aug 14, 2019
Bootstrap table left-column minimum width and content column max width.
primaryobjects / background.js
Last active Jun 7, 2019
Chrome Extension example to trigger the permission update warning.
View background.js
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
// No tabs or host permissions needed!
console.log('Turning ' + tab.url + ' red!');
code: '"red"'
primaryobjects / havelHakimi.R
Created May 30, 2019
[2019-05-20] Challenge #378 [Easy] The Havel-Hakimi algorithm for graph realization. Demo at
View havelHakimi.R
havelHakimi <- function(data) {
result <- F
repeat {
# Remove all 0's.
data <- data[data != 0]
if (length(data) == 0) {
result <- T
primaryobjects /
Last active Jul 7, 2019
Thoughts on Common Sense Artificial Intelligence

Thoughts on Common Sense Artificial Intelligence

I wanted to share some thought-provoking ideas from a recent talk that I attended on "Building AI with Common Sense", presented by Ernest Davis, professor of Computer Science at New York University. His research focuses on the automation of common sense, spatial, and physical reasoning.

The image below really sets the tone for the topic. Can you see what's happening?

Amazon Image Recognition processed this image and is 98% confident that it sees a "Robot" and a "Toy". Those are correct, from a limited sense. However, do you see what the robot is doing? The common sense aspect of this image is probably the most important part of it!

Most of the AI that we're familiar with centers upon machine learning, statistical based learning, sourced from training sets. This has demonstrated significant advances in recent years, especially from neural networks and deep learnin

primaryobjects /
Created May 8, 2019
Programming by Example proof-of-concept implementation with a machine learning model based on input/output features.

Programming By Example

The following program is a basic proof-of-concept implementation of the program synthesis technique of Programming by Example, as included in Microsoft Excel FlashFill.

The Data Set

The data-set "features.csv" consists of extracted features from input/output examples, as a user would provide prior to beginning program synthesis. For example, to produce a program that extracts the first character of every input string, the user might give examples of strings as input with lengths of 1, 2, or 5 characters and an output example of a single character. We can guess the most likely program to select as a solution might be "firstCharacter". Similarly, if the input consists of numbers, we can guess the most likely program to select as a solution might be "addition".

Large Database of Programs

primaryobjects / boxes.R
Last active May 3, 2019
[2019-04-08] Challenge #377 [Easy] Axis-aligned crate packing in R. Demo
View boxes.R
# [2019-04-08] Challenge #377 [Easy] Axis-aligned crate packing
# Given X, Y, x, and y, determine how many boxes can fit into a single crate if they have to be placed so that the x-axis of the boxes is aligned with the x-axis of the crate, and the y-axis of the boxes is aligned with the y-axis of the crate. That is, you can't rotate the boxes. The best you can do is to build a rectangle of boxes as large as possible in each dimension.
# For instance, if the crate is size X = 25 by Y = 18, and the boxes are size x = 6 by y = 5, then the answer is 12. You can fit 4 boxes along the x-axis (because 6*4 <= 25), and 3 boxes along the y-axis (because 5*3 <= 18), so in total you can fit 4*3 = 12 boxes in a rectangle.
# Demo
primaryobjects / oneToEachDigit.R
Created Mar 27, 2019
[2019-02-11] Challenge #375 [Easy] Print a new number by adding one to each digit. Demo at
View oneToEachDigit.R
# [2019-02-11] Challenge #375 [Easy] Print a new number by adding one to each of its digit
# For example, 998 becomes 10109.
# Bonus
# Solve without using strings.
primaryobjects / 1-quickbot.gif
Last active Mar 12, 2019
Controlling Mobile Robots Week 4 Programming Assignment Avoid Obstacles
You can’t perform that action at this time.