Skip to content

Instantly share code, notes, and snippets.

View HelixSpiral's full-sized avatar
🐔
🐔🐔🐔🐤🐤🐤🐤

Shawn Smith HelixSpiral

🐔
🐔🐔🐔🐤🐤🐤🐤
View GitHub Profile
@HelixSpiral
HelixSpiral / Diamond.c
Created January 6, 2012 19:40
Creates a command-line diamond
/* Creates a diamond */
/* Needed for standard IO features */
#include <stdio.h>
int main()
{
/* The number of lines we want the diamond to be */
int lines, x, y;
int stars = 1;
@HelixSpiral
HelixSpiral / Triangle.c
Created January 6, 2012 20:06
Creates a command-line triangle
/* Creates a triangle */
#include <stdio.h>
int main()
{
/* vars */
int lines, stars, x, y;
printf("How many lines do you wish the triangle to be?: ");
@HelixSpiral
HelixSpiral / OneHundredDoors.c
Created January 10, 2012 07:06
One Hundred Doors
/* http://rosettacode.org/wiki/100_doors */
#include <stdio.h>
int main()
{
int x, y;
int doors[100] = { 0 };
/* Loop the 100 times */
@HelixSpiral
HelixSpiral / Bottles.c
Created January 10, 2012 07:25
99 Bottles of beer on the wall
/* http://rosettacode.org/wiki/99_Bottles_of_Beer */
#include <stdio.h>
int main()
{
int bottles;
for(bottles = 99; bottles > 0; --bottles)
{
@HelixSpiral
HelixSpiral / PerfectSquare.c
Last active September 30, 2015 09:38
Determines the closest number to the users input that is a perfect square.
/** Write a program that prompts the user for a positive integer
* and then reports the closest integer having a whole number square root.
* For example if the user enters 8 then the program reports 9.
* The program should work for any number having one to seven digits.
*/
#include <stdio.h>
/* Checks to see if the number is a perfect square.
returns 1 for yes, 0 for no. */
@HelixSpiral
HelixSpiral / SumOfDigits.cpp
Created February 8, 2012 03:49
Returns the sum of the digits to the given number.
/** Write a program that prompts the user for a positive
* integer and then computes the sum of all the digits of
* the number. For example, if the user enters 2784,
* then the program reports 21. If the user enters 59,
* then the program reports 14. The program should work
* for any number having one to ten digits.
*/
#include <iostream>
#include <string>
@HelixSpiral
HelixSpiral / Prime.cpp
Created February 7, 2013 19:55
Challenge: If a number, 'X' is prime then 2^X-1 should also be prime, find at which prime this fails to be true. This uses the trial and error method of finding prime numbers.
#include <iostream>
#include <cmath>
#include "Prime.h"
int main()
{
int x;
bool Failure = false;
for (x = 1; Failure != true; ++x)
@HelixSpiral
HelixSpiral / HTSBasic-6.rb
Created February 7, 2013 22:00
This solves the HackThisSite 'basic' mission number 6.
# Enter the encoded password from HackThisSite
encoded_password = "a9;96j6i"
# empty string for the decoded password
password = ""
# Loop for the length of the encoded password
0.upto(encoded_password.length-1) do |x|
password += ((encoded_password[x].ord)-x).chr
end
@HelixSpiral
HelixSpiral / IntegerSort.cpp
Last active December 12, 2015 07:29
Challenge: Take input from a user and print the lowest number possible using the digits from the given input.
#include <iostream> // Needed for std::cout/cin
#include <vector> // Needed for std::vector
#include <string> // Needed for std::string
#include <algorithm> // Needed for std::sort
int main()
{
std::string user_input;
std::vector<int> digits;
bool negative;
@HelixSpiral
HelixSpiral / Sieve.cpp
Last active December 14, 2015 02:29
First time using std::vector<bool>. Decided to make a Sieve of Eratosthenes for practice. Takes a number for input and finds all the primes up to that number. Sieve[x] will return true if x is prime, false if not.
#include <iostream> // Needed for std::cin/cout
#include <vector> // Needed for std::vector
#include <cmath> // Needed for sqrt and ceil
int main()
{
/* Will be the sieve */
std::vector<bool> Sieve;
unsigned int x, y, limit;