Skip to content

Instantly share code, notes, and snippets.

"""2018
Hackerrank > UWI COMP2211 POTW-08 > Hopsquash
Peter Rabbit has found himself in Mr. McGregor's neighbour's garden.
This garden is packed with a number of small vegetables patches, but unlike Mr. McGregor's garden, it is not organised in a grid.
At least there are multiple patches of butternut squash,which Peter immediately seeks out.
Each vegetable patch is numbered from 1 to n . The rabbit hole from which Peter entered the garden is numbered 0.
The layout of the garden is specified by providing a sequence of pairs (S.i,T.i ) to indicate that Peter can go
from vegetable patch numbered to vegetable patch numbered T.i in a single hop. The type and quantity of vegetable
being grown at each patch is provided as a tuple (V.i,Q.i ) to indicate that patch i is growing vegetable V.i and there
""" 2018
Hackerrank > UWI COMP2211 POTW-08 > Palindromic Sort
Zoey loves marbles, for her birthday her father has given her n marbles which are comprised of m unique types.
Zoey wants to display her marbles in her room but first wants to sort them using what Zoey calls her Palindromic Frequency Sort.
The Palindromic Frequency Sort sorts elements based on their frequency. Lower frequencies precede higher frequencies,
and in the case of a tie, then the lower numbered marble precedes the higher numbered marble. For example,
if there were 3 types of marbles, and there were 10 of type 1, and 5 of types 2 and 3, then in ascending order,
they would be arranged as Type 2, Type 3, Type 1.
In Zoey's Palindromic Frequency Sort, the element with the largest frequency is placed at the center of the ordering.
@superrcoop
superrcoop / league-winner.py
Created March 26, 2018 01:50
Calculates the winner and loser of a league
'''
It's March Madness time again, and after watching a game you and a few of your friends decided that you should make your own fantasy league. Being a bit tipsy at the time, you decide to modify the rules a bit.
The number of teams, , can now be between and .
Each team may play multiple games over the course of the league, and each match earns points for both teams.
Standings in the competition are organized based on each team's current overall accumulated points. That is, the team with the largest overall point total will have a rank of 1 and the team with the smallest overall number of points will have rank .
When a match is played, both teams are rewarded league points according to the formula: where is the number of points scored during the match for the team and is the number of points awarded for the result of the match. The number of points awarded for each outcome of a match is defined as follows:
Condition R
Home Win 3000
Away Win 3500
@superrcoop
superrcoop / cracker.py
Last active April 9, 2018 16:17
very simple password cracker.. see advanced update @https://github.com/superrcoop/crackerjack
import crypt, getpass, pwd
import json,os,sys
import random
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
def gen_salt():
chars=[]
for i in range(4):
chars.append(random.choice(ALPHABET))
return "".join(chars)
@superrcoop
superrcoop / scanner.py
Last active April 9, 2018 16:19
Banner scanner is used to locate machines on a network with open, available ports and assess vulnerabilities
import socket
import sys
import os
import timeit
#grab the banner
def grab_banner(ip_address,port):
try:
print 'Creating socket and grabbing banner...'
s=socket.socket()
# Server to implement simplified Diffie-Hellman protocol and demonstrate socket
# programming in the process.
# Author: fokumdt 2016-10-01
# Version: 0.2
#!/usr/bin/python3
import socket
import sys
import random
@superrcoop
superrcoop / client.py
Last active April 9, 2018 16:15
very simple Diffie - Hellman key exchange. Your client and server will exchange the sequence of messages
# Client to implement simplified Diffie-Hellman protocol and demonstrate socket
# programming in the process
# Author: fokumdt 2016-10-01
# Version: 0.2
#!/usr/bin/python3
import socket
import sys
import math
import random
@superrcoop
superrcoop / CounterGame
Created May 14, 2016 15:04
Louise and Richard play a game. They have a counter set to N. Louise gets the first turn and the turns alternate thereafter.Given N, your task is to find the winner of the game.
import java.io.*;
import java.util.*;
import java.lang.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int in= scan.nextInt();
@superrcoop
superrcoop / codepython
Created March 28, 2016 19:16
Coding with Python!
#1. Let us begin by creating a constant. Call it Kand assign the value 6174 to it
k=6174
#2. Write a function called gt which accepts two arguments and returns a boolean that indicates
# whether the first argument is greater than the second.
@superrcoop
superrcoop / RandomNum
Created March 28, 2016 19:13
Random number generation and sorting in C
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);