Skip to content

Instantly share code, notes, and snippets.

View billabel's full-sized avatar

Bill Abel billabel

  • Homewood, Alabama
View GitHub Profile
@billabel
billabel / rogue-cursor.c
Created September 14, 2018 20:21
Use curses to display a moveable cursor in the window.
#include <ncurses.h>
// ncurses test
// rougelike code
// create a player character: @
// enable the user to move the character around the screen
int main()
{
@billabel
billabel / who-likes-it.rb
Last active September 14, 2018 20:19
Create readable description of names of users who like a post.
# a function for like that takes an array of names and returns a string
def likes(names)
if names.count <= 3
case names.count
when 0
"no one likes this"
when 1
"#{names[0]} likes this"
when 2
@billabel
billabel / fibonacci.c
Created September 14, 2018 20:15
Calculate the Fibonacci sequence.
#include <stdio.h>
int main()
{
int loop = 15, count, a = 0, b = 1;
for(count=1; count<= loop; ++count)
{
printf("%d\n%d\n", a, b);
a = a+b; //shift a to the next value in the squence
@billabel
billabel / snail.rb
Created September 14, 2018 19:48
Traverse an array in a snail shell pattern.
#
def snail(array)
include FollowThePath
init(array)
@squares.times do walkTheSquare(array) end
return @path
end
module FollowThePath
@billabel
billabel / fibonacci.rb
Created September 14, 2018 19:39
Find the nth Fibonacci number.
# find the nth value in the fibonacci squence
require "matrix"
# analyze processing time
require 'Benchmark'
time = Benchmark.realtime do
# get the user input for n, the nth value to find
n = gets.to_i
@billabel
billabel / missing-numbers.rb
Created September 14, 2018 19:35
Find the missing numbers in an array.
#!/usr/bin/env ruby
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
b = (1..100).to_a
# total all elements of an array
def total_array(array)
total = 0
array.each { | number | total += number}
@billabel
billabel / fizzbuzz.rb
Last active September 14, 2018 19:25
Fizz Buzz
#!/usr/bin/env ruby
#
# Write a program that prints the numbers from 1 to 100. For multiples of three, print "Fizz" and for mulitples of five print "Buzz". For multiples of both three and five, print "FizzBuzz".
# Let the user set the maximum number to evaluate
puts "Evaluate numbers up to?"
rangeMax = gets.to_i
# Store all the numbers in an array
numbers = (1..rangeMax).to_a
@billabel
billabel / hex-colors.js
Created September 14, 2018 18:11
A color palette of 4,096 3-digit hexadecimal colors.
// Based on http://chrisnager.com/hexcodes/
// --------------------------------------------------
// Create a color palette of all 4,096 3-digit hexadecimal colors
// --------------------------------------------------
// Hexadecimal digits
var digits = ['f', 'e', 'd', 'c', 'b', 'a', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0']
// Create a swatch book