Skip to content

Instantly share code, notes, and snippets.

View complxalgorithm's full-sized avatar

Stephen Sanders complxalgorithm

View GitHub Profile
@complxalgorithm
complxalgorithm / flattenarray.cs
Last active May 7, 2016 22:49
A method to flatten an array using C# (using an example).
public static class Ex {
public static List<object> Flatten(this List<object> list) {
var result = new List<object>();
foreach (var item in list) {
if (item is List<object>) {
result.AddRange(Flatten(item as List<object>));
} else {
result.Add(item);
}
@complxalgorithm
complxalgorithm / shortcircuit.cpp
Last active May 7, 2016 23:00
Displays short circuit evaluation in C++.
#include <iostream>
using namespace std;
bool a(bool in)
{
cout << "a" << endl;
return in;
}
bool b(bool in)
@complxalgorithm
complxalgorithm / matrixclass.cpp
Created May 7, 2016 22:48
Uses a Matrix class to show a way to add, subtract, and multiply square matrices.
#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
const int ROW = 5;
const int COL = 5;
class matrix
@complxalgorithm
complxalgorithm / differentgraphs.r
Created May 8, 2016 03:38
Demonstration of different graphs in R.
# Use 26 since it’ll never actually equal 26
# Floor will return integers; stores in vector
nums <- c(floor(runif(20, min=-10, max=26)))
# Give the chart file a name
png(file = “boxplotrand.png”)
# Plot the graph, using vector nums from first question
boxplot(y ~ x, data = nums, xlab = “X Values”,
ylab = “Y Values”, main = “Values”)
# Save the file
@complxalgorithm
complxalgorithm / line_cap_filter.go
Last active May 8, 2016 04:59
Golang script that will write capitalized version of all input text.
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
@complxalgorithm
complxalgorithm / greaterthanavg.c
Created May 8, 2016 06:57
C program that will calculate the average of a list of input numbers and then output how many numbers are greater than the average.
#!/usr/bin/c
#include <stdio.h>
int main() {
int intlist[99], listlen, counter, sum, avg, res;
sum = 0;
res = 0;
printf("Enter number of values you want to input.");
scanf("%d", &listlen);
if ((listlen > 0) && (listlen < 100)) {
@complxalgorithm
complxalgorithm / stoploopwithctrlc.c
Created May 8, 2016 07:07
C program that ignores Ctrl-C for 5 seconds; afterward, the loop can be killed.
#include <stdio.h>
#include <signal.h>
main ()
{
void (*oldHandler) (); /* To hold old handler value */
int count = 0; /* Loop counter, initialized at 0 */
oldHandler = signal (SIGINT, SIG_IGN); /* Ignore Control-C */
printf ("I've started looping and I can't be killed with ^C\n");
while(1)
{
@complxalgorithm
complxalgorithm / ifprimenumber.c
Created May 8, 2016 07:10
C program that checks whether or not an input number is prime.
/* To check if a number is prime or not */
#include <stdio.h>
#include <ctype.h>
int main()
{
int n, i, flag=0;
printf(“Enter a positive integer: ”);
scanf(“%d”, &n);
if (n<1 || isalpha(n))
{
@complxalgorithm
complxalgorithm / sumofinputvalues.sh
Created May 8, 2016 07:14
Bash script that will accept 5 input values and find the sum of them.
#!/bin/bash
declare -i counter sum
declare -a -i var
declare -a order
order=([0]="first" [1]="second" [2]="third" [3]="fourth" [4]="fifth")
counter=0
sum=0
while(($counter < 5))
do
echo "Enter the ${order[$counter]} number to add:"
@complxalgorithm
complxalgorithm / leapyear.c
Created May 8, 2016 07:26
C program that will determine if an input year was/will be a leap year.
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int main(){
int year;
printf("Type a year (up to 4 digits) to determine if it's a leap year:");
scanf("%d",&year);
getchar();
if(((year<0)||(isalpha(year))||(year>9999))){
printf("Invalid year. Try again.\n");