Don't have an account? Register now to chat, post, use our tools, and much more.
Online Users
There are 130 users online: 6 members, 99 guests and 25 bots.
Members: HOMER-16, Piguy-3.14, Tari.
Bots: Spinn3r (1), Magpie Crawler (6), VoilaBot (1), Googlebot (17).
SAX
Author Message
MufinMcFlufin

Joined: 29 Aug 2009
Posts: 252

 Posted: 15 Oct 2010 11:03:03 pm    Post subject: Nested Loops in One Line of Code Well, after thinking a bit about a piece of code made by Weregoose, I wanted to try and replace this code: (Note, that this code is for a program I made that finds the most similar printable character to one that you draw 8 pixels to the right of the tested characters. I don't think much any further explanation is needed, but do ask if you need more info) Code: ```:For(D,1,6 :For(O,2,6 :L1(A)+(pxl-Test(D,O)=pxl-Test(D,O+8→L1(A :End :End ``` I wanted to replace that code with some more efficient code that would use something along the lines of the summation of the sequence of pxl-tests, or whatnot. Then I decided to try and nest one seq( into another, and see if that would work. Here's what I came up with, after not doing my research on the seq( command: Code: ```:sum(seq(sum(seq(pxl-Test(D,O)=pxl-Test(D,O+8),O,2,6)),D,1,6 ``` Well...that didn't work, as apparently you can't nest one seq( into another. So, after some fiddling around, I came up with this code: Code: ```:round(FnInt(sum(seq(pxl-Test(int(D),int(O))=pxl-Test(int(D),int(O)+8),O,2,7-{EE}‾9)),D,1,7-{EE}‾9),0 ``` Toyed around with it, and found it works perfectly, however I've found that it's speed depends on how many pixels are the same. What I know so far about it is that it runs significantly faster with 30 pixels the same (all pixels the same in it's testing area) than with 29 pixels the same. I made a little program to test and record the speed of this code comparing all situations, from 30 pixels the same, to 0 pixels the same. I'm going to have it run throughout the night (I put it on wabbit emu, so I won't have to worry about battery life), as it's so far been running about 10 minutes, and it's still at 1 changed pixel. It currently does only 50 iterations per pixel change considering the fastest I've seen it do so far is about 3-5 seconds with 30 pixels the same, against about 30 seconds to a minute with 29 pixels the same, so 4000 iterations didn't seem necessary. Here's the code I'm using for it: Code: ```:ClrDraw :Pt-Off(0,0 :50→C :{6,6→dim([A] :Fill(0,[A] :For(E,1,6 :For(P,2,6 :startTmr→B :For(A,1,C :round(FnInt(sum(seq(pxl-Test(int(D),int(O))=pxl-Test(int(D),int(O)+8),O,2,7-{EE}‾9)),D,1,7-{EE}‾9),0 :End :checkTmr(B)/C→[A](E,P :Disp Ans :Pxl-Change(E,P :End :End ``` Here are the results I got:Code: ```# Pixels different:  0    1     2     3     4     5     6     7     8     9    10   11   12 Time per iteration: 1.4 42.82 45.58 48.32 48.28 50.82 89.74 78.58 78.54 89.56 4.12 42.8 45.54 # Pixels different:  13   14    15    16    17    18   19    20    21    22    23    24 Time per iteration: 48.3 48.26 50.78 89.68 78.56 78.5 89.52 50.74 47.96 47.94 45.14 42.4 ``` Anyone have a clue as to why the time varies so much depending on how many pixels are different?_________________ MufinMcFlufin's quote of the week: "Diapers and Politicians should both be changed often for the same reason." -Anonymous
KermMartian

Joined: 14 Mar 2005
Posts: 55879
Location: Earth, Sol, Milky Way

 Posted: 17 Oct 2010 07:03:51 pm    Post subject: Absolutely. It hinges on how the calculator's integration works. If there's an area with high delta-slope, it will use a much more fine-grained X increment in that area to increase accuracy. In areas with low or zero delta-slope, it will use a larger increment to save time on the assumption that not much is changing._________________
MufinMcFlufin

Joined: 29 Aug 2009
Posts: 252

 Posted: 17 Oct 2010 07:14:44 pm    Post subject: So you think it might go faster if I do this instead: Code: ``` :round(sum(seq(fnInt(pxl-Test(int(D),O)=pxl-Test(int(D),O+8),D,2,7-{EE}‾9),O,2,6)),0 ```_________________ MufinMcFlufin's quote of the week: "Diapers and Politicians should both be changed often for the same reason." -Anonymous
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
 Page 1 of 1 » All times are GMT - 5 Hours

 Jump to: Select a forum Announcements----------------Cemetech AnnouncementsCemetech LabsContests General Discussion----------------Technology & Calculator Open Topic-- Electronics/Hardware Development-- Calculator HardwareYour ProjectsGeneral Open Topic-- Politics & Rants-- Reviews-- Humour/Jokes Cemetech's Projects----------------Doors CSSourceCoderMember Features-- TI-Freak8x-- Merthsoft-- GrammerOther & Upcoming Projects-- The BASIC Elite-- mobileTunes-- CALCnet 2.2-- SuggestionsProgramming the TI-83 Plus/TI-84 PlusUsing the TI-83 Plus/TI-84 PlusWebsite Programming & Design----------------General Programmingz80 AssemblyTI-BASICCasio Prizm/FX Development & ProgrammingWebsite Markup & ScriptingGraphics1337 Programming Tips Building with Blocks----------------FreeBuild, LEGO, and Minecraft-- FreeBuild General-- Suggestions & Troubleshooting-- Content & Gallery-- Servers & Activities
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.027699 seconds.