mathmandan
  • Member for 6 years, 11 months
  • Last seen this week
First code golf decathlon
7 votes

Task 1, ><>, 10 + 3 = 13 bytes ::*-:*4,n; Run this using the official Python interpreter using the -v flag (at a cost of 3 bytes). This squares the quantity (n - n*n) and divides by 4, which of ...

View answer
It's Hip to be Square
6 votes

Python 3, 40 38 bytes Thanks to squid for saving 2 bytes! lambda n:n in(i*i for i in range(n+1)) Try it online! Too slow to return an answer for 2147483647 in a reasonable amount of time. (But ...

View answer
11 = (1+2+3+4+5) - (1+2+3) + (6) - (4)
5 votes

Python 2, 104 bytes N=input();i=s=0;l=() while N!=sum(l):exec'while sum(l)'+['<N:i+=1;l+=i,','>N:l=l[1:]'][s%2];s+=1 print s Try it online! Alternates between adding terms to the end of the ...

View answer
Uniquify Identifiers
5 votes

Python 2, 77 79 bytes a=input();u=[];j=1 for x in a: u+=[[x,j][x in u]] while j in u+a:j+=1 print u Takes keyboard input, like [3, 3, 3, 3, 3, 3]. Just keep track of the smallest positive integer ...

View answer
Golomb's wobbly sequence
5 votes

Python 2, 99 86 bytes Thanks to @Dennis for several improvements totaling 13 bytes! s=0,1,2,3 exec't=1\nwhile t==s[-1]or s.count(t)/s[t]:t+=1\ns+=t,;'*input() print s[-4] The program proceeds pretty ...

View answer
Base-2 integer logarithm of 64-bit unsigned integer
5 votes

Python 2, 26 t=lambda n:len(bin(n+n))-4 This is similar to the Python 3 answer by Tim S. However, doubling n and then subtracting 4 from the length has the advantage of working whether n is ...

View answer
Divisor skyline
4 votes

Python 2, 101 bytes N=input();r=range for i in r(N,0,-1):print''.join('# '[i>sum(x%-~p<1for p in r(x))]for x in r(1,1+N)) Try it online! This produces (a lot of) vertically leading whitespace....

View answer
Zipper multiplication
4 votes

Python 2, 99 bytes a,b=input();o=0;p=1-2*(a*b<0);a,b=abs(a),abs(b) while a:o+=a%10*(b%10)*p;p*=100;a/=10;b/=10 print o A lot of the bytes are there to account for the sign in case of negative ...

View answer
Hollow out an array
4 votes

Python, 50 bytes def f(a): for l in a[1:-1]:l[1:-1]=[0]*(len(l)-2) Accepts a list of lists, and modifies it in place. Python's slice syntax is not inconvenient for this task. I learned that ...

View answer
Alex is sometimes right
4 votes

Python 2, 264 bytes There's already a remarkable Python 3 answer by mbomb007. This answer steals flagrantly from that one (in particular the "Alex is wrriognhgt" trick). And this answer is ...

View answer
Iterated partial sums
4 votes

Python 2, 67 This uses the same summation as Anthony Roitman, and the same recursion as Morgan Thrapp. f=lambda l,n:f([sum(l[:i+1])for i in range(len(l))],n-1)if n else l I developed this solution ...

View answer
Is it a leap year?
4 votes

Python2 - 37 g=lambda x:(x%4or x%400and x%100<1)<1 Note that if a is a nonnegative integer, then a<1 is a short way of writing not bool(a). The last <1 thus effectively converts the ...

View answer
Bitflip-resistant composite numbers
3 votes

Python 2, 113 bytes r=range lambda N:[n for n in r(1,N)if 1-any((bin(k).count('1')<3)*all((n^k)%q for q in r(2,n^k))for k in r(n+1))] (The second line is an unnamed function which returns a list ...

View answer
Find the powertrain!
3 votes

Python 2, 111 bytes def p(n,b=0,o=''): if n<1:return n for c in str(n):o+=c+'**'[b:];b=~b j=eval(o+'1');return p(j)if j-n else j The idea is to make a string where the digits of n are ...

View answer
Define a function f such that f(f(n)) = -n for all non-zero integers n
3 votes

><>, 21 + 3 = 24 bytes, 22 points :0)$:0($:1$2%2*-*+-n; Use the official Python interpreter, and use the -v command line option to enter input, at a cost of 3 bytes. I have a feeling that ...

View answer
Alphabetic Fannkuch
3 votes

Python 2, 59 bytes def p(l): print l;o=ord(l[0])-97 if o:p(l[o::-1]+l[o+1:]) I guess this is a rather straightforward answer. Uses recursion and Python's slice syntax. Call as: p('eabdc').

View answer
Dutch Burgerservicenummer (BSN) eleven-test
2 votes

Python 2, 96 bytes def g(s):u=7<len(s)<10and sum(x*int(('0'+s)[-x])for x in range(2,10))-int(s[-1]);print(u%11<1)*u Takes a string as input. The function adds a '0' to the front of the ...

View answer
D&D Skill Challenges
2 votes

Python 2, 123 121 bytes from random import* def f(a,b,c): while c*b: r=randint(1,20);print r;c-=r<a;b-=r>=a if r in[1,20]:return r>9 return c (This answer mixes spaces and tabs, so ...

View answer
Find the nth Fibohexaprime
2 votes

Python 2, 127 bytes N=input();a,b=0,1 while N:a,b=b,a+b;t=int(''.join(c for c in hex(b)if ord(c)<65));N-=(t>1)*all(t%x for x in range(2,t)) print b The algorithm could be a lot more efficient. ...

View answer
Drop of Chaos (Constructing a Minimally Aperiodic Sequence)
2 votes

Python 2, 175 - 5 = 170 bytes n=input();s='';u=j=-1 while n>len(s): while u>2:u=int(s[0]);s=s[1:] u+=1;t=`u`+s;m=c=0 while t[c:]*0**m:c+=1;i=t[c:].find(t[:c]);m=j<i<=c if c>=len(t):...

View answer
What day is it (on Flooptonia)?
2 votes

Python 2, 168 bytes n=input();e=[-1,21,38,62,80,108,140,207];m=1 while n>e[m]:m+=1 print[`n-e[m-1]`+' '+'Qupu Blinkorp Paas Karpasus Dumaflop Lindilo Fwup'.split()[m-1],'Floopdoor'][n==80] This ...

View answer
Cryptographic hash golf (robbers)
2 votes

Python 2.x, 139 bytes by Puzzled H(2) and H(128) both return 16645614427504350476847004633262883518.

View answer
Divisible by 1000003? Easy, just multiply the last digit by 300001 and add!
1 votes

Python 2, 44 43 bytes (Crossed out 44 is still 44.) Thanks to Fireflame241 for saving a byte! P=input();i=P/3 while i*10%P-1:i-=1 print i Try it online! There is exactly one number between 0 and P-1 ...

View answer
Solve the Secretary Problem
1 votes

Python 2, 87 bytes a=input() t=int(len(a)/2.71828) m=max(a[:t]+[-1]) for x in a[t:]: if x>m:break print x The user enters the array as a list, with square brackets and commas. Python 2's input() ...

View answer
The Lucas-nacci Numbers
1 votes

Python 2, 71 bytes def a(n,x=0,y=1,z=2,w=1,p=0): if~n:print[x,z][p];a(n-1,y,x+y,w,z+w,~p) This definitely seems too long. However, I was pleased that I got to use the bitwise not operator...twice. ...

View answer
Exponentiation of natural numbers using only primitive integer operations
1 votes

Python 2, 67 62 bytes m=lambda x,y:y and x+m(x,y-1);p=lambda x,y:y<1or m(x,p(x,y-1)) This is an obvious solution: define multiplication in terms of addition, then exponentiation in terms of ...

View answer
Chunky vs. Smooth Strings
1 votes

Python 3, 69 bytes No one has posted a Python solution yet, so here's a fairly straightforward implementation of a "chunkiness" function. It short-circuits on a string of length 1, and ...

View answer
The Smart Person's Mirage
1 votes

Python2 Update: New version doesn't use any mod or division operations. word_dict = {3: 'Fizz', 4: 'Jazz', 5: 'Buzz'} def fizz_jazz_buzz(n, d): counters = {k: k for k in d} for i in xrange(...

View answer
Worn-tile Scrabble
0 votes

Python 2, 102 bytes (or maybe 95?) (Also fine for Python 3.) lambda a:''.join([r*7for r in'_ E DG BCMP FHVW K * * JX * QZ'.split()][x][:a.count(x)]for x in set(a)) Try it online! I don't think the ...

View answer
Check my tunneling arrays
0 votes

This answer does not work. Here for illustration purposes only. This answer passes all of the (currently) posted test cases. However, it fails (raises an error) on other valid input, such as [1, 2] ...

View answer