« first day (2361 days earlier)      last day (2484 days later) » 

10:00 AM
@DestructibleLemon Swift is a relatively easy language, and it has great modules like SceneKit and SpriteKit that are designed for games, and counting cycles and stuff is very easy. Though you should have a mac in order to use Swift :/
 
ok the idea is it is a simple lang for the bots to be written in
redcode simple
 
Ruby, Java, JS, Python, Scala.
All are easy ^
 
Anonymous
@DestructibleLemon What about something targetting GolfCPU?
 
what is golf cpu
 
Anonymous
I am not Google
 
10:02 AM
Also, C# is quite easy
 
@Mego well thank you
 
Anonymous
I don't have a link handy, but it was a simple CPU architecture created for some low-level fastest-code challenges
 
it's a GH
 
Anonymous
IIRC there was a simple assembly language created for it
 
Anonymous
That looks right
 
big.mul.small <- function(a,b) {
  i <- 1
  carry <- 0
  while (i <= length(a) || carry) {
    temp <- ifelse(i <= length(a), a[i]*b+carry, carry)
    carry <- temp %/% 10
    a[i] <- temp %% 10
    i <- i + 1
  }
  return(a)
}

pow <- 1
for(i in 1:100) pow <- big.mul.small(pow,99)
print(paste(rev(pow),collapse=""))
 
I wish python's [x for x in list] syntax could do [x for x in list where condition]
 
[1] "36603234127322950493061602657251738618971207663892369140595737269931704475072474818719654351002695040066156910065284327471823569680179941585710535449170757427389035006098270837114978219916760849490001"
@Mayube it's called [x for x in list if condition]
 
what is that?
 
10:13 AM
@Cowsquack building a bignum in R
the example is to find 99^100
 
oh... huh, can that condition access x?
 
@Mayube yes
(or else it would be constant, which isn't really useful afterall)
 
Project Euler?
 
then i guess I just need to lern me a better python then
 
@Cowsquack the bignum is for a problem in PE, but the 99^100 is just an example
 
10:14 AM
that link is borked for me, what is the problem number?
 
oh, you can't access the forum before you complete the problem... sounds right
it's PE56
 
so the main thing for my language is the memory system that is used with it
initially it would have just been a map and an accumulator but it doesn't really work
 
Anonymous
@Mayube primes_up_to_n=lambda n:[2, 3]+[x for x in range(3,n,2) if all(n%y>0 for y in primes_up_to_n(x))]
 
@Mego why not range(5,n,2)?
 
Anonymous
@LeakyNun Because then n=5 would fail. range is half-open.
 
10:22 AM
@Mayube You may have [x if x else y for x in range(blah...blah)]
 
@Mego range(5,n+1,2)?
that's a nice recursion without an apparent base case
 
Anonymous
@LeakyNun Following the example of range, I'm excluding the argument from the list
 
Anonymous
It's up to n, not up to and including n
 
wait an empty list is falsey in python right?
 
Anonymous
@Mayube Yes
 
10:23 AM
@Mego Then why would n=5 fail?
 
oh good that saves me a little time
wait no it doesn't, ah well
 
Anonymous
@LeakyNun Because I misunderstood what you were asking :P
 
@Mego no, it needs to be 5
or else there would be an extra 3
 
@Mayube print(bool([])) prints False
 
@Mr.Xcoder he means it doesn't save him time
 
Anonymous
10:25 AM
@LeakyNun Alternatively I could go with the original and just exclude 3 from the base case :P
 
@LeakyNun I know that. It was just a proof for the empty list being falsy in Python.
 
@Mego that would make it slower, not that it doesn't already have O(scary) complexity now
 
I passed 7.5k network rep :)
 
Anonymous
@LeakyNun It was an example to show off conditionals in list comprehensions, not an exercise in speed. If I wanted speed, I'd implement a more advanced test than trial division.
 
@Mego I would just use the sieve of Eratosthenes
 
Anonymous
10:27 AM
Trial division was faster and easier for me to write :P
 
something is fundamentally wrong with your code
 
CMC: Given a number as input, return it's bitwise complement (~n)
 
primes_up_to_n=lambda n:[2, 3]+[x for x in range(3,n,2) if all(n%y>0 for y in primes_up_to_n(x))]
print(primes_up_to_n(13))
[2, 3, 3, 5, 7, 9, 11]
Because somehow 9 is a prime number
 
This is how it would look in Cthulhu, assuming that i'll use I for input: ~I... Very creative
 
Anonymous
@LeakyNun The first list should only be 2
 
10:30 AM
@Mego it still prints 9
 
@Mr.Xcoder in a signed integer isn't the logic behind a bitwise negate the same as an integer negate?
the result sorry, not the logic
 
no, not the same
~n := -(n+1)
 
@Mayube No
 
Note that n+(~n) logically would have all 1
then add 1 and the carry go "over to infinity" so the number becomes 0
n+(~n)+1=0 so ~n = -(n+1)
 
Anonymous
@LeakyNun Found the typo. s/n%/x%/
 
10:31 AM
@Mego ok
 
~n = - (n+1), ~-n = n-1, -~n = n+1
 
yeah I see it now
 
@Mego O(scary) is very scary
 
Anonymous
@Mr.Xcoder -1.__sub__
 
It does 40 in a second
and good luck doing 50
 
Anonymous
10:33 AM
I really don't care about how slow it is
 
@Mego ~input().
 
@Mego 30 seconds
Real time: 30.353 s
User time: 30.022 s
Sys. time: 0.015 s
CPU share: 98.96 %
Exit code: 0
 
@LeakyNun How do you get those stats? I still use timeit :/
 
@Mr.Xcoder I use TIO
 
Anonymous
@Mr.Xcoder I prefer function solutions in Python over full-program solutions. You also forgot your print
 
10:34 AM
Aaah
 
@Mego inb4 repl
not that I agree with using REPL
 
Anonymous
@LeakyNun Do you not understand "I really don't care"?
 
@Mego I don't care about whether you care
I'm going to edit this into your prime function in Actually /s
 
Anonymous
Well, you constantly going on about how slow code that was written to be an example is slow is getting really annoying
 
@Mego sorry
 
10:35 AM
@LeakyNun I am so dumb that I never opened the Debug window on TIO
 
@Mr.Xcoder how did you debug the errors then
 
Anonymous
@LeakyNun Just don't write errors. Simple! :P
 
@LeakyNun I though TIO is not capable of showing errors!
I am so dumb
You shed some light upon my dumbness
 
Anonymous
@Mr.Xcoder I don't think that's the phrase you are looking for
 
I really should explore stuff more
@Mego Oh...
 
Anonymous
10:37 AM
You're looking for "enlightened"
 
@Mego Rephrased.
 
Anonymous
That's much clearer :P
 
Anyone knows how to substitute multiple matches in one statement in a regex in python?
 
@RestlessC0bra I am one of the worst regex-writers I know, so I will not answer
 
PE57 isn't the challenge; the challenge is doing it in R where there is no parallel assignment or bignum.
But I do have an algorithm
 
10:40 AM
@DestructibleLemon Curvature fixed
 
@RestlessC0bra use Retina
 
What char should I use for generating the first n Fibonacci number, if and are already taken?
 
I just had to actually commit to using a bit more trigonometry than I wanted to.
 
@ATaco nice I think
 
@RestlessC0bra just use re.sub
with argument count
@Mr.Xcoder F
 
Anonymous
10:41 AM
@LeakyNun That's not how count works
 
@LeakyNun Nice idea :p Not obvious at all...
 
@Mego I'll shut up about it then
is it normal if I find the TIO R to be better than the R I downloaded?
 
@LeakyNun Maybe I should use ƒ.
 
you can't travel through portals?
 
10:47 AM
Not yet, due to the theory of colliding with them being... Less then ideal.
 
PE57 in R:
num <- 1; denom <- 1
count <- 0
for(i in 1:1000){
  temp <- num + denom
  num <- temp + denom
  denom <- temp
  if(floor(log10(num)) > floor(log10(denom))) count <- count + 1
  if(denom > 1e100) {num <- num/1e100; denom <- denom/1e100}
}
print(count)
10 mins ago, by Leaky Nun
PE57 isn't the challenge; the challenge is doing it in R where there is no parallel assignment or bignum.
 
@LeakyNun did you see this? pastebin.com/BgCtFebQ
 
@CensoredUsername seems useful, thanks
what boggles me is mainly the registers
 
This function:
def first_a_fibonacci(a):
	result = []
	if a == 0: return [0]
	elif a==1: return [0,1]
	elif a==2: return [0,1,1]
	else:
		x,y = 0,1
		result += [x,y]
		while a-2>=0:x,y=y,x+y;a-=1;result.append(y)
		return result
Executes in 0.033s for 10 and 0.35 for 100 :P
 
@Mr.Xcoder if a < 3: return [0,1,1][:a]
it's shorter but not slower
 
10:51 AM
anyway @LeakyNun that code calculates the largest prime divisor of a 64-bit number
 
@CensoredUsername alright
 
the 64-bit arithmetic in 32-bit code is why it looks so complex
 
@Mr.Xcoder if you want to be faster, pre-initialize the whole array instead of expanding the array by appending.
it saves time and memory
 
@LeakyNun doesn't matter that much in python
 
how?
 
10:53 AM
it preallocates in factor-of-2 in the background
starting with a list size of 8
 
oh, wow, you're much more knowledgeable than I am
I'm just told that this is good practice in R
 
well that's basically what all sane list/vector implementations do
i.e. it's what Matlab doesn't do
 
@CensoredUsername lol
how do you know so much
 
experience, and liking figuring out how stuff works under the hood
 
but how comes it takes so long for 100
100 takes 0.034 s on TIO @Mr.Xcoder
that number is too low to be significant (because TIO wrapper consumes time)
 
10:56 AM
it seems to scale quite linearly
.033 s for 10, .35 s for 100 would be linear, which is what you expect from the algo
 
@LeakyNun I made a mistake. I meant to write 0.035
 
@CensoredUsername no, it's how TIO works
 
ah, overhead then
 
the number is too low to be significant
in reality it could as well be 0.00002 s
but the TIO wrapper takes a constant time
 
0.531s for 10000
On tio
It's reasonable
 
10:58 AM
yeah I got it
 
import time

def first_a_fibonacci(a):
	result = []
	if a == 0: return [0]
	elif a==1: return [0,1]
	elif a==2: return [0,1,1]
	else:
		x,y = 0,1
		result += [x,y]
		while a-2>=0:x,y=y,x+y;a-=1;result.append(y)
		return result

start = time.time()
n = 100000
for _ in range(n): a = first_a_fibonacci(10)
end = time.time()
print((end-start)/n)
2.490081787109375e-06
@Mr.Xcoder do you see what I mean
 
@LeakyNun I do
I use timeit
 
It's 2.103989839553833e-05 for 100
so it's linear here
 
anyway @LeakyNun if you're wondering why I know significant amounts of x64 asm, it's because I write stuff like github.com/CensoredUsername/whitespace-rs
 
@CensoredUsername Rust is low-level?
 
11:00 AM
@LeakyNun reasonably, but that's a JIT-compiler
I don't think you can get much lower than that ;)
 
does x86 have arbitrary precision?
 
import timeit

def first_a_fibonacci(a):
	result = []
	if a == 0: return [0]
	elif a==1: return [0,1]
	elif a==2: return [0,1,1]
	else:
		x,y = 0,1
		result += [x,y]
		while a-2>=0:x,y=y,x+y;a-=1;result.append(y)
		return result

print(timeit.timeit('first_a_fibonacci(100000)','from __main__ import first_a_fibonacci',number=1))
Prints: 0.5104190589991049 (for 100000), so it's fine.
 
I don't recall any arch handling arbitrary precision in hw
this JIT handles it very simply. If overflow is detected it switches to a bignum-based interpreter
alternatively you can tell it to use wrapping arith
you'd be surprised how annoying it is to do certain ops safely in hw though
div is a pain
 
what is hw?
 
11:06 AM
hardware
i.e. what x86 has available for you to do division
 
I'd be surprised if there's a hardware with arbitrary precision
 
there's probably crazy hw somewhere that implements wide-as-hell ops and software traps if it becomes too big or something
however, arbitrary precision arithmetic is really not used that often so common archs don't really do anything for it except for simple carry propagation operands
i.e. x64 arbitrary width addition is just a loop around adc (add with carry)
 
does x86 have arrays?
 
no son, we have pointers
and that's it
technically you could use the vector extensions for some array calc, but that's fixed-width
 
import timeit

def first_a_fibonacci_1(a):
	result = []
	if a == 0: return [0]
	elif a==1: return [0,1]
	elif a==2: return [0,1,1]
	else:
		x,y = 0,1
		result += [x,y]
		while a-2>=0:x,y=y,x+y;a-=1;result.append(y)
		return result

def first_a_fibonacci_2(a):
	if a<3: return [0,1,1][:a+1]
	result = [0]*a
	x,y = 0,1
	for i in range(1,a): result[i]=y; x,y=y,x+y;
	return result

print(timeit.timeit('first_a_fibonacci_1(100000)','from __main__ import first_a_fibonacci_1',number=10))
print(timeit.timeit('first_a_fibonacci_2(100000)','from __main__ import first_a_fibonacci_2',number=10))
4.295146663003834
4.000230653997278
There's a constant 0.02 s difference in the array allocation
 
not that it matters
 
like, C array arith will end up being compiled into instructions like mov rax, [rdx + 8* rbx]
which you can think of as rax = rdx[8*rbx]
 
@LeakyNun I used that, thanks.
I have exactly 20 silver badges and 75 bronze badges (and 1 gold)
 
@Mr.Xcoder please don't use that athFibonacci
 
@LeakyNun Why?
 
11:14 AM
I wrote a fib function with logarithmic complexity for Actually
@Mr.Xcoder because your function has linear complexity
(and you forgot to return!)
 
@LeakyNun That one's indeed important
 
1 min ago, by Leaky Nun
I wrote a fib function with logarithmic complexity for Actually
This may be the first (and last) time I ever wrote practical code for someone/something
 
I won't use it, it's just a separate branch
 
what do you mean?
 
@LeakyNun I mean that I will fix that and thanks for the spotting the bugs
I will PR only after I fix the bugs and make athFibonacci more efficient.
 
11:17 AM
fib_cache = {0:0, 1:1, 2:1}

def Fib(n):
    global fib_cache
    if n in fib_cache:
        return fib_cache[n]
    else:
        result = fast_fib(n)[1]
        fib_cache[n] = result
        return result

# F(2n) = (F(n-1) + F(n+1)) * F(n)
#       = (F(n-1) + F(n-1) + F(n)) * F(n)
#       = (2F(n-1) + F(n)) * F(n)

# F(2n-1) = F(n-1)*F(n-1) + F(n)*F(n)

# this returns [F(n-1), F(n)], so
# the implementation should be
# fast_fib(1000)[1]
def fast_fib(n):
    global fib_cache
    if n==0: return 1,0
2
This is the code I wrote
you can use it freely
 
What time does it have for 1000?
 
1000 is an understatement
logarithmic complexity means much more
 
0.032
wow, that's fast
 
As I've already said
0.032 is too low to be significant
If you see 0.032, it's probably much faster than that
 
I know
TIO, you know
 
11:21 AM
n=100000 finishes in 0.072 s
 
I will use that for Cthulhu
 
logarithmic complexity means linear to the number of digits...
 
@LeakyNun It doesn't finish for 1000000000 :(
 
right, I noticed that for 100000000
so it might not be logarithmic afterall
I guess the multiplications are too large
that one cannot assume them to be constant time at this scale
 
0.09076855099920067 for 1000000 though
 
11:23 AM
10000000 (that's 1e7) finishes in 4.118 s
so the multiplications start dominating the complexity at this moment
 
@LeakyNun My mac finishes it in 3.722789225001179 for 1e7
 
well, can we agree that it's fast enough?
 
@LeakyNun It is
 
@Mr.Xcoder so would you use it?
 
4 mins ago, by Mr. Xcoder
I will use that for Cthulhu
 
11:26 AM
lol cool
this is the second time I wrote something practical then
 
:)
second time you shared sth practical
 
wait, let me try to tweak it
is (a<<1)*b faster or a*b*2?
 
It should be
But where do you have a*b*2?
 
they're equivalent
never mind, it doesn't really matter
 
@LeakyNun Port it to Prolog
 
11:31 AM
@Fatalize Wanna use it for Brachylog?
 
Possibly
 
@LeakyNun I ran 99999999999999999*99999999999999999 and 99999999999999999**2 and I got ~0.000209 and ~0.000175 respectively.
(Ran those 10000 times each)
(With timeit)
@LeakyNun Time for some Pyth? (If you have the time and want, give me an easier task this time)
 
@Fatalize not free now
@Mr.Xcoder do you have any knowledge of group theory?
 
@LeakyNun No
 
given a and b prime, find {1,a,a^2,a^3,...} mod b
hint: the sequence must be finite and periodic
 
11:39 AM
periodic sequence?
 
yes
so the result must be finite
 
And WTH is a set mod b? Each element mod b?
 
for 2,7 return [1,2,4] any permutation
yes
 
Ok, wait a little.
The first 3 elements?
 
no
the only elements
 
11:41 AM
>_>
I don't get it
 
1 mod 7, 2 mod 7, 4 mod7, 8 mod 7, 16 mod 7,...
becomes 1,2,4,1,2,...
 
When does it end?
 
so you return 1,2,4
 
I am quite dumb, fogive me
When does it end?
 
the only possible values
 
11:42 AM
I am quite dumb, fogive me
 
it goes in a cycle
hint: it ends before the second 1
 
Oh, like for 3 and 5: {1,3,9,27} and then stop because 81 mod 5 is 1?
 
no
9 mod 5 is 4
{1,3,4,2}
 
Yeah, that's what I meant, but I am quite dumb
Will try
(I also have a netfall so I may repond late)
 
You get 1 3 4 2 1 3 4 2 1 3 4 2 1 3 4 2 1 3 4 2 1, so the pattern is 1 3 4 2
ninja'd
 
11:46 AM
@Fatalize don't expect me to write the reverse version though
 
2 hours ago, by Mr. Xcoder
yesterday, by HyperNeutrino
Jun 23 at 12:27, by Erik the Outgolfer
please, "ninja'd" should be restricted to when you actually post the message a split second later than somebody else posting the same message, and then you are the one who is ninja'd
 
since when did we have rules about ninja'ing ;_;
 
Since Jun 23 at 12:27
 
That was when they were formalized.
 
that was a rhetorical question
 
11:55 AM
does anybody know if taking a bytestring or byte array for input is allowed?
in python
plz send teh links
 
@LeakyNun Ungolfed, 30 bytes 😭😭: J1KE aYJWn%^QJK1 aY%^QJK=+J1;Y
I used W, you won't be proud of me 😭
 
my challenge will be useless for you unless you step out of your comfort zone and start using m f u .e .b .u .U V
 
@LeakyNun I will use them, trying to golf it down by using them.
But I will come back in ~20 mins, I gotta have lunch my my parents :/
 

« first day (2361 days earlier)      last day (2484 days later) »