« first day (2474 days earlier)      last day (2368 days later) » 

6:03 PM
@Adám J: *?@0:
 
@FrownyFrog Nice, but can you find another one which doesn't use a constant function but rather the normal number 0?
 
Not (*[:?0[[)?
 
@HyperNeutrino actually you can save a byte: 2 .__rtruediv__
 
@FrownyFrog No, 5 bytes.
 
6:12 PM
@EriktheOutgolfer oh hey cool :D thanks
 
the decimal point needs to be right after the integral part, without a space
 
right that makes sense
oh I get why 2.__truediv__ is a syntax error now
 
why?
 
for the same reason 0or is a syntax error
 
Anonymous
@FrownyFrog It tries to parse it as a float
 
6:14 PM
So 2 .__truediv__ would work
 
Anonymous
You can also do 2..__rtruediv__
 
Or would you need (2).__truediv__?
 
@Adám the 5-byter is elusive, man. Closest I got still uses ?0
 
@EriktheOutgolfer it isn't though
 
6:15 PM
shorter way to do this? or in ruby?
 
Anonymous
@HyperNeutrino It was in Py2
 
A=[input().split()for i in' '*int(input())]
A.sort(key=lambda x:-float(x[1]))
print(*[k for k,v in A])
 
@Mego oh okay
 
@HyperNeutrino not a trailing 0, just 0
 
@J.Sallé ×∘?∘0
 
6:15 PM
read in a bunch of vals like ("word", .5) to an array A
sort it by the numbers in reverse
print the words
 
850or 0 isn't a syntax error, 0or 1 is though
@Mego I think it's in python 3 too
or was it fixed in 3.6
 
Anonymous
@EriktheOutgolfer I think 3.6 fixed it
 
@MarcusAndrews what is x
 
Anonymous
@MarcusAndrews If you can coerce the input into Python lists/tuples with eval and reverse them with [:-1], you can do A.sort() without the key arg
 
6:17 PM
it's the lambda parameter
shrunk it a bit:
A=[input().split()[::-1]for i in' '*int(input())]
A.sort(reverse=True)
print(*[v for k,v in A])
 
Anonymous
@MarcusAndrews Instead of reverse sorting it, print it out reversed
 
whoops I messed up somewhere
 
(*?)&0?
 
values are wrong now
 
Anonymous
So A.sort();print(*[v for k,v in A[::-1]])
 
6:18 PM
I had to go back to the lambda
 
@FrownyFrog *&?&0
 
values were wrong when I tried to remove it
 
I can't read that
It also gives me 0 like 20% of the time lol
 
ah it's because it's comparing the nums as strings
not floats
damn it
looks like that float in the lambda was important
 
6:23 PM
just need to shave off a few chars
aacchhghghghjg
A=[input().split()for i in' '*int(input())]
A.sort(key=lambda x:-float(x[1]))
print(*[k for k,v in A])
 
@FrownyFrog That is odd. By definition it should work, no?
 
I don't understand the syntax
 
ran out of time
oy
 
@MarcusAndrews you don't seem to be using A more than once
first of all you can get rid of list.sort and use the sorted builtin instead
 
@FrownyFrog Ah, you're right. My bad.
 
6:26 PM
I needed the sort because the inputs were strings
the lambda converts the number string to actual numbers
 
that will not save any bytes but now you're using A only once
 
@Mego ohhh thats where erdogan got the idea
 
needed to get the right result
 
(exactly same here btw)
 
@MarcusAndrews huh
 
6:27 PM
lexicographic comparison vs numeric comparison
 
@Adám What do you mean I'm right? It's not a correct function?
Or I'm right that I don't understand it?
 
@FrownyFrog No, I fooled myself in the apparent similarity between J and APL. But & here does that strange power (^:) like thing.
 
@MarcusAndrews so you can't use sorted?
I don't think that's true
 
No I can use sorted, the lambda was just hard to get rid of
since I needed to cast certain elements in A to floats at some point
and couldn't do it nicely in the first step
 
6:30 PM
as you can see using sorted will not save any bytes, but it will make you use A only once, which is very wasteful
 
I need to sort it though
 
@Adám (*?)&0 is six
 
@MarcusAndrews so now you can replace "A" with its actual contents for -4 bytes
 
@FrownyFrog Yup. That's what my J expert colleague said too.
@FrownyFrog So your *?@0: is the best.
 
Ah I see what you're saying now
 
6:32 PM
plus, sorted doesn't need a variable to sort in-place like list.sort
 
Cool
 
what do you mean by "doesn't need a variable"?
 
it doesn't need A anymore
 
Ah, right
 
but now I can see something which is either just a big, big waste of bytes or that there's some bug in your code
 
6:35 PM
@Adám So what does *&?&0 (3) do? I assume it does something 3 times but what?
 
@MarcusAndrews input is first line is number of next lines, and then some space-separated strings right?
 
the input looks like:
10    <--- number of items to follow
word .15
pepsi 4.6
anotherword 1.6
bus 3
...
The idea being to print out the words on a single line, space-separated, from lowest to highest number
 
your code doesn't seem to do that
it sorts from highest to lowest number...
@MarcusAndrews that's because you negate the number after you convert it to float
 
I may have misremembered the order
whatever it is, the code works
my memory of the instructions may be off
it may have been highest to lowest
 
so that brings down to 97
unfortunately using zip won't save anything here
 
6:43 PM
@FrownyFrog Ah, it isn't even the powery thing. It is (?N) * (?0), so every time ?N gives zero (i.e. one Nth of the time), it results in zero (to the power of a non-zero value).
 
another one, clearing the most significant set bit
 
@Adám If it's sign ? sign ? sign ?0 it would always be 1 Ithink
 
for i in' '*int(input()):k=int(input());pos=len(bin(k)[2:])-1;print(k^(1<<pos))
 
@FrownyFrog It isn't sign, it is multiplication.
 
I think it can be faster in ruby
 
6:44 PM
@Adám Got it
 
ok, tried translating to ruby:
gets.to_i.times{n=gets.to_i;p n^(1<<n.to_s(2).size-1)}
Can this be improved?
 
@MarcusAndrews but you can get the python one down to 93
 
took the length of the num in binary (minus 1) to get the exponent of the MSB, then xored to clear
 
@FrownyFrog Gosh, who am I, teaching J? I don't even know J. I just piece things together from the docs.
 
ruby is at 54
 
6:46 PM
the x.pop() will remove the second element of each word-number pair
 
@Adám I just used you as a proxy to your resident expert
 
so you can just concatenate all instead of picking the first element
 
sorting by the key of x.pop?
clever
 
@FrownyFrog He's really handy to keep around. Hm, maybe I should feed him…
 
@FrownyFrog heh
 
6:51 PM
is there a shortcut for size in ruby?
gets.to_i.times{n=gets.to_i;p n^(1<<n.to_s(2).size-1)} to simplify the size piece here
 
I don't know ruby :p
 
CMC: Prove that doing CRC32 twice is not nearly as strong as CRC64.
 
apparently gets.to_i.times{n=gets.to_i;p n^1<<n.to_s(2).size-1} works too
I guess << has a really firm precedence
 
don't know about ruby, but in python the precedence of << is lower than the precedence of +, ^, |, &, etc.
@Adám um why
 
@EriktheOutgolfer Why prove it? Hey all CMCs are optional.
 
6:58 PM
oh alright just thought maybe it has to do with something you want to take much less time
 
@EriktheOutgolfer No, it is inspired by an internal company discussion in which I just received another email.
 
Is someone trying to argue that CRC32 twice is just as strong as CRC64? O.o
 
it's like "apply enhance video quality version 1 twice" vs. "apply enhance video quality version 2 once" lol
 
Bitmap it
 
Anonymous
@Adám Pigeonhole principle. There are only 2**32 outputs from CRC32, so applying it twice still only gets you 2**32 possible outputs (though they're potentially a different set). In fact, if you know that it's applied twice, you know every possible output, since it doesn't depend on the input.
 
7:04 PM
lock on and enhance the z-axis
 
he gets it
 
Anonymous
CRC32 twice isn't even as strong as CRC32 once, so comparing it to CRC64 isn't even relevant
 
@Mego But if the first part has 2³² possibilities and the second part too, doesn't that give 2³²×2³² possibilities overall?
 
what do you mean exactly by CRC twice?
 
Anonymous
@Adám No. Assuming that CRC32 is a decent hash function (spoiler: it isn't), it will map each 32-bit integer to a different 32-bit integer.
 
Anonymous
7:06 PM
@NieDzejkob CRC32(CRC32(x))
 
> decent hash function
 
@Mego I think Adam should answer that one
 
dunno if using "decent" and "hash" in the same sentence is very legit ;p
 
Anonymous
So by applying CRC32 twice, you get an output that only relies on the CRC32 hash of the input, rather than the input itself, so collision attacks are substantially easier.
 
Pull it back to "CRC2" -- 4 possible outputs done to 4 possible outputs still only yields 4 possible outputs. You could do "CRC2" a million times and you'd still only have 4 possible outputs.
 
7:09 PM
@NieDzejkob @Mego Ah, I mean two separate hashes done with two different seeds, and then then hashes concatenated to form 64.
 
Anonymous
The same principle applies for any hash function: since the hash only depends on the (single) hash of the input, it's easier to find a collision. Thus, for any hash function H, H(H(x)) is weaker than H(x), and you should never ever do that.
 
Anonymous
@Adám In that case, you just cut the hash in half, and break both CRC32 hashes.
 
@Mego Oh, right. Maybe I've not understood the discussion properly.
 
Anonymous
Concatenating hashes doesn't cause the avalanche effect to happen, so it's very easy to extract the relevant parts of each hash.
 
Reminds me of the old NTLM password cracks
 
Anonymous
7:12 PM
The "correct" way to do block hashes ("correct" meaning the way that SHA and friends do it) is to use an initial seed for the first block, and then have the output of the first block combine with the seed in some data-destructive manner to derive the seed for the second block, and so on.
 
Anonymous
Data-destructive meaning that, if you have a function f(a, b) = c and you know a and c, you can't know the value of b for certain. For example, XOR is not data-destructive, but AND and OR are (for certain inputs).
 
Anonymous
There's an actual term for that kind of operation but I can't remember it
 
Anonymous
I guess many-to-one would work
 
Anonymous
And as icing on the insecure cake, CRC is easily reversible, so using CRC at all for anything that requires secure hashing is a terrible idea in itself. CRC is a checksum algorithm, not a hash algorithm.
 
Anonymous
</rant>
 
7:20 PM
"lossy" operation?
flattening? idk
 
Is f(a, b) => 1 data-destructive enough /s
 
I've never heard of CRC being used as a hashing algo, that seems a little strange
 
@Mego Ah, right this is how it goes: If you concatenate the two CRC32s then you don't just need to find a string for each CRC32; you need to find a single string which will give those two CRC32s.
 
0
A: Sandbox for Proposed Challenges

Magic Octopus UrnPalindrome Jumbles Given a list of strings l, find the longest palindrome you can make from combining any number of the input words (forward or backward). If no palindromes can be formed, return an empty string. Examples [a,a,a,man,plan,canal,panama] 'amanaplanacanalpanama' [a,a...

 
Java doesn't let you use reflection to extend classes at runtime and I can't decide if this is a bad thing or a good thing.
 
7:28 PM
extend how?
 
@Pavel You can always take a look at the Unsafe internal api ;)
 
@Pavel At least we're sure it's a thing
 
@NewSandboxedPosts They like Palindromes...
 
@MarcusAndrews My school uses a thing to prevent accessing java.util at compile time so I hoped to try extending a java.util.Stack with my class at runtime instead
The idea is to implement a class representing a stack of strings and my idea was essentially public class StringStack extends java.util.Stack<String>
 
Anonymous
@MarcusAndrews Some people do it. Those people are wrong.
 
Anonymous
7:36 PM
@Adám The same applies for any hash algorithm, even without concatenation. Finding two inputs that each hash to specific outputs is not more difficult than finding a single input that hashes to a specific output.
 
Anonymous
How difficult that is depends on the specific algorithm.
 
@Mego Some people also use MD5 for passwords and others think the world is flat. It's best not to put too much stock into what "some people" think.
 
Anonymous
@StewieGriffin Looks good, though I expect all of the answers to use Johnson-Trotter
 
Anonymous
@Pavel The problem happens when people put sensitive information behind MD5-hashed passwords
 
7:38 PM
Any way to compress this?
g=input()
w=int(input())
print(int(w/1.2)if g=="M"else int(w*1.2)if g=="F"else"INVALID")
either python/ruby
 
"... googling Johnson-Trotter"
 
Anonymous
@MarcusAndrews print({'M':w//1.2,'F':int(w*1.2)}.get(g,"INVALID"))
 
int(w*1.2) -> w*6//5
 
Anonymous
If you can reverse the order of the inputs, you can drop g=input() and do .get(input(),"INVALID")
 
Unfortunately doesn't work
I can't reverse the order
very cool way of handling if/elif/else though
 
7:42 PM
Wait... can you do x//1 instead of int(x)?
idk Python very well
 
Anonymous
@ETHproductions Not if x isn't an int/float
 
Anonymous
input() in Python 3 returns a string
 
yeah, good point
 
Anonymous
@MarcusAndrews dict.get is usually better than if/elif/else. List indexing is even better, but can only be used in certain scenarios.
 
@MarcusAndrews Ruby: g=$_;w=eval gets;$_=g==?M?(w/1.2).to_i:g==?F?(w*1.2).to_i::INVALID, and use the -p flag
 
7:43 PM
That 5/6 and 6/5 trick is nice though
lots of good tips all at once XD
hm not sure if I can set the flag
 
@MarcusAndrews If you can't replace $_ with gets in the first statement and $_= with $><< in the last one.
 
@Pavel why on earth is ?x a thing in Ruby
 
@ETHproductions ?x expands to 'x'
 
Yeah, but what's that useful for? just plain shorter code?
 
Anonymous
Ruby is like if Python and Perl had a child and then dropped it on its head a few too many times
 
7:47 PM
@ETHproductions It used to mean 'x'.ord but then they dropped the .ord and kept the syntax
 
That would make a bit more sense I guess
 
@Mego If the father is Perl I don't think any dropping-on-head is required.
Ruby is only weird if you use it in weird ways. No one says you have to use the ?x syntax, and it's considered bad practice to do so in production.
 
@Mego erm, builtins :p
 
Anonymous
@EriktheOutgolfer Builtins are still probably Johnson-Trotter, so my point stands
 
@Mego Mathematica's is probably some sort of hypersonic wizardry the Wolfram people cooked up
 
7:51 PM
@EriktheOutgolfer I don't think you'll be able to use any builtin algorithms, implementing J-T yourself is possibly a nice way to solve it (but I don't know).
 
another one, taking in a list of vectors, negative the items of every-other-one, summing them all up and displaying
d,n=map(int,input().split())
f=1
S=[0]*d
for i in range(n):
 v=[f*k for k in map(int,input().split())]
 S = [S[k]+v[k] for k in range(d)]
 f*=-1
print(*S)
my current attempt
 
> You must restrict the memory usage to O(n^2), where n is the number of elements in the input vector. You can't have O(n!). That means you can't store all permutations in memory.
oh no I can't do Œ!Q in jelly for 3 bytes then :( :p
 
basically a rolling sum/subtract/sum/subtract
 
@EriktheOutgolfer :)
 
@StewieGriffin Larger test case - But you only give the input. You should provide the output too (in Pastebin or smth).
 
Anonymous
7:54 PM
@MarcusAndrews (-1)**i is shorter than using f
 
@MarcusAndrews These two questions may help you
 
@StewieGriffin also you say the distinct permutations? oh well
 
Anonymous
And you can just use reduce:
 
(currently trying reduce actually)
but the lambda is lengthy
@cairdcoinheringaahing Thanks
 
Anyone up for JHT?
 
huh definitely ont lol
 
hmm it doesn't like me putting the vector input line inside the adder
 
1
A: Sandbox for Proposed Challenges

Magic Octopus UrnPalindromic Collapse Given a string s, traverse from left-to-right, finding the first prefix that is a palindrome. When you encounter the first prefix palindrome, remove the end-half of the palindrome. Insert it back into the original string, then restart again from the left side of the new word...

 
Anonymous
@MarcusAndrews I think this will work:
 
Anonymous
from functools import*
d,n=map(int,input().split())
a=[[k*(-1)**i for k in map(int,input().split())]for i in range(n)]
S=reduce(lambda x,y:[c+d[0]*d[1] for c,d in zip(x,y)],a)
print(*S)
 
Anonymous
8:00 PM
Haven't tested it yet though
 
saved some more room
d,n=map(int,input().split())
S=[0]*d
for i in range(n):
 v=list(input().split());S=[S[k]+(-1)**i*int(v[k])for k in range(d)]
print(*S)
Ah I'll try it out
 
@Mr.Xcoder Sure, give me a few decades/centuries/millenniums... It can't possibly be done, so you just have prove that it would work...
 
'int' not subscriptable on the S/reduce line
 
Anonymous
Yeah I see what I messed up
 
@StewieGriffin isn't "larger test case" more than 1000 integers? it says that for testing it's n<1000
 
8:02 PM
also 186 to my 135 currently
d,n=map(int,input().split())
S=[0]*d
for i in range(n):v=list(input().split());S=[S[k]+(-1)**i*int(v[k])for k in range(d)]
print(*S)
133 by putting it on one line
 
@EriktheOutgolfer Fixed. :)
 
1
Q: Output all distinct permutations of a vector

Stewie GriffinChallenge: Output all distinct permutations of a, potentially long, list of positive integers. You may assume that the vector has less than 1,000 numbers when testing, but the process should in theory work for any vector with more than one number, regardless of size. Restrictions: You must re...

 
@StewieGriffin you should delete the sandbox post
 
Anonymous
@MarcusAndrews Yeah I think that's going to be shorter than reduce
 
Anonymous
Also the list call isn't necessary - str.split() returns a tuple, which is subscriptable
 
8:06 PM
ah, of course, thanks
 
Also you can remove the newline:
d,n=map(int,input().split())
S=[0]*d
for i in range(n):v=input().split();S=[S[k]+(-1)**i*int(v[k])for k in range(d)]
print(*S)
 
@EriktheOutgolfer Will do :)
 
8:41 PM
Anyone know how to make a custom object immutable in Python?
 
@cairdcoinheringaahing Does this (borrowed from SO) work:
class A(custom_object):
    __slots__ = []
 
override __setattr__ perhaps
 
@Mr.Xcoder Thanks
@MarcusAndrews No cause then you can't create instances in __init__
 
I cannot test it now since my brain is fried once I dived into ordinal numbers thanks to SBA :D
 
char x = 'X';
int v = 0;
System.out.print(true  ? x : 0);
System.out.print(false ? v : x);
Here's a fun one
what does that print
 
8:44 PM
 
i suppose so
 
I guess XX?
 
It's supposed to look like it prints X (maybe with a newline), then X again, but that it's what it actually does.
My guess: 00
 
Maybe you're right
 
8:46 PM
holy moly
 
hi, does anybody know the link to a first prototype of I believe J in something like 15 lines of C which was mentioned in an article available online I cannot find anymore? it really bothers me to have lost that
 
Wait I think I know why, let me test
 
@mschauer We golf code, not read minds, sorry :(
 
8:49 PM
so when true it outputs its char value but when false, its ord?
what
 
System.out.print(true  ? 'X' : 0);
System.out.print(false ? 0 : 'X');
What does ^ print?
Guess what :P
 
@Mr.Xcoder XX
 
Great O_o
Java is weird.
 
Well, TIO is very helpful :P
 
@Mr.Xcoder XX
Oh ninja'd
 
8:50 PM
basically if the second and third operands have the same type, it's easy, but when you mix them, the JLS specifies some weird shit
 
@Mr.Xcoder what about that is weird
 
@Mr.Xcoder Not that Python would be better when it comes to ternaries.
@Pavel This
 
Oic
Yeah because char and int aren't the same thing in Java
 
@Mr.Xcoder Python tenaries are basic, but long. Aside from that, there's no problems
 
@cairdcoinheringaahing Yeah I forgot about x if c else y I was thinking about (ಠ_ಠ) c and x or y (I am aware that they are not equivalent!)
 

« first day (2474 days earlier)      last day (2368 days later) »