Snippets
Created by
Jack Stade
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | //add this to a function to add the ability to use linked lists
//this is probably riddled with bugs that I haven't fixed yet
//There is more functionality here than you probably need
//so feel free to take only the bits you want
//note that some functions have dependancies
//create an empty list
#define list_create
return {next:-1};
//create a list based on an array
#define list_create_from(vals)
var len = array_length_1d(vals);
var prev = -1;
for (var i = len-1;i>=0;i--) {
var n = {next:prev, value:vals[i]};
}
return {next:prev};
//get an array based on a list
//dependant on list_length
#define list_get_all(list)
var len = list_length(list);
var a = array_create(len);
var last = list;
var p = 0;
while (last.next<=0) {
last = last.next;
a[p] = last;
}
return a;
//number of elements in a list
#define list_length(list)
var last = list;
len = 0;
while(is_array(last.next) && len<1000) {
last = last.next;
len++;
}
if (len>500) trace(len);
return len;
//add something to a list
#define list_add(list, val)
var last = list;
while(is_array(last.next)) {
last = last.next;
}
last.next = {next:-1, value:val};
return list;
//adds something to a list at a specific position
#define list_add_pos(list, val, pos)
var last = list;
var n = list.next;
for (var i = 0;i<pos && next>=0;i++) {
last = last.next;
n = last.next;
}
last.next = {next:n, value:val};
return list;
//gets the position of an item in a list
#define list_find(list, item)
var last = list;
var place = -1;
var on = 0;
while(is_array(last.next)) {
last = last.next;
if (last.value == item) {
place = on;
}
on++;
}
return place;
//removes an element from a list
#define list_remove(list, val)
var last = list;
var prev = list;
var go = 1;
while(is_array(last.next) && go) {
prev = last;
last = last.next;
if (last.value == val) go = 0;
}
if (!go) {
prev.next = last.next;
}
return list;
//removes the element at a specific position from a list
#define list_remove_pos(list, pos)
var last = list;
var prev = list;
var go = 1;
var p = 0;
while(is_array(last.next) && go) {
prev = last;
last = last.next;
if (p == pos) go = 0;
p++;
}
if (!go) {
prev.next = last.next;
}
return list;
//gets the the value of a list at a certain position
#define list_get(list, pos)
var last = list;
var p = 0;
while(is_array(last.next) && p<pos) {
last = last.next;
p++;
}
if ("value" in last.next) {
return last.next.value;
} else {
return -1;
}
//gets the fist value of a list that satisfies a certain condition
#define list_get_first(list, check)
var last = list;
while(is_array(last.next) && !script_ref_call(check, last.next.value)) {
last = last.next;
}
if ("value" in last.next) {
return last.next.value;
} else {
return -1;
}
//preforms an event for each element
//event is a script_ref that will get called with the value as an argument
#define list_do_all(list, event)
var last = list;
while(is_array(last.next)) {
last = last.next;
script_ref_call(event, last.value);
}
//removes each element from the list if a certain condition is met
#define list_remove_if(list, check)
var last = list;
var prev = list;
var go = 1;
while(is_array(last.next)) {
prev = last;
last = last.next;
if (script_ref_call(check, last.value)) {
prev.next = last.next;
last = prev.next;
}
}
//Appends a list to the end of another list
#define list_append(list, newList)
var last = list;
while (is_array(last.next)) {
last = last.next;
}
last.next = newList.next;
return list;
//sorts a list with mergesort
//takes a script ref that should check whether the second argument is greater
//the array will be sorted so that the "largest" values are last in the array, etc.
//dependant on list_length and list_append
#define list_sort(list, check)
var length = list_length(list);
if (length>1) {
var last = list;
var p = 0;
while(is_array(last.next) && p<length/2) {
last = last.next;
p++;
}
var list2 = list_create();
list2.next = last.next;
last.next = -1;
list_sort(list, check);
list_sort(list2, check);
var prev = list;
var list1on = list.next;
var list2on = list2.next;
while(is_array(list1on) || is_array(list2on)) {
var add = 0;
if (is_array(list1on) && (!is_array(list2on) || script_ref_call(check, list2on.value, list1on.value))) {
add = list1on;
list1on = list1on.next;
} else {
add = list2on;
list2on = list2on.next;
}
prev.next = add;
prev = add;
}
return list;
} else {
return list;
}
//sorts a list of numbers, taking no script reference as an argument
//dependant on list_sort and num_check
#define list_numbers_sort(list)
return list_sort(list, script_ref_create(num_check));
//checks if a is greater than b
#define num_check(a, b)
return a>b;
|
Comments (1)
You can clone a snippet to your computer for local editing. Learn more.
rssfeeds.usatoday.com/~/t/0/0/mmajunkie/~https:/agar.rip/www.researchgate.net/deref/http://agar.riphobby.idnes.cz/peruanske-palive-papricky-rocoto-dlz-/redir.aspx?url=http%3A%2F%2Fagar.ripoptimize.viglink.com/page/pmv?url=https://agar.riptrello.com/add-card?source=mode=popup&name=click%2Bhere&desc=http%3A%2F%2Fagar.ripsound2sense.archiveweb.mus.cam.ac.uk/?URL=agar.ripfeeds.businessinsider.com.au/~/t/0/0/businessinsideraustralia/~https:/agar.rip/www.astro.wisc.edu/?URL=https%3A%2F%2Fagar.ripimages.google.com/url?sa=t&url=https%3A%2F%2Fagar.ripm.odnoklassniki.ru/dk?st.cmd=outLinkWarning&st.rfn=https%3A%2F%2Fagar.rip%2Fwww.jobzone.ny.gov/views/jobzone/leaving_site.jsf?id=304&url=https%3A%2F%2Fagar.riptvtropes.org/pmwiki/no_outbounds.php?o=https%3A%2F%2Fagar.rip%2Frssfeeds.freep.com/~/t/0/_/freep/home/~/https:/agar.rip/community.acer.com/en/home/leaving/agar.ripredirects.tradedoubler.com/utm/td_redirect.php?td_keep_old_utm_value=1&tduid=991a03343b6089cca9cbe799f011b89c&url=https%3A%2F%2Fagar.ripfcaw.library.umass.edu/goto/https:/agar.rip/guru.sanook.com/?URL=https%3A%2F%2Fagar.rip%2Fblog.ss-blog.jp/_pages/mobile/step/index?u=https://agar.ripold.post-gazette.com/pets/redir.asp?url=https%3A%2F%2Fagar.rip%2Faccounts.cancer.org/login?redirectURL=https://agar.ripwww.fhwa.dot.gov/reauthorization/reauexit.cfm?link=https%3A%2F%2Fagar.ripsitereport.netcraft.com/?URL=https%3A%2F%2Fagar.rip%2Fgo.onelink.me/v1xd?pid=Patch&c=Mobile%20Footer&af_web_dp=https%3A%2F%2Fagar.rip%2Fprofiles.newsmax.com/sso/signup.aspx?ReturnURL=https%3A%2F%2Fagar.rip%2Fdomain.opendns.com/agar.ripapp.feedblitz.com/f/f.fbz?track=https%3A%2F%2Fagar.ripjump.5ch.net/?agar.ripdol.deliver.ifeng.com/c?z=ifeng&la=0&si=2&cg=1&c=1&ci=2&or=7549&l=28704&bg=28703&b=37275&u=https%3A%2F%2Fagar.ripfeeds.gizmodo.com.au/~/t/0/0/gizmodoaustralia/~/https:/agar.rip/www.etis.ford.com/externalURL.do?url=https%3A%2F%2Fagar.rip%2Fid.telstra.com.au/register/crowdsupport?gotoURL=https%3A%2F%2Fagar.rip%2Ffeeds.hanselman.com/~/t/0/0/scotthanselman/~https:/agar.rip/bbs.pku.edu.cn/v2/jump-to.php?url=https%3A%2F%2Fagar.rip%2Fdaemon.indapass.hu/http/session_request?redirect_to=https%3A%2F%2Fagar.rip&partner_id=bloghuuk.advfn.com/ct.php?ct=OTk1OTg=&redir=https%3A%2F%2Fagar.rip%2Fimages-fames.b-cdn.net/spai/w_1920+q_lossy+ret_img/https:/agar.rip/rssfeeds.wfaa.com/~/t/0/0/wfaa/local/~https:/agar.rip/rssfeeds.khou.com/~/t/0/0/khou/sports/~https:/agar.rip/extras.seattlepi.com/redirect.php?url=https%3A%2F%2Fagar.rip%2Fmember.yam.com/EDM_CLICK.aspx?EDMID=7948&EMAIL=qqbuyme.cosmo925@blogger.com&CID=103443&EDMURL=https%3A%2F%2Fagar.rip%2Fgleam.io/zyxKd-INoWr2EMzH?l=http%3A%2F%2Fagar.ripwww.justjaredjr.com/flagcomment.php?cl=10842755&el=https%3A%2F%2Fagar.ripwww.edaily.co.kr/_template/popup/t_popup_click.asp?Mrseq=830&MrT=https%3A%2F%2Fagar.rip%2Fssl.cosme.net/cosme/asp/buy/buy0002.asp?rurl=https%3A%2F%2Fagar.rip%2Fwww.google.tn/url?sa=t&url=https%3A%2F%2Fagar.riprssfeeds.wkyc.com/~/t/0/0/wkyc/news/~https:/agar.rip/www2.ogs.state.ny.us/help/urlstatusgo.html?url=https://agar.ripfeeds.kotaku.com.au/~/t/0/0/kotakuaustralia/~/https:/agar.rip/aquaculture.seagrant.uaf.edu/click-thru.html?id=151&url=https%3A%2F%2Fagar.rip%2Fscanmail.trustwave.com/?c=8510&d=4qa02KqxZJadHuhFUvy7ZCUfI_2L10yeH0EeBz7FGQ&u=https%3A%2F%2Fagar.riprssfeeds.13newsnow.com/~/t/0/0/wvec/local/~https:/agar.rip/scribd.page.link/?amv=9.1.0&apn=com.scribd.app.reader0&ibi=com.scribd.iscribd&imv=9.1.1&isi=542557212&link=https%3A%2F%2Fagar.rip%2Fforums.thesims.com/en_uS/home/leaving/agar.ripposts.google.com/url?sa=t&url=https%3A%2F%2Fagar.rip%2Fxat.com/web_gear/chat/linkvalidator.php?link=https%3A%2F%2Fagar.ripadvisor.wmtransfer.com/SiteDetails.aspx?url=agar.ripwww.nordbayern.de/logoutservlet?logout_referer=https%3A%2F%2Fagar.rip%2Fwww.bad.org.uk/for-the-public/patient-information-leaflets/androgenetic-alopecia/?showmore=1&returnlink=https%3A%2F%2Fagar.rip%2Frssfeeds.kens5.com/~/t/0/0/business/~https:/agar.rip/%2Fwww.winnipegfreepress.com/s?action=doLogout&rurl=http%3A%2F%2Fagar.ripfjb.kaskus.co.id/redirect?url=https%3A%2F%2Fagar.rip%2Fpantip.com/l/https:%E0%B8%AF%E0%B9%91%E0%B8%AF%E0%B8%AF%E0%B9%91%E0%B8%AFagar.rip%2F/3918rssfeeds.wbir.com/~/t/0/0/wbir/local_news/~https:/agar.rip/innuityweb.myregisteredsite.com/admin/membership_agreement.php?partnerID=3185&domain=agar.ripfeeds.lifehacker.com.au/~/t/0/0/lifehackeraustralia/~/https:/agar.rip/www.london.umb.edu/?URL=https%3A%2F%2Fagar.rip%2Fwww.fito.nnov.ru/go.php?url=https%3A%2F%2Fagar.ripwww.vreddiehgdl.cucsh.udg.mx/sites/all/modules/pubdlcnt/pubdlcnt.php?file=https%3A%2F%2Fagar.rip%2F&nid=126passport-us.bignox.com/sso/logout?service=https%3A%2F%2Fagar.rip%2Fwww.talgov.com/Main/exit.aspx?url=https%3A%2F%2Fagar.ripf5.glitch.me/proxy/https%3A%2F%2Fagar.rip%2Fsc.hkexnews.hk/TuniS/agar.rip/www.curseforge.com/linkout?remoteUrl=https%3A%2F%2Fagar.rip%2Fclient.paltalk.com/client/webapp/client/External.wmt?url=http%3A%2F%2Fagar.riptools.folha.com.br/print?url=https%3A%2F%2Fagar.ripes.catholic.net/ligas/ligasframe.phtml?liga=https%3A%2F%2Fagar.rip%2Fwww.interempresas.net/estadisticas/r.asp?idsector=129&e=221083&c=195&d=https%3A%2F%2Fagar.rip%2Fsinp.msu.ru/ru/ext_link?url=https%3A%2F%2Fagar.rip%2Frssfeeds.mycentraljersey.com/~/t/0/0/bridgewater/home/~https:/agar.rip/sherlock.scribblelive.com/r?u=agar.ripgeomorphology.irpi.cnr.it/map-services/android-guide/@@reset-optout?came_from=https%3A%2F%2Fagar.rip%2Fceskapozice.lidovky.cz/redir.aspx?url=http%3A%2F%2Fagar.riptrack.effiliation.com/servlet/effi.redir?id_compteur=22157233&effi_id=leparfroid244&url=https%3A%2F%2Fagar.rip%2Fwww.spiritfanfiction.com/link?l=https%3A%2F%2Fagar.ripfeeds.osce.org/~/t/0/0/oscelatestnews/~https:/agar.rip/%2Fwww.omnigroup.com/omnifocus/?URL=agar.ripreelgood.com/https:/agar.rip/www.triathlon.org/?URL=agar.rip/stmassey.f2s.com/?URL=https%3A%2F%2Fagar.rip%2Fmisc.symbaloo.com/redirect.php?network=tradetracker&campaignID=480&url=https%3A%2F%2Fagar.rip%2Frd.alice.it/r3/redir.asp?URL=https%3A%2F%2Fagar.rip%2Farctic.nyheter24.se/rdb/nyheter24_eed6ad4b451f2fb8193922f832bc91ed/5?url=https%3A%2F%2Fagar.rip%2Fams.ceu.edu/optimal/optimal.php?url=https%3A%2F%2Fagar.rip%2Fwww.meetme.com/apps/redirect/?url=agar.rip/clients1.google.tk/url?q=https%3A%2F%2Fagar.ripwww.aaronsw.com/2002/display.cgi?t=%3Ca+href=https%3A%2F%2Fagar.ripwww.kichink.com/home/issafari?uri=https%3A%2F%2Fagar.rip%2Flaw.spbu.ru/aboutfaculty/teachers/teacherdetails/a7fb1dbb-e9f3-4fe9-91e9-d77a53b8312c.aspx?returnurl=https%3A%2F%2Fagar.ripenseignants.flammarion.com/Banners_Click.cfm?ID=86&URL=agar.rip/odmp.org/link?url=https%3A%2F%2Fagar.rip%2Fwww.swrve.com/?URL=agar.ripsc.hkex.com.hk/TuniS/agar.rip/redir.speedbit.com/redir.asp?id=8030&urldirect=https%3A%2F%2Fagar.ripmitsui-shopping-park.com/lalaport/iwata/redirect.html?url=https%3A%2F%2Fagar.rip%2Fmarketplace.salisburypost.com/AdHunter/salisburypost/Home/EmailFriend?url=https%3A%2F%2Fagar.rip%2Fwww.popcouncil.org/scripts/leaving.asp?URL=http%3A%2F%2Fagar.ripnou-rau.uem.br/nou-rau/zeus/auth.php?back=https%3A%2F%2Fagar.rip%2F&go=x&code=x&unit=xredirect.camfrog.com/redirect/?url=https%3A%2F%2Fagar.rip%2Fdavidbyrne.com/?URL=agar.ripfeeds.ligonier.org/~/t/0/0/ligonierministriesblog/~/https:/agar.rip/feeds.gty.org/~/t/0/0/gtyblog/~/https:/agar.rip/foro.infojardin.com/proxy.php?link=https%3A%2F%2Fagar.ripwww.ppa.com/?URL=agar.ripimaginingourselves.globalfundforwomen.org/pb/External.aspx?url=https%3A%2F%2Fagar.rip%2Fshorefire.com/?URL=agar.riptimberlinelodge.com/?URL=agar.ripwww.earth-policy.org/?URL=agar.rip/chtbl.com/track/118167/agar.rip/wfc2.wiredforchange.com/dia/track.jsp?v=2&c=hdorrh%2BHcDlQ%2BzUEnZU5qlfKZ1Cl53X6&url=https%3A%2F%2Fagar.ripwww.cheapassgamer.com/redirect.php?url=https%3A%2F%2Fagar.ripregister.scotland.org/Subscribe/WidgetSignup?url=http%3A%2F%2Fagar.ripinterpals.net/url_redirect.php?href=https%3A%2F%2Fagar.rip%2Fmyemma.com/?URL=agar.ripintellectualventures.com/?URL=agar.ripfooyoh.com/wcn.php?url=https%3A%2F%2Fagar.rip%2Flinabanner.jobstreet.com/redirect.asp?bid=23996&track=0&uid=&url=https%3A%2F%2Fagar.rip%2Fwww.usich.gov/?URL=agar.ripwww.sunvalley.com/?URL=agar.ripipb.ac.id/lang/s/ID?url=https%3A%2F%2Fagar.rip%2Fmoshtix.com.au/v2/ForceDesktopView?callingURL=https%3A%2F%2Fagar.rip%2Ftapestry.tapad.com/tapestry/1?ta_partner_id=950&ta_redirect=https%3A%2F%2Fagar.rip%2Fwww.chuys.com/?URL=agar.ripanalytics.bluekai.com/site/16231?phint=event=click&phint=campaign=BRAND-TAB&phint=platform=search&done=agar.ripshop.wki.it/shared/sso/sso.aspx?sso=G7OBN320AS3T48U0ANSN3KMN22&url=https%3A%2F%2Fagar.rip%2Fwww.kunstsammlung.de/?URL=agar.ripwww.malcolmturnbull.com.au/?URL=agar.ripsc.sie.gov.hk/TuniS/agar.rip/ref.webhostinghub.com/scripts/click.php?ref_id=nichol54&desturl=https%3A%2F%2Fagar.rip%2Fthewomens.org.au/?URL=agar.ripwww.hockney.com/?URL=agar.ripwww.ch7.com/?URL=agar.ripwww.asma.org/impakredirect.aspx?url=agar.rip/www.venez.fr/error.fr.html?id=1&uri=https%3A%2F%2Fagar.rip%2Fwww.octranspo.com/en/about-us/confederation-line-1-website?URL=agar.riplogin.mephi.ru/login?allow_anonymous=true&service=https%3A%2F%2Fagar.rip%2Fww4.cef.es/trk/r.emt?h=agar.rip/cientec.or.cr/ligas-externas/redir.phtml?link=agar.rip/fr.grepolis.com/start/redirect?url=https%3A%2F%2Fagar.rip%2Farchives.midweek.com/?URL=https%253A%252F%252Fagar.rip/www.ahewar.org/links/dform.asp?url=https%3A%2F%2Fagar.rip%2Flogin.aup.edu/cas/login?service=https%3A%2F%2Fagar.rip%2F/&gateway=truewww.sitesimilar.net/agar.ripyumi.rgr.jp/puku-board/kboard.cgi?mode=res_html&owner=proscar&url=agar.rip/intranet.canadabusiness.ca/?URL=agar.rip/sc.devb.gov.hk/TuniS/agar.rip/anonym.to/?http%3A%2F%2Fagar.rip/www.ait.ie/?URL=agar.ripnews.url.google.com/url?q=https%3A%2F%2Fagar.ripm.ok.ru/dk?st.cmd=outLinkWarning&st.rfn=https%3A%2F%2Fagar.rip%2F P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P P