def gcd(a, b)
a %= b
a == 0 ? b : gcd(b, a)
end
class Fraction
def initialize(num, den)
@num = num
@den = den
simplify
end
class << self
private def simplify
frac_gcd = gcd(@num, @den)
@num /= frac_gcd
@den /= frac_gcd
end
end
end
test = Fraction.new(5, 2)
puts test.num
Why doesn't this work? It errors on simplify in initialize.
# + adds
# - subtracts
# / divide
# * multiply
# s sqrt
# % mod
# a set vars to stack
# g sets stack to numbers
# q pushes value of stack to numbers
# i incrament
# d decrament
# r stops subtraction at 0
# w turns back on subtraction past 0
# [ starts loop
# ] ends loop runs until stack is 0
# { starts loop
# } ends loop and loops until loops[ln] is 0
# k incrament loops
# . prints ascii value of stack (starts at a=1)
# , adds ascii value of stack to stri
# > prints stri
# < prints stack
# _ prints ascii stack starting at 48
Newline
Disclaimer: It is a bit of a mess and pretty simple. This is the first language I have ever written and the conjecture is the only one I understood. I know another user had a longer answer with the same one but I decided to write this anyway.
To write in Newline you must have a lot of t...
That is the challenge I wrote it for. Redoing it
I am going to have the super-annoying-eso-mode a command line flag (making this unstoppable for bowling)
If you are not familiar with Braid-Theory I recommend that you read this first. This question assumes that you are at least familiar with the concepts at hand and assumes you are well familiar with group-theory
Let us define σn to be the braid in which the nth strand (One indexed) from the ...
@HyperNeutrino nah, its the implementation that is semi-complicated mostly... but I guess the bots would also be complicated if they wanted to predict collisions...
Python 2, 295 293 bytes
def s(a):
for i in range(len(a)-2):
if a[i]==a[i+2]and a[i]==a[i + 1]+1:a[i]-=1;a[i+1]+=1;a[i+2]-=1;return a
for i in range(len(a)-1):
if a[i]>a[i+1]+1:a[i],a[i+1]=a[i+1],a[i];return a
return a
def r(a):
y=s([x for x in a])
while y!=a:a,y=y,s(y)
return y
print r...
Python 2, 353 bytes
def s(a,r=range):
for i in r(len(a)-2):
if a[i]==a[i+2]and a[i]==a[i+1]+1:a[i]-=1;a[i+1]+=1;a[i+2]-=1;return a
for i in r(len(a)-1):
if a[i]==-a[i+1]:return a[:i]+a[i+2:]
for i in r(len(a)-1):
if a[i]>a[i+1]+1:a[i],a[i+1]=a[i+1],a[i];return a
return a
def r(a):
y=s(...
I will sacrifice 2 temporary reputation and 1 temporary score so you can get a screenshot ><
theoretically you could obliterate someone if they had twice their rep as number of posts and they had less rep than half of your rep minus 125 by downvoting their every answer
Traceback (most recent call last):
File ".code.tio", line 13, in <module>
print r(input()) == r(input())
File ".code.tio", line 11, in r
while y-a:a,y=y,s(y)
TypeError: unsupported operand type(s) for -: 'list' and 'list'
numpy does some pretty interesting stuff with operator overloading; for example some_array == value will return a boolean array of True where the condition is satisfied and False elsewhere
Python 3 + pipe, 129 bytes
This solution uses the pipe module off pip (written by Julien Palard).
from pipe import*
a=range(1,int(input())+1)
a|reverse|izip(a)|select(lambda a:"%s%s"%a)|aggregate(lambda a,b:"%s%s"%
(a,b))|stdout
This approach didn't really work out, but I figured I'd post i...
that account belongs to my friend Chloe except she never actually used this account she just wanted to get enough rep to chat on our french TNB room lol. she doesn't know programming lol, so that's what one of my other friends wrote, except the answer failed to get her enough rep lol