Skip to content

Instantly share code, notes, and snippets.

@Mjiig
Mjiig / euler.cpp
Created September 9, 2012 21:50
Euler #47
#include <vector>
#include <iostream>
#include <algorithm>
class Primegen
{
std::vector<int> primes; //store all the primes we've generated so far
void nextprime(void); //add one new prime to the end of the list
class Pentagonals(object):
def __init__(self):
self._nums={}
def add_pent(self):
n=len(self._nums)+1
self._nums[n-1]=(n*((3*n)-1)/2)
def is_pent(self, n):
return n in self._nums
int VM::run(std::string state)
{
r1=r2=r3=r4=r5=0;
for(int i=0; i<256;i++)
{
memory[i]=0;
}
load(state);
mainloop();
@Mjiig
Mjiig / rc4.cpp
Created June 8, 2012 21:17
rc4 cipher for MagPi
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
class State
{
unsigned char s[256];
int i, j;
@Mjiig
Mjiig / euler.cpp
Created June 2, 2012 13:26
Project Euler #56
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
class Hugenum
{
public:
std::string str; //stores the number in decimal form, this is a horrible way to store numbers, but it works for almost any size we can imagine
@Mjiig
Mjiig / rc4.cpp
Created May 18, 2012 21:40
Simple RC4 encryption program
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
class State
{
unsigned char s[256];
int i, j;
@Mjiig
Mjiig / menu.py
Created April 24, 2012 17:27
Terminal menu in python
# -*- coding: utf-8 -*-
# Topmenu and the submenus are based of the example found at this location http://blog.skeltonnetworks.co…..stom-menu/
# The rest of the work was done by Matthew Bennett and he requests you keep these two mentions when you reuse the code
import curses, os #curses is the interface for capturing key presses on the menu, os launches the files
screen = curses.initscr() #initializes a new window for capturing key presses
curses.noecho()
curses.cbreak()
curses.start_color() # Lets you use colors when highlighting selected menu option
screen.keypad(1) # Capture input from keypad
# Change this to use different colors when highlighting
@Mjiig
Mjiig / euler.c
Created April 8, 2012 21:55
Project euler #53
#include <stdio.h>
double bang(int i)
{
return i==0?1:(double) i * bang(i-1);
}
double ncr(int n, int r)
{
double numerator=bang(n);
@Mjiig
Mjiig / euler.c
Created April 1, 2012 09:02
Project euler #52
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
void digits ( char digits[10], int n )
{
int top=(int)log10((float)n)+1;
int i=0;
@Mjiig
Mjiig / lychrel.c
Created March 16, 2012 23:25
Lychrel numbers
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool palindrome ( unsigned long long int i );
unsigned long long int reverse ( unsigned long long int i );
bool lychrel ( unsigned long long int i );
int main ( void )
{