Discuss Scratch

MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

CodeLegend wrote:

MartinBraendli2 wrote:

For the polynomial interpolation challenge:
I was looking for good algorithms, but all i can find are algorithms that take a list of x-values and their corresponding f(x)-values and produce an interpolation for a specific x-value (Newton, Heremite and others). Is there a good algorithm to tackle that challenge? I could do it by solving multiple linear equations, but I'm quite sure, there is a better algorithm out there.
I was taught to use matrix multiplication.

EDIT: (for everyone here)

Let's say you have 3 points: (0,1), (2,3), (5,4)
We want to find an equation of the form y=ax^2+bx+c which passes through them all. So we're looking to return the values of a, b, and c.
So we can form these equations, one for each point:
1=a*0^2+b*0+c
or 1=0a+0b+1c
3=a*2^2+b*2+c
or 3=4a+2b+c
4=a*5^2+b*5+c
or 4=25a+5b+c

With these equations, we can form this matrix relationship:
[ 0 0 1] [a] [1]
[ 4 2 1]*[b]=[3]
[25 5 1] [c] [4]

Then solve for [[a][b][c]]

[ 0 0 1]^-1[ 0 0 1] [a] [ 0 0 1]^-1[1]
[ 4 2 1] * [ 4 2 1]*[b]=[ 4 2 1] * [3]
[25 5 1] [25 5 1] [c] [25 5 1] [4]

[a] [ 0 0 1]^-1[1]
[b]=[ 4 2 1] * [3]
[c] [25 5 1] [4]

[a] [ 1/10 -1/6 1/15] [1]
[b]=[-7/10 5/6 -2/15]*[3]
[c] [ 1 0 0 ] [4]

[a] [-2/15]
[b]=[19/15]
[c] [ 1 ]
a=-.13333333333
b=1.26666666666
c=1

So the program would output those three values. You can check them in the previous equations, and the math should check out.
So if you're going to use this method, you need a way to inverse and multiply matrices.
Yeah, I got that far, but i couldn't find a simple method for inversing matrices. I found a better method now. I won't tell how I'll do it atm, since I'm not yet sure that I'll beat Random-Man.
Random-Man
Scratcher
48 posts

[ATC#5] Codegolfing to the Extreme!

MartinBraendli2 wrote:

CodeLegend wrote:

-snip-
Yeah, I got that far, but i couldn't find a simple method for inversing matrices. I found a better method now. I won't tell how I'll do it atm, since I'm not yet sure that I'll beat Random-Man.

I'm… I'm… flabbergasted!!!!!!!!!!!!!!!!!11111111111111111111

However, I'm encountering problems because:
1. I only have 5 variables
2. My languages conditionals are dependent on the length of the program before it, so if I edit anything, I then must change all the conditionals to match it

So…
It's becoming super annoying…
MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

Random-Man wrote:

1. I only have 5 variables
Do you have lists? Challenge 13 is close to impossible without lists (not impossible, but super duper uber annoying). For my approach I need 5 lists (thank god I added extra lists (which need 1 char more), I only have 4 standard lists).

Random-Man wrote:

2. My languages conditionals are dependent on the length of the program before it, so if I edit anything, I then must change all the conditionals to match it
Yes, i know the pain (Tee++ once had a GOTO command too).
Now in Tee++:
Loop:
[

]
|  Break loop
> Break loop if POP is bigger than 0 (boolean true = 1, false = -1)
< Break loop if top of stack is not bigger than 0, only pop on break

If
(booleanValue)
?
(ifTrueCode)
;

If/else
(booleanValue)
?
(ifTrueCode)
.
(elseCode)
;

Switch
(valuePreferableInteger)
!
(ifInt1Code)
,
(ifInt2Code)
,
(ifInt3Code)
.
(defaultCode)
;

My loops are quite flexible, but for simple Stuff (like loop n times) they take way to many characters. But the advantage is, that my syntax is quite flexible and its rather easy to create nested loops/ifs/switches.

Last edited by MartinBraendli2 (Aug. 13, 2016 17:05:31)

Random-Man
Scratcher
48 posts

[ATC#5] Codegolfing to the Extreme!

I will add loops once this contest is over, considering I have many extra characters, for the fun of it… And though I don't have lists, I have two stacks and lots of stack manipulation commands, so that will be useful…
CodeLegend
Scratcher
500+ posts

[ATC#5] Codegolfing to the Extreme!

Random-Man wrote:

I will add loops once this contest is over, considering I have many extra characters, for the fun of it… And though I don't have lists, I have two stacks and lots of stack manipulation commands, so that will be useful…
Yeah, I don't have lists either, but I have lots of stack manipulators, so I can use the stack as any number of lists. I also only have eight variables, so some of these challenges will be very difficult for me also…
MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

CodeLegend wrote:

Random-Man wrote:

I will add loops once this contest is over, considering I have many extra characters, for the fun of it… And though I don't have lists, I have two stacks and lots of stack manipulation commands, so that will be useful…
Yeah, I don't have lists either, but I have lots of stack manipulators, so I can use the stack as any number of lists. I also only have eight variables, so some of these challenges will be very difficult for me also…
IMO challenge 13 is the hardest. I'd really like to see how a language without lists would tackle that.
Jonathan50
Scratcher
1000+ posts

[ATC#5] Codegolfing to the Extreme!

Random-Man wrote:

2. My languages conditionals are dependent on the length of the program before it, so if I edit anything, I then must change all the conditionals to match it
Me too
Random-Man
Scratcher
48 posts

[ATC#5] Codegolfing to the Extreme!

CodeLegend wrote:

Random-Man wrote:

I will add loops once this contest is over, considering I have many extra characters, for the fun of it… And though I don't have lists, I have two stacks and lots of stack manipulation commands, so that will be useful…
Yeah, I don't have lists either, but I have lots of stack manipulators, so I can use the stack as any number of lists. I also only have eight variables, so some of these challenges will be very difficult for me also…
But I thought you made the challenges and the language… Shouldn't your language be perfect?
Random-Man
Scratcher
48 posts

[ATC#5] Codegolfing to the Extreme!

My bottles of what program:
Jb1-N}sK(n"U>%As&'xQX%!2sxvY28eWXsjU>%As&'xQX%%$"],'75'n1-N1$''K'96'n0$"/w6b36"N}sKX'185'n0>?"`>\o\3oX|JBi.lv8Pk 2y;/9mqP\{%2O)pk41)L!sCW, WK_buw",)"_}q,o!"gI"_z|A;}vY.A8`Wl1U@$W%co[V:0a "99"U>%AswVZqd2}V\:@PcJY{i\"]
There are so many places where I could make it 1 char shorter, and yet I'm just too tired of working with my own language, so…
For now, I'll keep my hair.
Random-Man
Scratcher
48 posts

[ATC#5] Codegolfing to the Extreme!

MartinBraendli2 wrote:

CodeLegend wrote:

MartinBraendli2 wrote:

For the polynomial interpolation challenge:
I was looking for good algorithms, but all i can find are algorithms that take a list of x-values and their corresponding f(x)-values and produce an interpolation for a specific x-value (Newton, Heremite and others). Is there a good algorithm to tackle that challenge? I could do it by solving multiple linear equations, but I'm quite sure, there is a better algorithm out there.
I was taught to use matrix multiplication.

EDIT: (for everyone here)

Let's say you have 3 points: (0,1), (2,3), (5,4)
We want to find an equation of the form y=ax^2+bx+c which passes through them all. So we're looking to return the values of a, b, and c.
So we can form these equations, one for each point:
1=a*0^2+b*0+c
or 1=0a+0b+1c
3=a*2^2+b*2+c
or 3=4a+2b+c
4=a*5^2+b*5+c
or 4=25a+5b+c

With these equations, we can form this matrix relationship:
[ 0 0 1] [a] [1]
[ 4 2 1]*[b]=[3]
[25 5 1] [c] [4]

Then solve for [[a][b][c]]

[ 0 0 1]^-1[ 0 0 1] [a] [ 0 0 1]^-1[1]
[ 4 2 1] * [ 4 2 1]*[b]=[ 4 2 1] * [3]
[25 5 1] [25 5 1] [c] [25 5 1] [4]

[a] [ 0 0 1]^-1[1]
[b]=[ 4 2 1] * [3]
[c] [25 5 1] [4]

[a] [ 1/10 -1/6 1/15] [1]
[b]=[-7/10 5/6 -2/15]*[3]
[c] [ 1 0 0 ] [4]

[a] [-2/15]
[b]=[19/15]
[c] [ 1 ]
a=-.13333333333
b=1.26666666666
c=1

So the program would output those three values. You can check them in the previous equations, and the math should check out.
So if you're going to use this method, you need a way to inverse and multiply matrices.
Yeah, I got that far, but i couldn't find a simple method for inversing matrices. I found a better method now. I won't tell how I'll do it atm, since I'm not yet sure that I'll beat Random-Man.
Bogo solving anyone?
I bet a program that could theoretically solve this using a Bogo and check method that is shorter than what you explained…
MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

Random-Man wrote:

MartinBraendli2 wrote:

CodeLegend wrote:

MartinBraendli2 wrote:

For the polynomial interpolation challenge:
I was looking for good algorithms, but all i can find are algorithms that take a list of x-values and their corresponding f(x)-values and produce an interpolation for a specific x-value (Newton, Heremite and others). Is there a good algorithm to tackle that challenge? I could do it by solving multiple linear equations, but I'm quite sure, there is a better algorithm out there.
I was taught to use matrix multiplication.

EDIT: (for everyone here)

Let's say you have 3 points: (0,1), (2,3), (5,4)
We want to find an equation of the form y=ax^2+bx+c which passes through them all. So we're looking to return the values of a, b, and c.
So we can form these equations, one for each point:
1=a*0^2+b*0+c
or 1=0a+0b+1c
3=a*2^2+b*2+c
or 3=4a+2b+c
4=a*5^2+b*5+c
or 4=25a+5b+c

With these equations, we can form this matrix relationship:
[ 0 0 1] [a] [1]
[ 4 2 1]*[b]=[3]
[25 5 1] [c] [4]

Then solve for [[a][b][c]]

[ 0 0 1]^-1[ 0 0 1] [a] [ 0 0 1]^-1[1]
[ 4 2 1] * [ 4 2 1]*[b]=[ 4 2 1] * [3]
[25 5 1] [25 5 1] [c] [25 5 1] [4]

[a] [ 0 0 1]^-1[1]
[b]=[ 4 2 1] * [3]
[c] [25 5 1] [4]

[a] [ 1/10 -1/6 1/15] [1]
[b]=[-7/10 5/6 -2/15]*[3]
[c] [ 1 0 0 ] [4]

[a] [-2/15]
[b]=[19/15]
[c] [ 1 ]
a=-.13333333333
b=1.26666666666
c=1

So the program would output those three values. You can check them in the previous equations, and the math should check out.
So if you're going to use this method, you need a way to inverse and multiply matrices.
Yeah, I got that far, but i couldn't find a simple method for inversing matrices. I found a better method now. I won't tell how I'll do it atm, since I'm not yet sure that I'll beat Random-Man.
Bogo solving anyone?
I bet a program that could theoretically solve this using a Bogo and check method that is shorter than what you explained…
Hehe.
Theoretically correct is not enough for this competition, you also have to pass the required tests. Imagine how long it would take to verify a program. Lets say you have to get 15 bits per number right (all 11 bits exponent, plus 4 bits of the mantissa, which would give a tolerance of about +/- 5%). That would give you 1e18 possibilities for the test with 4 data points. Lets say you have a uber fast interpreter, that tests 1e12 combinations per second. Then you would still need 12 days to pass that test. So you would miss the deadline.
CodeLegend
Scratcher
500+ posts

[ATC#5] Codegolfing to the Extreme!

MartinBraendli2 wrote:

Random-Man wrote:

MartinBraendli2 wrote:

EDIT: snip
Bogo solving anyone?
I bet a program that could theoretically solve this using a Bogo and check method that is shorter than what you explained…
Hehe.
Theoretically correct is not enough for this competition, you also have to pass the required tests. Imagine how long it would take to verify a program. Lets say you have to get 15 bits per number right (all 11 bits exponent, plus 4 bits of the mantissa, which would give a tolerance of about +/- 5%). That would give you 1e18 possibilities for the test with 4 data points. Lets say you have a uber fast interpreter, that tests 1e12 combinations per second. Then you would still need 12 days to pass that test. So you would miss the deadline.
Well that's assuming an unoptimized brute force algorithm. What if you tried random operations on random combinations of the input numbers? You might get it done within a week

Last edited by CodeLegend (Aug. 14, 2016 16:59:35)

Random-Man
Scratcher
48 posts

[ATC#5] Codegolfing to the Extreme!

Oh… well I'm out…
I completely forgot to add an absolute value command…







I guess I'll need to use my ? command even more…
CodeLegend
Scratcher
500+ posts

[ATC#5] Codegolfing to the Extreme!

Random-Man wrote:

Oh… well I'm out…
I completely forgot to add an absolute value command…







I guess I'll need to use my ? command even more…
Ouch. I have decent (relatively) conditionals and my workaround is 9 characters long…
.0<(y-1*)
Of course you could take off the ) if it's at the end of the program.
MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

Random-Man wrote:

Oh… well I'm out…
I completely forgot to add an absolute value command…







I guess I'll need to use my ? command even more…
Where would you need abs()? The examples in the polygon challenge are both counter-clockwise, so they will produce the same sign (so if needed, you can hardcode the “negate output”, without conditional).
CodeLegend
Scratcher
500+ posts

[ATC#5] Codegolfing to the Extreme!

MartinBraendli2 wrote:

Random-Man wrote:

Oh… well I'm out…
I completely forgot to add an absolute value command…







I guess I'll need to use my ? command even more…
Where would you need abs()? The examples in the polygon challenge are both counter-clockwise, so they will produce the same sign (so if needed, you can hardcode the “negate output”, without conditional).
Your programs have to be able to work with any input, not just the ones in the examples… (otherwise the hard programs could all be much much shorter)

first post wrote:

As of posting this topic, I have already chosen several (15) challenges for you to attempt. In order for you to complete each one, you must write a program in your submitted language that performs the specified action.
MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

CodeLegend wrote:

MartinBraendli2 wrote:

Random-Man wrote:

Oh… well I'm out…
I completely forgot to add an absolute value command…







I guess I'll need to use my ? command even more…
Where would you need abs()? The examples in the polygon challenge are both counter-clockwise, so they will produce the same sign (so if needed, you can hardcode the “negate output”, without conditional).
Your programs have to be able to work with any input, not just the ones in the examples… (otherwise the hard programs could all be much much shorter)

first post wrote:

As of posting this topic, I have already chosen several (15) challenges for you to attempt. In order for you to complete each one, you must write a program in your submitted language that performs the specified action.
Yes, the program should produce valid outputs for all valid inputs, not just the specified examples. But the description as well as the example leave it open, whether you want the laymans “always positive” area or the mathematicians/programmers “sign denotes orientation” area. I think a program that returns negative values for clockwise polygons would be also reasonable.
My program returns “always positive” area btw, but swaping out ‘#’ for ‘~’ would make it signed area.
MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

I finally finished challenge 13, the biggest pain of all. It took me about 3h to find the last bug.
A[iyaB>uyGuy´Y][ixaB>0Fq1TaY[xyE~?xgyg-t*T;dy0E>]1t/1Q1Y[xyE~?0FhyyxS?I;Z[dz0E>zIhzq+zIHzhygzq*-zH]}H}KQ;iyaB>]0Y[iyaB>x´yyq*yp+yP]]_-p' P
Has still has potential to be golfed a bit, but I'm tired.

@WizzWizz7: Is your code for the pokemon challenge inspired by mine? The string “uvehhhqali” looks suspicious. Anyway, I golfed my code, from 40 byte down to 32:
"suaaeztro"kQAa6$q3eaL8B+?I;\e?~
dzaima
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

would it be ok if the 99 bottles each line would take a couple seconds each? because every loop time it would cobvert all the required text from base 2 to base 95? and by a couple I mean anywhere from 1 to 10 seconds. Still haven't gotten close to finishing it as it's so complicated.
EDIT: I've found a bug in my code that makes me not able to have the character space as the first character. Am I allowed to fix that?

Last edited by dzaima (Aug. 15, 2016 14:34:39)

MartinBraendli2
Scratcher
100+ posts

[ATC#5] Codegolfing to the Extreme!

dzaima wrote:

I've found a bug in my code that makes me not able to have the character space as the first character. Am I allowed to fix that?
IMO that really depends on where the bug is coming from (language design => deal with it, interpreter/implementation => fix it). Can you explain why this is not possible?

Powered by DjangoBB