« first day (1396 days earlier)      last day (3439 days later) » 

12:45 AM
@hwnd there's another one
 
12:55 AM
@MartinBüttner there's another one
 
@MartinBüttner Is any part of PCRE allowed, i.e backtracking control verbs?
 
@hwnd I don't see why not, as long as you don't invoke Perl code ;)
do they work in the online tester?
 
1:11 AM
When you say using Perl code, I assume you're talking about something like this.
^([a-zA-Z]+)(??{my $len = length($1); qr([0-9]{0,$len})})$
And no online testers do not recognize this syntax.
 
yes, that's what I meant... well yes the online testers won't. but if someone wants to use the actual Perl flavour, I'm usually allowing them to write a test harness in ideone, if no online tester is available. and then you could theoretically use this stuff. not that it's feasible at 37 characters...
 
Hmm interesting to know, I probably could use this syntax.
 
Woah wow what the regex jump
 
lol
 
Good thing one of my regexes still works :D
 
1:25 AM
I love challenges!
 
@Sp3000 another answer and you might snatch user23013's top spot ;)
 
Heh. I wonder if user23013's seen the change yet
 
I did ping him I think
 
>> Posted on ASCII's 95 chars 2 hours ago
I take that as a yes
Hmmm i keep forgetting that you can have ] without escaping it
 
1:42 AM
I don't think there's any character that you actually need to escape inside a character class except the backslash.
in all other cases, think twice...
 
You have to escape [ if it's not the first character of the class.
 
I meant outside a character class :P
e.g. w]
 
@hwnd yeah, but you can always move it there, that's what I mean
wait no
you meant ], right?
@Sp3000 and yes, that's also true
furthermore, in some flavours you don't need to escape {} that don't form valid quantifiers
 
:o notes down
(I made my program escape everything just so I don't have to deal with problems like [P-G] when it means [-PG] and [!.]] when it means []!.])
(and then I take out the backslashes myself)
 
1:59 AM
damn, I should sleep...
 
what is "sleep"
 
Sleep is a crutch.
 
@Doorknob sorry, I meant "hibernate"
 
i am stumped on how one can save 14 chars off my code to find the first palindromic prime greater than n:
def golf(n):
 P=k=1
 while`k`*(P%k>0>n-k)!=`k`[::-1]:P*=k;k+=1
 return k
this is from the page checkio.org/mission/prime-palindrome-golf/publications that kjo linked to
(it has to be a function named golf and a recursion limit of 100 prevents obvious recursive solutions)
 
2:14 AM
Wait so what do the scores mean? Is it (some fixed number) minus your answer's length?
 
250 - length
so the top score corresponds to 58 chars
 
grc
it's interesting that the top solution is in Python 3.3
 
i was surprised by that
given the clear utility of backticks in checking for palindromes
is there some new built-in that's useful?
 
Let's find out!
 
grc
there doesn't seem to be
 
2:25 AM
You know, I'm wondering how many solutions there are given the limit
If there's only, say, 5 possible numbers then you could always just do a lookup table
 
they don't give the list of test cases, but I extracted it anyway
d={1:2,2:3,5:7,8:11,10:11,11:101,13:101,101:131,171:181,213:313,228:313,270:313‌​,679:727,551:727,750:757,771:787,931:10301,5157:10301,7091:10301,9000:10301,28535‌​:30103,37081:37273,98688:98689}
it's a lot, but i could imagine compressing it
golf=lambda n:min({2,3,7,11,101,131,181,313,727,757,787,10301,30103,37273,98689}-set(range(n‌​+1)))
that works but is too long
 
You could probably compress that down more with x+x[1::-1] since they all have an odd number of digits
... or maybe not
(didn't see 11)
 
11 aside, how are you using the odd number of digits?
 
I was hoping to not have to store the chars after the middle of the number, but I don't think that'd save that much...
 
oh, i see
that's a clever idea
and might allow recursion without exceeding the recursion limit
my approach though requires iterating through all number to generate the factorial, so it wouldn't work with this
 
2:36 AM
Yeah, I was thinking of other ways of prime checking but I can't think of anything as compact
I mean, Wilson's theorem would take just as much
 
just as much?
 
Prime iff (n-1)! = -1 (mod n)
Might be worse actually
 
that's what i'm using
 
... oh
 
i've found it to be generally quite shorter than the usual all(n%i...) when you're iterating over n
 
2:38 AM
I thought you were doing n does not divide (n-1)!
 
oh, i am
ok, i guess i'm not using that the product is -1 mod n for primes
just that's it's 0 for composites
 
:P
 
except for 4, which thankfully isn't tested
so we can pretend it's a prime
i was tempted to use the stronger version to produce the -1 in [::-1]
to make the reversal work only if wilson's theorem does
but it throws an error when it's 0
and things like [::-2] still work to reverse one-digit numbers
 
I wonder if some shortcutting is possible... gimme a sec
Nope :P can't do k[0]*(...)!=k[-1]
 
the poor man's palindrome check
 
2:52 AM
You could do

import random
golf=lambda _:random.randint(0,1e6)
You'd beat the top guy by a long mile once you get it
 
haha
actually, only by 5 chars :-o
err, 8 chars
 
I don't think the 1e6 is doing what I want D:
 
those darn floats
should be an int, but nooooo
ruining ranges everywhere
 
Python would be so much better for golfing if it just truncated the float
Too bad Python's not meant for golfing though ;D
 
yeah, though i think range(1e6) is pythonic enough for real code
 
2:57 AM
:/ yeah...
 
your code actually runs on their framework!
victory is (eventually) assured!
you can do similar without import random by getting id(0)
 
I don't think that'd work, would it?
It's just an address
 
id(0) gives a different large random-looking value each time
 
grc
3:34 AM
def golf(n):
 while`n+1`!=`n+1`[-2**n%~n::-1]:n+=1
 return n+1
3
 
what does -2**n%~n do?
 
grc
Fermat primality test for n+1 with base 2
 
whoa
that's a primality test?
that's so short
 
grc
but it gives -1 instead of 1 for indexing
it only tests for pseudoprimes to base 2
which seems to work in this case
 
how does this work?
what value does 2**n%~n give for primes?
 
grc
3:39 AM
1-n
from here, we get 2**n % (n + 1) == 1
 
Nice :o is that the one that fails on Carmichael numbers?
(not that I think that applies to any of the test cases)
 
grc
Carmichael numbers fail for all possible bases
this only tests one base
so it fails for these
 
Ahaha nice
Does that beat the top solution? :D
 
grc
nope :(
ties with second
 
:( damn
 
3:43 AM
still, that's amazing
 
grc
... and -2**n%~n is just 2**n % (n + 1) == 1 modified to give -1 (which is better for indexing)
 
yes, the offset by 1 is weird
 
Didn't think Fermat would work well enough when restricted to one base :o
 
grc
yeah I was thinking of miller-rabin
but that was too long
 
what magic you can do when your program just has to work on test cases!
 
3:46 AM
:P
 
so i'll note that just doing n+=1 at the start breaks even on characters
any chance that the condition is nicer to write without the offset?
another thought
 
Thing is, you need the next one larger than, right?
So 2 needs to return 3...
 
grc
you can try, but the primality test is shortest for testing n+1
 
ok
another thought then
the while is what's forcing separate lines
what do you think of an exec loop instead?
the body of the loop would increment n if it fails to meet the conditions
so when a good n is reached, it would get stuck on it, even if the loop keeps executing
(is there a way to import backticks for repr into python 3?)
 
TypeError: can't multiply sequence by non-int of type 'float'
Damnit 1e6
 
grc
3:55 AM
exec loop:

def golf(n):exec"n+=`n+1`!=`n+1`[-2**n%~n::-1];"*9999;return n+1
 
did that save chars?
 
grc
no
 
Hmm was trying that, didn't know exec didn't need ()
 
darn
 
grc
Python 2's exec is a statement
for some reason
 
3:56 AM
... well I'm glad they changed that one too
 
the six-char string =`n+1` appears twice in the exec loop
probably still too short to save on the repetition though
 
grc
return-~n saves a char
 
Hah, that trick
 
i think *n*n suffices for *9999
 
I wonder if something like golf=lambda n:eval() if possible. Would be insane though
 
4:01 AM
hmm
i with you could sneak an exec into a lambda
 
You can, it just returns None :/
 
wait, but does it execute the code?
 
>>> y=lambda x:exec("print('Hi')")
>>> y(5)
Hi
(Python 3)
 
but : f = lambda n:exec("n+=1") or n \n print(f(3))
gives 3
 
grc
>>> f=lambda x: exec("global y;y = 5") or y
>>> f(3)
5
 
4:05 AM
>>> f = lambda n:exec("n+=1;print(n)") or n
>>> print(f(3))
4
3
Scope yeah
 
why doesn't this work?
x=3
f = lambda:exec("x+=1") or x
print(f())
 
My guess is probs exec is like functions in terms of local variables/scope
Hence grc using global
 
i guess that makes sense, though then i'd expect my code to throw an error
 
>>> golf=lambda n:exec("global n;n+=str(n+1)!=str(n+1)[-2**n%~n::-1];"*n*n)
>>> golf(5)
Traceback (most recent call last):
  File "<pyshell#23>", line 1, in <module>
    golf(5)
  File "<pyshell#22>", line 1, in <lambda>
    golf=lambda n:exec("global n;n+=str(n+1)!=str(n+1)[-2**n%~n::-1];"*n*n)
  File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
    file.write(warnings.formatwarning(message, category, filename,
AttributeError: 'NoneType' object has no attribute 'write'
!?
Never seen that error before
 
grc
:o
you broke python!
 
4:12 AM
It's too long anyway XD
So what, we're on 61, need 58?
 
grc
yeah
 
Random side note: Should have totally put <> in one of my Unscramble cops to confuse people
Makes your code look 90% more hackery
 
grc
yours were hard enough already...
did you ever reveal your solution btw?
 
I revealed the 60 char one, so I don't intend on revealing the other one
It's basically like DLosc's
(although I think it's easier)
 
grc
using an underscore four times as a variable is sneaky :P
 
4:19 AM
whistles
 
grc
wow the submissions are still flowing in for that question
 
Yeah - I've given up though, exhausted all my good ideas :P
 
4:32 AM
def golf(_):
 while`-~_`<>`-~_`[-2**_%~_::~0]:_+=1
 return-~_
There we go, now it looks more like golfed code :D (despite no char changes)
 
grc
that's beautiful :)
 
i tried saving some chars with the following, but it breaks:
`n+1`!=`n--2**n%~n`[::-1]
the idea is to make the -1 that comees from the Fermat test part not participate in the slicing, but rather in the +1
with the hope that nothing coincidentally comes up as a "palindrome" due to some other offset
unfortunately, when n is sufficiently large, the repr appends and L to the end
even when the result of the expression is just n+1, because the intermediate steps of 2**n gave a large number
 
Ah...
 
5:15 AM
Regular everyone-in-chat-works-to-golf-something-down sessions sound fun :P
11
My Chrome's not liking the CheckIO site though :(
@xnor I just solved a problem but solutions don't seem to be sorted by bytes - is golfing only for some problems or something?
 
i guess not?
this one took pains to explain that it wanted shortest code, so i assume most are not
i just joined the site today to look at the palindrome prime problem
 
Hm k...
Well I was doing this one: checkio.org/mission/non-unique-elements
Trying to find where all the other golf ones are (if any)
 
maybe we can steal them for PPCG :-P
and make them golf
that's a cute problem
 
Pick one and let's get started >:D
 
we can golf it in chat anyway?
 
5:26 AM
Yeah k, that works
Well I've got the ever-versatile 47-byte
checkio=lambda x:[a for a in x if x.count(a)>1]
 
cool
too bad you can't do filter(x.count-1,x)
 
Yeah :( needs lambda
 
checkio=lambda x:[a for a in x if~-x.count(a)]
 
Touche :P
 
that's all i got
there isn't away to subtracts two lists, is there?
 
5:32 AM
Hmm not that I can think of
 
it would be nice if there were something like x-list(set(x))
map(x.remove,list(set(x))?
 
It's returning Nones
Hmm having to keep the list in order makes it a bit trickier to golf
Maybe another problem?
 
darn, checkio=lambda x:[map(x.remove,set(x)),x][1] works, except I was dumb and forgot that it removes one of every element, duplicate or not
ok, another problem
 
Oh, I found Prime Palindrome Golf
It's tagged codeGolf, but the tag's not clickable :(
Maybe this one?
 
ok, cool
can we say no import re?
 
5:44 AM
Ahaha if you want, but I'm having trouble thinking of a good short regex anyway
 
i'd rather just not check :-P
 
D: well we can see how we go without it, and later if we have time with it
 
ok
 
Well, I have 98 :/
... 80
 
i got 64
 
5:56 AM
I have 74 now :/
 
did you see "Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. "?
you can exploit truthiness
 
Hmmm
71
Need a better way to check for digits
 
i guess i'm doing something different
uppercase letters are my issue
 
Uppercase? Interesting...
Damnit I wish I could get rid of my length checking portion but I can't :/
 
6:12 AM
oh, shoot, my program crashes on the empty string
 
D:
 
oh, wait, 0 < len(password) ≤ 64
 
Ah nice :P
 
down to 57
 
:o
 
6:19 AM
i think i'm not getting better than what i have
should I show you?
 
Hmmm, go for it - I don't think I'll break 60 any time soon
 
i can give you hint if you want?
how are you doing it?
 
I had x.upper()<x<x.lower() but now I'm trying sets
 
oh, that's exactly what I'm doing
err, the inequality
 
Hence why I said digits
 
6:23 AM
oh, i see, i had been doing something different at the time
that has trouble with capital letters, strangely
but the ineq took care of it
 
Hm k...
 
i think you're just forgetting a little thing and you'll slap your forehead when you see it
 
Oh? thinks about it
Ah I think I know what you mean
Well that gives... 63. Hm.
 
grc
it might be easier if you look at the test cases again :P
 
oh, i wasn't using the test cases
 
6:37 AM
Neither :P
Still stuck at rearranging:
checkio=lambda x:(min(x)<":")&(x.upper()<x<x.lower())&(x[:9]<x)
 
are you playing along with this golf, grc?
@sp3000 there's some tricks from the practice golf that might come in handy :-)
 
Probably is :P
I wanted to shove the x[:9] in the inequality
But unfortunately x.upper() and x[:9] aren't comparable
 
i'm using python 2, but there they're uselessly comparable
the list is always smaller
 
Well I don't mean that, I just mean there exists cases where one's bigger than the other
 
oh, i see
so chaining is a good idea
 
grc
6:41 AM
@xnor I got to about 100 then stopped
 
x.upper()<x<x.lower()
          v
          x
          [
          :
          9
          ]
If only
 
grc
befunge-python
 
wait, I don't think x>x[9:] does what you want
it basically compares the first and tenth character of x
oh, x[:9], whoops
vertical python is hard to read :-P
 
:P
I got so confused by upper/lower I didn't realise this actually works:
checkio=lambda x:(min(x)<":"<"_"<max(x))&(x[:9]<x<x.lower())
60 though
 
nice
now chain some more!
 
6:50 AM
checkio=lambda x:min(x)<":"<"_"<max(x)*(x[:9]<x<x.lower())
If you say so :P
That's one short though, 58
 
i think you're going to get something better than 57
 
Am I? D: Do you see something I'm not seeing?
(actually what did you use for length comparison?)
 
no, you're just doing something a bit different and I think better than what I did with the length-checking
i used s[9:]*(rest)
 
I just thought x[:9]<x was better than len(x)>9 :P
 
but if you can chain x[:9]<rest by getting the rest to start with x as you're doing, that's 2 chars shorter
 
6:53 AM
Oooh interesting
 
grc
you could use single quotes to save some pixels
 
Ahaha I have a habit of using double quotes almost everywhere
 
grc
I always use single quotes for golfing cause it looks shorter :D
 
I wonder why people tend to use single
XD
Should I switch all my xs to _? ;D
 
grc
pity you can't use space as a variable
 
6:57 AM
` +( ^ _ ^ )+ `
Oh the horror
(that's space-space plus (space xor space-underscore-space xor space) plus space-space)
 
@grc by the way, you should submit your palindrome prime golf on that site for a nifty second place
 
checkio=lambda x:max(x)>"_">":">min(x)<x[:9]<x<x.lower()
56! All the chaining
 
nice
 
(why didn't I think of this earlier)
 
i wish python had a binary comparison operator ? that is always True
so that you can unconditionally chain things together
 
7:07 AM
How come?
Ah, right
 
other completely useless things on my golf wishlist:
- A character that causes Python to crash if it appears other than in a comment or string (for the jumble cops and robbers)
- A conditional version of print that does if b: print x
 
- Everything to not be three or more chars long
 
good one!
 
Surely that's the biggest point on your wishlist :P
 
grc
builtin regular expressions
 
7:10 AM
I mean, pick your poison: lambda x: or def ... return
 
grc
and some of perl's operators
 
@Sp3000 i was hoping santa would be more likely to give my present if I tried for something small
 
Ahaha nice. Maybe itertools, random, re, string etc. imported by default
 
this is sounding more and more like Pyth...
 
It's the only reason Pyth exists, surely :P
"I want to use Python but stuff is too long"
 
7:13 AM
From what I can see, the rules are quite different, almost none of the answers are reusable and most of the answers in the later question implicitly convert string to int.
 
@MartinBüttner here's a solution with 40 bytes:
 
In fact, the question is more similar to codegolf.stackexchange.com/questions/40257/… which was also initially thought to be a dupe of codegolf.stackexchange.com/questions/20996/…
 
}0
^0
=0&23169
&1
}0
^1
>0
+Z\/&1&2
+9
 
7:27 AM
Ooooooh hell
Interestingly the top solutions are all Py3
 
i got 85 chars
8 chars off
 
7:43 AM
:o nice
I don't even know where to start
(import itertools is probably a bad idea)
 
7:57 AM
is there a short way to convert a set to a Boolean that represents whether it's empty?
or nonempty
lists have l>[]
 
You can do <{1}
If you know the set doesn't contain 1
(Also I have 124 so far, terrible. Sure I can do something about this arithmetic...)
 

« first day (1396 days earlier)      last day (3439 days later) »