Computer Science Canada The 20line or less weekly contest! |
Author: | MihaiG [ Thu Feb 26, 2009 1:54 am ] | ||
Post subject: | The 20line or less weekly contest! | ||
Update: Since this started thursday, the submitted code will be reviewed wednesday night(or thursday morning) based on submission time(server time), Users and mods can both participate(cept mods dont get bits) winners will recieve 100bits and a "virtual" trophy/badge for each week. Hey guys, ive really gotten into having fun in optimizing code so i want to start a weekly event, where users submit programs written in 20 lines or less. Users will be encouraged to be creative and improve on the code and ideas of others. Some basic rules i want to lay out are: 1.Submissions must have a total length(20 lines or less, commenting does not count). 2.Code must be commented(where not obvious, assume we have only programmed for 3 weeks) 3.Ideas and code may be used from previous submissions in the case where the resulting code is at least 3 lines shorter than the previous(and or similar) version. 4. Reasonable explanations must be included with each submission. 5. Prizes of 100bit will be awarded to weekly winners And to start it off, i will warp your minds with the Sierpinski Triangle.
What this essentialy does it if the AND operation between two coordinates results in zero then a black pixel is drawn,(you can also switch that z = 0 to a z != 0) So thats my first submission i am waiting for your submissions! *edit note you can use a max screen for my program, but it works best with square displays where the window size is a 2^n :]*[/img] |
Author: | Tony [ Thu Feb 26, 2009 3:20 am ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
MihaiG @ Thu Feb 26, 2009 1:54 am wrote: i need a temporary value to store the AND operation to since turing doesnt like using it directly
It might not like it, but it works.
For comments, refer to MihaiG's program above. This does the same thing. Though calling this "optimized" would be misleading, as it makes the solution worse, in just about every way imaginable. |
Author: | The_Bean [ Thu Feb 26, 2009 11:00 pm ] | ||||
Post subject: | Re: The 20line or less weekly contest! | ||||
I propose a line length limit, not because of multiple commands on one line, but to prevent me from doing this... This is to all those people that were trying to make those projectile games a while back.
To anyone saying that its more than 20 lines, the Draw.ThickLine() is only actually on 1 line, it looks like more because of text wrapping. And heres a nicer version for the commenting part.
|
Author: | MihaiG [ Fri Feb 27, 2009 11:16 am ] |
Post subject: | RE:The 20line or less weekly contest! |
Heres my take on it, line length should not be an issue if the line wraps around(i know ive written some nested stuff that is huge), just as long as you only have like "one" main fcn on that line |
Author: | Clayton [ Fri Feb 27, 2009 11:32 am ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
What about curly braces? Is:
3 lines, or 7? |
Author: | copthesaint [ Fri Feb 27, 2009 11:59 am ] | ||||
Post subject: | Re: The 20line or less weekly contest! | ||||
What counts as a line? ie does for statement, if statements ect. Does this count as 2 lines?
Does This count as 1 line?
|
Author: | copthesaint [ Fri Feb 27, 2009 12:55 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
This is my add on (15 lines) that I made, It's like The Draw.Fill AND it doesn't delete other colors. The problem with this is though if you the color is in the are ANYWHERE it will change it. It has It's flaws and benefits.
|
Author: | MihaiG [ Fri Feb 27, 2009 3:10 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
Clayton: only turing, hence why it was posted in the turing section, any part of the code that is interpreted/excecuted (non commenting or non space) counts to the line count |
Author: | SNIPERDUDE [ Mon Mar 02, 2009 9:40 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
I'm guessing using semi-colons to shorten it is not allowed? |
Author: | zylum [ Mon Mar 02, 2009 11:49 pm ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
Another Sierpinski triangle generator. Generates a random triangle.. This could be made a lot shorter with some trickery but I thought I'd keep it in this somewhat clean state
|
Author: | syntax_error [ Mon Mar 02, 2009 11:51 pm ] |
Post subject: | Re: RE:The 20line or less weekly contest! |
SNIPERDUDE @ Mon Mar 02, 2009 9:40 pm wrote: I'm guessing using semi-colons to shorten it is not allowed?
MihaiG wrote: Clayton only turing, hence why it was posted in the turing section, any part of the code that is interpreted/excecuted (non commenting or non space) counts to the line count Does turing have semi colons? I think not. Edit: Fixed tags. |
Author: | Tony [ Mon Mar 02, 2009 11:54 pm ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
Turing supports semi-colon separation of statements
|
Author: | BigBear [ Tue Mar 03, 2009 4:14 pm ] | ||
Post subject: | Re: RE:The 20line or less weekly contest! | ||
Tony @ Mon Mar 02, 2009 11:54 pm wrote: Turing supports semi-colon separation of statements
I am pretty sure that 20 lines is after F2 formatting |
Author: | MihaiG [ Tue Mar 03, 2009 5:55 pm ] |
Post subject: | Re: The 20line or less weekly contest! |
excellent zylum love it id love to see the trickery i think the point is to strive in creating nifty pieces of code, not how to cheat the system, also i think to be fair, in all respects, only post one submission a week,(unless requested, ie how i requested zylum's "alternate") but listen it doesnt have to be graphical, i just did that as an example also, i think it would be good to also post explanations of the code posted , ie zylum |
Author: | MihaiG [ Thu Mar 05, 2009 4:42 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Ok so first week is over, and the award goes to Zylum. +100bits to zylum! to start of week2 i give you fun i give you 15(or 16) lines of code with trickery
you can remove the delay if it is going to slow |
Author: | The_Bean [ Thu Mar 05, 2009 6:47 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Did someone say 3D?
A sphere rotating with your mouse in 12 lines. The formula can be changed to incorporate any 3D formula, although they may not turn out that great being as it is just dots. |
Author: | copthesaint [ Thu Mar 05, 2009 8:59 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Wow cool effect. I was very interested in you sphere. But I didn't know for sure how you did it at first. This may help others understand too what it does is basicly makes 18 dots 18 times and gives the illusion of 3D Gj Bean and don't give me credit for this. I am just posting this code for those who don't understand it. (Like me)
|
Author: | saltpro15 [ Thu Mar 05, 2009 9:25 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
The_Bean, that is so cool! and it's not that difficult to understand |
Author: | The_Bean [ Thu Mar 05, 2009 9:44 pm ] | ||||||
Post subject: | Re: The 20line or less weekly contest! | ||||||
Heres what is going in those giant lines of Drawing: The 2 for loops going -18..18 are the degrees, I multiply them by 10 to get -180..180 by 10 which is a complete 360. Take the equation of a sphere:
Now look at the rotation formula:
Where p1 and p2 are either x,y,z depending on how you want it rotated and theta controls the degrees of rotation. To make it spin horizontally: p1=xCoordinate and p2=zCoordinate and theta=xm To make it spin vertically: p1=yCoordinate and p2=zCoordinate and theta=ym Now replace variables where you can, and remember you need to keep the z value change in horizontal spinning in the verticle spinning:
You can change the formula of a sphere to get different looking shapes. |
Author: | Tony [ Thu Mar 05, 2009 10:59 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
The_Bean @ Thu Mar 05, 2009 9:44 pm wrote: The 2 for loops going -18..18 are the degrees, I multiply them by 10 to get -180..180 by 10 which is a complete 360.
Turing actually supports
type of syntax. for |
Author: | copthesaint [ Fri Mar 06, 2009 2:52 am ] |
Post subject: | RE:The 20line or less weekly contest! |
tony the 180 by 10 what is it used for/ how would you use it? |
Author: | zylum [ Fri Mar 06, 2009 3:30 am ] | ||||||
Post subject: | RE:The 20line or less weekly contest! | ||||||
copthesaint, the code Tony posted iterates from -180 to 180 by increments of 10.. So instead of writing:
you would simply have
All of these 3D submissions remind me of one I made in a previous 20 line contest...
Perspective, lighting and back face culling XD |
Author: | Tallguy [ Fri Mar 06, 2009 9:23 am ] |
Post subject: | RE:The 20line or less weekly contest! |
i gotta say, @The_Bean - so sweet!! i love the sphere, how long did it take you to make? |
Author: | MihaiG [ Fri Mar 06, 2009 3:02 pm ] |
Post subject: | Re: The 20line or less weekly contest! |
i hearby disband zylum from posting any more submissions so other people can win <3 very nice zylum, want to add some commenting to your submission? |
Author: | copthesaint [ Mon Mar 23, 2009 10:56 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Here is a 18 line program that is easy and cool. I took 5 min to make it.
|
Author: | zero-impact [ Sat Mar 28, 2009 1:29 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Here is a particularly nice looking zoom of the mandelbrot set. In 18 lines!
|
Author: | copthesaint [ Wed Apr 01, 2009 12:15 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Here is a 19 line program that will take a string and split up the values inbetween each space. This is usefull for online programs and loading txt files.
|
Author: | saltpro15 [ Wed Apr 01, 2009 3:44 pm ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
here is hello world
in 1 line! how amazing! |
Author: | SNIPERDUDE [ Wed Apr 01, 2009 3:57 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
I vote saltpro15 the weekly winner. |
Author: | saltpro15 [ Wed Apr 01, 2009 4:43 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
yay, thanks SNIPERDUDE :p also, excellent video in your signature, I don't even like hip-hop and I thought it was great |
Author: | copthesaint [ Wed Apr 01, 2009 5:08 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
Umm What are you two talking about... This is Kinda off topic don't you think... |
Author: | saltpro15 [ Wed Apr 01, 2009 5:28 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
Yes it is, my bad. I should get cracking on a real submission |
Author: | Zren [ Wed Apr 01, 2009 8:08 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
copthesaint @ Wed Apr 01, 2009 12:15 pm wrote: Here is a 19 line program that will take a string and split up the values inbetween each space.
This is usefull for online programs and loading txt files.
Your program doesn't catch the last word into the array without having a trailing space. Just pointing that out dude. Good try though. |
Author: | SNIPERDUDE [ Wed Apr 01, 2009 10:56 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
do note the difficulty it would be to add error checking with such limited room. Although just to make it work in this case have the function just add one to the output number. |
Author: | BBPProductions [ Thu Jun 04, 2009 9:42 am ] |
Post subject: | RE:The 20line or less weekly contest! |
I relly liked the sphere! |
Author: | stas054 [ Sat Jun 13, 2009 7:58 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
var pie:string:="I <3 pie" put pie |
Author: | stas054 [ Sat Jun 13, 2009 8:03 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
The_Bean @ Thu Mar 05, 2009 6:47 pm wrote: Did someone say 3D?
A sphere rotating with your mouse in 12 lines. The formula can be changed to incorporate any 3D formula, although they may not turn out that great being as it is just dots. suggestion: making it white on the black background would look better |
Author: | Carey [ Tue Aug 25, 2009 6:17 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Like that? |
Author: | Magix [ Sun Oct 25, 2009 3:57 pm ] | ||||
Post subject: | [SUBMISSION] Image 2 Source Convertor | ||||
A new submission: Note: This is note my code. I found it somewhere on this forum, and all I did was compress it from 42 lines of code to 18 lines of code, while still following proper coding etiquette. I take no credit for this, I just think that it is very worthy of winning an award on this contest. Anyways, it is an image-to-source convertor that can take any image and convert it to a turing file using the Draw.Dot command. Its rather awesome, considering its only 18 lines of code. Here it is...
Just in case you are wondering how I compressed it so much, I removed the code to check if the image exists, and I removed the code to check if the filename of the output file is taken or not. If you are interested, here is the original code...
To make this work, put enter the image location when prompted for it. If it is in the same directory as the Turing Code, just type in the filename with the extension. Example: filename.jpg. If it is the a different directory, use /, ./ and ../ commands to show this. This image only recognizes BMP and JPG images. I attached a sample of what this program can do. |
Author: | A.J [ Sun Oct 25, 2009 6:16 pm ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
You are missing something... add the following line after getting the filename:
|
Author: | Magix [ Sun Oct 25, 2009 6:24 pm ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
Oh! Sorry I didn't even notice that! Thanks! So the full code would go...
|
Author: | SNIPERDUDE [ Mon Oct 26, 2009 3:58 pm ] | ||
Post subject: | Re: RE:The 20line or less weekly contest! | ||
Magix @ October 25th 2009 wrote: Oh! Sorry I didn't even notice that! Thanks! So the full code would go...
I was messing with the code (it would be over 20 lines now), and made it much more efficient by putting some of those repetitive values in for loops. This not only significantly reduced the length of the output file (9.1X on one test, 11.9X on another), but also really sped up the process. I can send you the code if you wish, but this is probably not the right thread. I was bored really. |
Author: | petree08 [ Thu Nov 12, 2009 9:36 am ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Here is my Rorschach ink blot generator
|
Author: | petree08 [ Thu Nov 12, 2009 9:45 am ] |
Post subject: | RE:The 20line or less weekly contest! |
so i don't know if it is an ink blot generator any more but i messed with it more and got this [code] var X, Y : int X := 1 Y := maxy div 2 for C : 1 .. Rand.Int (800, 1700) X := X + Rand.Int (-1, 1) Y := Y + Rand.Int (-1, 1) if X < -maxx or X > maxx or Y < 1 or Y > maxy then X := 1 Y := maxy div 2 end if drawdot ((maxx div 2) + X, Y, 7) drawdot ((maxx div 2) - X, Y, 7) View.Update end for [\code] i like this one better |
Author: | mirhagk [ Tue Nov 24, 2009 12:25 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
um so yeah they should have posted a line length limit or else i could just do this its mona lisa and random special drawing effects in 11 lines of code. (without special effects its 7 lines of code). no i did not use a picture file at all, it draws it point by point. Wanna know how i did it, well first i modified the earlier picture to turing code into the following
instead of thousands of Draw.Dot commands (and close to a million kb for some pictures) it creates an array of all the points to store a colour variable, then it adds the code to use a for loop and draw the picture using the array. then i opened the created 7 line program and proceeded to add the special effects. try it out, and you can create your own programs like this using the above code (which still qualifies for the 20 lines or less btw) |
Author: | Zasalamel [ Mon Nov 30, 2009 7:00 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
Yeah mirhagk! i didn't think you would post it... |
Author: | mirhagk [ Tue Dec 08, 2009 12:26 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
didn't think I'd post what?? the mona lisa thing, or the code used to make it?? |
Author: | Superskull85 [ Wed Dec 09, 2009 12:02 am ] | ||||
Post subject: | Re: The 20line or less weekly contest! | ||||
I was wondering how small I could make my base conversion program, and still make it usable (not entirely "the best"). Any base 2-36 to decimal (10):
Decimal (10) to any base 2-36:
I am pretty sure the algorithms will convert any number given. If not let me know. I know this is not the best algorithm that could be designed, but it gave me a challenge and made me look at the problem in a whole different way. |
Author: | Tony [ Wed Dec 09, 2009 12:12 am ] |
Post subject: | Re: The 20line or less weekly contest! |
Superskull85 @ Wed Dec 09, 2009 12:02 am wrote: I know this is not the best algorithm that could be designed
Wait, is the algorithm "use strint", or are you talking about validation/parsing-input? |
Author: | Superskull85 [ Wed Dec 09, 2009 6:10 pm ] | ||||
Post subject: | Re: The 20line or less weekly contest! | ||||
Using strint would accomplish the same thing but would not allow you to express numbers in other bases as you would be limited to the bases 2 through 36. Using my method you could convert a base one number, such as "11111" into decimal (would be five) if you wanted to (you cannot convert decimal to base one using my method). Also by adding/changing a couple of lines you could represent all the bases between 2 and 62 using all numerical characters (0-9), and all upper case (A-Z) and lower case (a-z) letters. Any base 1-36 to decimal (10):
Any decimal (10) to base 2-62:
You cannot do this with strint. So to be specific I should of said, "I was wondering how small I could make my base conversion program, without using strint and still make it usable (not entirely "the best")." instead in my previous post. |
Author: | Tony [ Wed Dec 09, 2009 6:37 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
Oh, I see what's going on now. At first I just saw the use of strint, but now your description also explains how this works beyond the limitations. Nice. |
Author: | Magix [ Thu Dec 10, 2009 5:55 pm ] | ||
Post subject: | Another Submission | ||
Here I am with another submission...a prime number finder... with Turing! You enter a low number and a high number, and the program can list out for you all the prime numbers between them, and in the end, it outputs the total number of prime numbers. Only problem is that, because of my noob coding and Turing's un-flexibility, it runs very slowly if the gap between the numbers you enter is too big. If you enter 1 and 10,000, it runs just fine, but enter 1 and 100,000, and the thing gets slower. It still works though.
This version is super-compressed to fit into 20 lines. If you want to see the full version, click here. |
Author: | mirhagk [ Sun Dec 13, 2009 9:58 am ] | ||||
Post subject: | RE:The 20line or less weekly contest! | ||||
Hey just a little tip this section:
you don't need to check if it's divisible by one right? so start it at 2 (will increase speed a little) also you already know it's divisble by itself and not divisible by numbers greater than itself. So you only need to check for numbers smaller than itself (count-1) heres what that section should look like (also remember to change the if statement checking how many factors it has, it should have 0 with the new improvements to the code)
|
Author: | Tony [ Sun Dec 13, 2009 1:56 pm ] |
Post subject: | Re: RE:The 20line or less weekly contest! |
mirhagk @ Sun Dec 13, 2009 9:58 am wrote: So you only need to check for numbers smaller than itself (count-1)
One might notice that there is a lot more numbers one does not need to check to see if a number is prime or not. Do we need to check count-2? -3? How many can we take off, and still be certain in the true/false answer for number being prime? |
Author: | DemonWasp [ Sun Dec 13, 2009 11:32 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
...and do we really need to know how many factors the number has? Isn't it enough to know that it has factors other than 1 and itself? |
Author: | mirhagk [ Sun Dec 13, 2009 11:37 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
wouldnt it be more effecient to keep an array of all the numbers set to true then set them to false if you find a number it's divisible by. then when your checking the number you can check against only if the number is true (so it only checks against prime numbers). |
Author: | ecookman [ Sun Dec 13, 2009 11:39 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
some really cool stuff here, I am just for fun going to see if I can make anything like these. Wait, isn't it possible to code everything in one line? |
Author: | mirhagk [ Sun Dec 13, 2009 11:43 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
with a ; but otherwise no. (well maybe some programs but not most useful programs) |
Author: | Tony [ Sun Dec 13, 2009 11:57 pm ] |
Post subject: | Re: RE:The 20line or less weekly contest! |
mirhagk @ Sun Dec 13, 2009 11:37 pm wrote: wouldnt it be more effecient to keep an array of all the numbers...
If you want to check a range of numbers, yes, you can use a sieve (and it would be ridiculously better); but it's not really applicable if we are checking just one number (well, it could be used in a way that we find all the primes up the current number we are checking, but that's extra work). |
Author: | mirhagk [ Mon Dec 14, 2009 2:09 am ] |
Post subject: | RE:The 20line or less weekly contest! |
well the program i have in mind would cancel out checking numbers if they have been declared by the program to be non-prime |
Author: | deltamanx [ Fri Jan 08, 2010 9:24 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
This might not look like much; but there's a reason I put it here.
This would normally do nothing special right... But guess what happened when I ran this with arguments to save everything it outputted to a file. And then left it running while I was off on a 10 day vacation? Result? 8.67 GB file composed of only NOOBNOOBNOOBNOOB... I would have attached, but you put a limit. So ya. Now take a look at this in perspective... |
Author: | chrisbrown [ Fri Jan 08, 2010 10:01 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
What a fantastic waste of computing power. IMO, each NOOB you have there increases your rank on the noob scale. Also: you could have had a file 4-6 times bigger in the same time had you used a different language... just for perspective. |
Author: | deltamanx [ Fri Jan 08, 2010 10:22 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Above was a joke submission, here's my real one.
20 line on the mark. I call it: Linear art. |
Author: | petree08 [ Thu Apr 08, 2010 11:47 am ] |
Post subject: | RE:The 20line or less weekly contest! |
It's cool man, but art? maybe not. |
Author: | prateke [ Wed May 12, 2010 5:50 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Fastest factor finder in this forum!!
its also very extremely and awesomely fast I can has teh award for this week? |
Author: | Tony [ Wed May 12, 2010 6:33 pm ] |
Post subject: | Re: The 20line or less weekly contest! |
prateke @ Wed May 12, 2010 5:50 pm wrote: Fastest factor finder in this forum!!
You can make it run in O(logN) instead of O(N) with one tiny change. |
Author: | Geniis [ Thu May 13, 2010 1:04 am ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
not sure about O(logN), but i got it O(sqrtN)(at least i think that's what it is) :
|
Author: | Brightguy [ Thu May 13, 2010 8:57 am ] |
Post subject: | Re: The 20line or less weekly contest! |
Geniis @ Thu May 13, 2010 1:04 am wrote: not sure about O(logN), but i got it O(sqrtN)(at least i think that's what it is)
Yes, O(sqrt(N)) arithmetic (not bit) operations, where N is the number to factor. The log(N) was probably a misprint: there is no known polynomial time factoring algorithm. |
Author: | Tony [ Thu May 13, 2010 9:46 am ] |
Post subject: | Re: The 20line or less weekly contest! |
Brightguy @ Thu May 13, 2010 8:57 am wrote: The log(N) was probably a misprint
Right. I was thinking of N^0.5 (that being sqrt(N)). |
Author: | BITISCT [ Thu Aug 12, 2010 12:29 am ] |
Post subject: | Re: The 20line or less weekly contest! |
Very, very minimal langton's ant. Included is the original without lines cut out |
Author: | goroyoshi [ Sat Apr 02, 2011 7:45 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
are we still doing this? if so then
|
Author: | Insectoid [ Sat Apr 02, 2011 8:28 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
If you have a look at some of the other submissions in this thread, you'll see that a button masher is not really contest material. |
Author: | mirhagk [ Thu Nov 03, 2011 2:26 am ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
Not sure if this is still going, but I made one of the scariest programs ever. It has no variables, instead it directly references memory addresses, and it has a nasty optimization because of this. See if you can a) determine what the program does b) determine how it does it. Have fun 17 lines of code, oh and make sure you input a number at the beginning
EDIT: found another spot for that little optimization, and added a cool feature to the top |
Author: | Beastinonyou [ Thu Nov 03, 2011 7:51 am ] |
Post subject: | Re: RE:The 20line or less weekly contest! |
mirhagk @ Thu Nov 03, 2011 2:26 am wrote: a) determine what the program does
Well, it seems it returns all multiples of that number. As for how it does it.... Are you David Copperfield? or David Blaine? |
Author: | mirhagk [ Thu Nov 03, 2011 5:55 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
It's not super difficult lol, it's essentially just using assembly, have to keep a few things in mind, once you get used to numbers for variables it's not hard, just a bit confusing, I can comment it all if anyone'd like. |
Author: | ClayWall [ Tue Nov 22, 2011 12:34 am ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Nothing fancy just thought if I'm the only entry this week I might win!
|
Author: | Zren [ Wed Nov 23, 2011 10:35 am ] | ||
Post subject: | RE:The 20line or less weekly contest! | ||
Denied.
Figured since this is no longer active, we should do a slightly bigger timeframe contest. I'm thinking along the lines of a monthly thing. The rules 'd change from month to month though. |
Author: | Dreadnought [ Thu Nov 24, 2011 7:11 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Well, I don't know if this program is contest material but I figured I post it anyway. It efficiently computes the nth fibonacci number... almost. For values of n larger than 74 it loses the last digits because the real numbers in turing only have 16 digit precision. (It is currently set to show the 1200th one) Here it is (I know I've used some horrible coding practices, but its 20 lines)
You can't go much higher than the 1200th before getting a real expression overflow, but the fact that you only have the first 16 digits (they're accurate) and 3 lines of zeros is unfortunate. Its light-years faster than the conventional recursive method of adding all numbers in the sequence up to the desired one (the 50th would probably take over an hour if you don't overflow). |
Author: | Insectoid [ Thu Nov 24, 2011 7:55 pm ] |
Post subject: | RE:The 20line or less weekly contest! |
Your mult_qfe function can probably be a procedure, and you can remove the 'result c' line completely since c is of global scope. What you're doing right now is modifying C, then setting C equal to itself. Then again, I have no idea what your code is doing (if you'd mind re-posting it with comments and proper function/variable names, that'd be great) so you might actually need it. Looking closer at your code you might actually be saving lines this way by not having to explicitly return C. |
Author: | Dreadnought [ Fri Nov 25, 2011 12:00 am ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
I thought of making it a procedure, but each procedure call is one line and in this case lines are precious so I left it as a function. As for the usage of the global C, its purpose was just to save a line of code within the mult_qfe function which would have declared C locally. I agree, though that the code is though to read. It was closer to 30 lines when it was readable so removing lines meant creating gibberish. To understand what's going on, I'm using a closed form to generate numbers in the Fibonacci sequence very quickly. The equation for the nth number in the sequence is Fn = (q^n - (1 - q)^n)/(sqrt 5), where q = (1 + (sqrt 5))/2 Since you asked, here's a readable, commented version of my code (I changed QFE to IRE)
By the way, IRE and QFE were just made up names for an equation with an irrational root. I use them to maintain complete accuracy throughout computation. Also, on line 10 of my original code, I could use elsif and save 2 lines, derp. |
Author: | Aange10 [ Fri Nov 25, 2011 12:24 am ] | ||||
Post subject: | RE:The 20line or less weekly contest! | ||||
y has not been declared. And as for a color tester
use it all the time EDIT: Or if we are aloud to use semi colens
|
Author: | Dreadnought [ Fri Nov 25, 2011 12:50 pm ] |
Post subject: | Re: The 20line or less weekly contest! |
Ya, your right, line 20 should be var y : IRE := exp_IRE (x, n div 2) Change that and it should work. (the 20 line version still works though) |
Author: | Jeffmagma [ Thu Dec 10, 2015 1:21 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
Doesn't seem like this is going on anymore, but for fun:
|
Author: | Jeffmagma [ Fri Jan 22, 2016 1:49 pm ] | ||
Post subject: | Re: The 20line or less weekly contest! | ||
yay boxes
|