Skip to content

Instantly share code, notes, and snippets.

View AbstractBeliefs's full-sized avatar

Gareth Pulham AbstractBeliefs

  • Scotland
View GitHub Profile
def adds_10(initialValue):
return initialValue + 10
if __name__ == "__main__":
while True:
print adds_10(input("> "))
from PIL import Image
instring = """0 0 0 0 0 0 0 1 1 0 1 1 0 1 0 1 1 1 0 0 0 0 0 0 0
0 1 1 1 1 1 0 1 1 1 0 1 1 0 0 1 0 1 0 1 1 1 1 1 0
0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1 1 0 1 0 0 0 1 0
0 1 0 0 0 1 0 1 0 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0
0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 1 0 1 0 1 0 0 0 1 0
0 1 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0
0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1
class CraicBot(sleekxmpp.ClientXMPP):
# Initiate the bot, set event handlers for when messages come in
def __init__(self, jid, password, room, nick):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.room = room
self.nick = nick
self.add_event_handler("session_start", self.start)
>>> def getargs(*d):
print d
>>> getargs(1,2,3)
(1, 2, 3)
>>> getargs([1,2,3])
([1, 2, 3],)

Raindrops

Write a program that converts a number to a string, the contents of which depends on the number's prime factors.

  • If the number contains 3 as a prime factor, output 'Pling'.
  • If the number contains 5 as a prime factor, output 'Plang'.
  • If the number contains 7 as a prime factor, output 'Plong'.
  • If the number does not contain 3, 5, or 7 as a prime factor, just pass the number's digits straight through.
def getPrimeFactors(number):
if prime(number):
return [number]
else:
prime = getLowestPrime(number)
return getPrimeFactors(number/prime).append(prime)
Exercism Corrections
====================
void setup(){
Serial.begin(9600);
}
void loop(){
Serial.println(Serial.parseFloat());
}
#include <stdio.h>
#include <stdlib.h>
void caeser(char* input, int shift){
do {
*input = *input - 'a'; // convert to 0-idx alphabet
*input = *input + shift; // shift
*input = *input % 26; // wraparound going past z
*input = *input + 'a'; // shift back to ascii alphabet
} while (*++input);
#include <stdio.h>
#include <stdlib.h>
void caeser(char* input, int shift){
do {
*input = *input - 'a'; // convert to 0-idx alphabet
*input = *input + shift; // shift
*input = *input % 26; // wraparound going past z
*input = *input + 'a'; // shift back to ascii alphabet
} while (*++input);