Skip to content

Instantly share code, notes, and snippets.

@TApicella
TApicella / RosettaCode- Multisplit.py
Created May 16, 2017 17:31
RosettaCode- Multisplit created by tapicella - https://repl.it/IBTP/3
'''
Task
Multisplit
You are encouraged to solve this task according to the task description, using any language you may know.
It is often necessary to split a string into pieces based on several different (potentially multi-character) separator strings, while still retaining the information about which separators were present in the input.
This is particularly useful when doing small parsing tasks.
The task is to write code to demonstrate this.
@TApicella
TApicella / RosettaCode- Middle three digits.py
Created May 16, 2017 17:50
RosettaCode- Middle three digits created by tapicella - https://repl.it/IBVw/5
'''
Write a function/procedure/subroutine that is called with an integer value and returns the middle three digits of the integer if possible or a clear indication of an error if this is not possible.
Note: The order of the middle digits should be preserved.
Your function should be tested with the following values; the first line should return valid answers, those of the second line should return clear indications of an error:
123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345
1, 2, -1, -10, 2002, -2002, 0
from PIL import Image
import random as r
import math
def distance(point1, point2, manhattan_dist=False):
if manhattan_dist:
return abs(point2[0]-point1[0]) + abs(point2[1]-point1[1])
else:
return math.sqrt( (point2[0] - point1[0])**2 + (point2[1] - point1[1])**2 )
@TApicella
TApicella / beergolf.py
Last active May 23, 2018 15:46
beergolf created by tapicella - https://repl.it/@tapicella/beergolf
p=print
r=str
m=',\n'
b=' bottles of beer'
w=' on the wall'
f='Take one down, pass it around'+m
n='.\n'
q=w+n
y=w+m
k=n+f