Whoa, whoa, whoa ... stop typing your program. No, I don't mean "print ABC...." I'm talking the capitals of the United States.
Specifically, print all the city/state combinations given in the following list
- in any order
- with your choice of delimiters (e.g.,
Baton Rouge`LA_Indianapolis`IN_...is acceptable), so long as it's unambiguous which words are cities, which are states, and which are different entries - without using any of
ABCDEFGHIJKLMNOPQRSTUVWXYZin your source code
Output should be to STDOUT or equivalent.
EDIT - Whoops!
<edit>
While typing up the list from memory (thanks to the Animaniacs, as described below), I apparently neglected Washington, DC, which isn't a state capital, but is in the song, and is sometimes included in "lists of capitals" (like the Mathematica answer below). I had intended to include that city in this list, but missed it, somehow. As a result, answers that don't have that city won't be penalized, and answers that do have that city won't be penalized, either. Essentially, it's up to you whether Washington, DC is included in your ouput or not. Sorry about that, folks!
</edit>
Baton Rouge, LA
Indianapolis, IN
Columbus, OH
Montgomery, AL
Helena, MT
Denver, CO
Boise, ID
Austin, TX
Boston, MA
Albany, NY
Tallahassee, FL
Santa Fe, NM
Nashville, TN
Trenton, NJ
Jefferson, MO
Richmond, VA
Pierre, SD
Harrisburg, PA
Augusta, ME
Providence, RI
Dover, DE
Concord, NH
Montpelier, VT
Hartford, CT
Topeka, KS
Saint Paul, MN
Juneau, AK
Lincoln, NE
Raleigh, NC
Madison, WI
Olympia, WA
Phoenix, AZ
Lansing, MI
Honolulu, HI
Jackson, MS
Springfield, IL
Columbia, SC
Annapolis, MD
Cheyenne, WY
Salt Lake City, UT
Atlanta, GA
Bismarck, ND
Frankfort, KY
Salem, OR
Little Rock, AR
Des Moines, IA
Sacramento, CA
Oklahoma City, OK
Charleston, WV
Carson City, NV
(h/t to Animaniacs for the list of capitals)
Take a bonus of -20% if your submission doesn't explicitly have the numbers 65 through 90 or the number 1 in the code. Generating these numbers (e.g., a=5*13 or a="123"[0] or a=64;a++ or the like) is allowed under this bonus, explicitly having them (e.g., a=65 or a="1 23 456"[0]) is not.
Leaderboard
var QUESTION_ID=60650,OVERRIDE_USER=42963;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+(?:[.]\d+)?)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
20 Answers 20
Mathematica, (削除) 168 (削除ここまで) (削除) 153 (削除ここまで) 149 bytes - 20% = 119.2 bytes
u="\.55nited\.53tates";\.41dministrative\.44ivision\.44ata[{#,u}&/@\.43ountry\.44ata[u,"\.52egions"],{"\.43apital\.4eame","\.53tate\.41bbreviation"}]
Obligatory, but I did not know that any character can be replaced by \.xx or \:xxxx with the appropriate hex code.
Edit: Cut of 4 more characters by replacing Thread with a pure function.
Output:
{{Montgomery,AL},{Juneau,AK},{Phoenix,AZ},{Little Rock,AR},{Sacramento,CA},{Denver,CO},{Hartford,CT},{Dover,DE},{Washington,DC},{Tallahassee,FL},{Atlanta,GA},{Honolulu,HI},{Boise,ID},{Springfield,IL},{Indianapolis,IN},{Des Moines,IA},{Topeka,KS},{Frankfort,KY},{Baton Rouge,LA},{Augusta,ME},{Annapolis,MD},{Boston,MA},{Lansing,MI},{Saint Paul,MN},{Jackson,MS},{Jefferson City,MO},{Helena,MT},{Lincoln,NE},{Carson City,NV},{Concord,NH},{Trenton,NJ},{Santa Fe,NM},{Albany,NY},{Raleigh,NC},{Bismarck,ND},{Columbus,OH},{Oklahoma City,OK},{Salem,OR},{Harrisburg,PA},{Providence,RI},{Columbia,SC},{Pierre,SD},{Nashville,TN},{Austin,TX},{Salt Lake City,UT},{Montpelier,VT},{Richmond,VA},{Olympia,WA},{Charleston,WV},{Madison,WI},{Cheyenne,WY}}
-
\$\begingroup\$ I don't think the forbidden numbers are used either \$\endgroup\$user46060– user460602015年10月13日 17:06:20 +00:00Commented Oct 13, 2015 at 17:06
-
\$\begingroup\$ Very clear way to capitalise. I wasn't aware of that use of hex codes. How do you get them not to immediately display as capitals in the code? \$\endgroup\$DavidC– DavidC2015年10月13日 17:28:08 +00:00Commented Oct 13, 2015 at 17:28
-
2\$\begingroup\$ This may save some code, even after you replace the caps:
EntityValue[EntityList[EntityClass["AdministrativeDivision", "AllUSStatesPlusDC"]], {"CapitalName","StateAbbreviation"}]\$\endgroup\$DavidC– DavidC2015年10月13日 17:37:18 +00:00Commented Oct 13, 2015 at 17:37 -
\$\begingroup\$ @DavidCarraher Too many capitals in
AllUSStatesPlusDCI'm afraid! \$\endgroup\$user46060– user460602015年10月13日 19:10:09 +00:00Commented Oct 13, 2015 at 19:10 -
\$\begingroup\$ Yes. I see what you mean. \$\endgroup\$DavidC– DavidC2015年10月13日 19:32:12 +00:00Commented Oct 13, 2015 at 19:32
R, (削除) 96 bytes (削除ここまで) 98 bytes -20% -> 78.4
Thanks to @plasticinsect for the bonus!
library(maps);data(us.cities);cat(gsub("()( \\w+)$",",\2円",us.cities$n[us.cities$ca==2]),sep="\n")
Previous code at 96 bytes:
library(maps);data(us.cities);cat(gsub("( \\w+)$",",\1円",us.cities$n[us.cities$ca==2]),sep="\n")
From package maps, it loads a dataset of US cities. Column capital contains a 2 if it is a state capital. The names of the cities are given is column name in the form "City StateAbbreviation" (i. e. Albany NY), so one need to add an explicit delimiter in between before output. (削除) To do so I eventually use the regex To avoid using 1円 meaning I can't have the bonus I suppose. (削除ここまで)1円 in the regex I added an empty group so that I can use 2円.
Usage:
> library(maps);data(us.cities);cat(gsub("()( \\w+)$",",\2円",us.cities$n[us.cities$ca>1]),sep="\n")
Albany, NY
Annapolis, MD
Atlanta, GA
Augusta, ME
Austin, TX
Baton Rouge, LA
Bismarck, ND
Boise, ID
Boston, MA
Carson City, NV
Charleston, WV
Cheyenne, WY
Columbia, SC
Columbus, OH
Concord, NH
Denver, CO
Des Moines, IA
Dover, DE
Frankfort, KY
Harrisburg, PA
Hartford, CT
Helena, MT
Honolulu, HI
Indianapolis, IN
Jackson, MS
Jefferson City, MO
Juneau, AK
Lansing, MI
Lincoln, NE
Little Rock, AR
Madison, WI
Montgomery, AL
Montpelier, VT
Nashville, TN
Oklahoma City, OK
Olympia, WA
Phoenix, AZ
Pierre, SD
Providence, RI
Raleigh, NC
Richmond, VA
Sacramento, CA
Saint Paul, MN
Salem, OR
Salt Lake City, UT
Santa Fe, NM
Springfield, IL
Tallahassee, FL
Topeka, KS
Trenton, NJ
-
\$\begingroup\$ If you add an empty capture group to the beginning of your regex, you could use 2円 instead of 1円. It would cost you two bytes, but gain you the bonus. \$\endgroup\$plasticinsect– plasticinsect2015年10月16日 07:17:54 +00:00Commented Oct 16, 2015 at 7:17
-
\$\begingroup\$ @plasticinsect Thanks! I wouldn't have thought of that. \$\endgroup\$plannapus– plannapus2015年10月16日 07:44:07 +00:00Commented Oct 16, 2015 at 7:44
-
\$\begingroup\$ Great use of built-in. Three things: 1. you can type the newline within the code instead of
\nfor 1 byte,>0instead of ``==2` and also I don't think you needdata(us.cities), on my machine it loads when you load the pacakage. Try it out! \$\endgroup\$JayCe– JayCe2018年05月17日 14:17:08 +00:00Commented May 17, 2018 at 14:17 -
2\$\begingroup\$ Even shorter by renaming the data. \$\endgroup\$JayCe– JayCe2018年05月17日 14:21:26 +00:00Commented May 17, 2018 at 14:21
CJam, 312 bytes
".ýç9.5i-jæ¤þ ̧«Ã«cj|ù;ÎüÄ`Ñ ̄Äÿçsøi4ÔÚ0;3⁄4o'ÈàÚãÕ»®1⁄4v{Ðù·*ñfiö\^é]ù¬ðö ̧qÚpÿ©a$ÿÆhk×ばつïÕ{ñ9ÁÛ%Ðø¦ð·âßxâj Öë¬ ̄,Ð+?Û¡!ù%Âí©Úfx`¤|}1⁄4>qñμÉÎ4Óæj-wöÄÆ 4,üÖáÌxsÍ·üãýÛêmÁj±æ0?3¢¶§%Û57Ëmc.~`b= ́á\ÉpË,ôb¶ÌsÁì3⁄4*§òÿ_Ö©;<tíèz6ljç ̧b§èäø&g×ばつÔÎîæ¡©)Ô@"'[fm256,f=)b27b'`f+'`/{_2>'q/32af.^' *o2<eup}/
The code is 390 bytes long and qualifies for the 20% bonus.
Note that the code is riddled with unprintable characters. Try it online in the CJam interpreter.
Idea
We have to encode the output somehow without using uppercase letters or the numbers 1 and 65 to 90 anywhere in the code.
We start by rewriting the desired output as
akjuneau`paharrisburg`txaustin`maboston`wvcharleston`azphoenix`kyfrankfort`msjackson`mdannapolis`vtmontpelier`ndbismarck`hihonolulu`meaugusta`nvcarsonqcity`sccolumbia`ohcolumbus`wycheyenne`casacramento`arlittleqrock`nmsantaqfe`mnsaintqpaul`idboise`tnnashville`codenver`nhconcord`almontgomery`inindianapolis`riprovidence`utsaltqlakeqcity`ilspringfield`ncraleigh`labatonqrouge`sdpierre`dedover`orsalem`waolympia`kstopeka`varichmond`cthartford`nyalbany`milansing`njtrenton`mthelena`iadesqmoines`gaatlanta`wimadison`nelincoln`fltallahassee`okoklahomaqcity`mojefferson
By subtracting the character ` from all characters of that string, we obtain an array containing integers from 0 to 26. We can convert this array from base 27 to base 229, yielding an array of integers from 0 to 228.
If we add 91 to each base-229 digit and take the results modulo 256, we map the range [0, …, 164] to [91, … 255], and the range [165, …, 228] to [0, …, 63]. This leaves the characters with code points from 64 (@) to 90 (Z) unused.
The string to encode is not in the same order as the sample output in the question. I tried several permutation until I found one that contains no null bytes, linefeeds, carriage returns or non-breaking spaces (problematic with the online interpreter), and no double quotes (require escaping).
Code
"...@" e# Push a string of 342 ISO-8859-1 characters.
'[fm e# Subtract the char '[' (code point 91) from each char of the string.
256,f= e# Compute the remainder of the differences divided by 256.
) e# Pop the last integer from the array ('@' -> 27 -> 229).
b27b e# Convert the remaining array from base 229 to base 27.
'`f+ e# Add the character '`' to the resulting digits.
e# This pushes the string from the "Idea" section.
'`/ e# Split the result at backticks.
{ e# For each resulting chunk C:
_2> e# Copy C and remove its first to characters.
'q/ e# Split at occurrences of 'q'.
32a e# Push [32].
f.^ e# Mapped, vectorized XOR; XOR the first character of each chunk
e# with 32. This changes its case.
' * e# Join the resulting chunks, separating by spaces.
o e# Print.
2< e# Reduce the original C to its first two characters.
eu e# Convert to uppercase.
p e# Print, enclosed in double quotes, and followed by a linefeed.
}/ e#
-
\$\begingroup\$ So how does this work? How are the capitals generated without being coded in? \$\endgroup\$user31556– user315562015年10月14日 06:09:48 +00:00Commented Oct 14, 2015 at 6:09
-
\$\begingroup\$ @MathiasFoster I've updated my answer. \$\endgroup\$Dennis– Dennis2015年10月14日 06:16:23 +00:00Commented Oct 14, 2015 at 6:16
Perl, 605 bytes - 20% = 484
$_="baton rouge,laindianapolis,incolumbus,ohmontgomery,alhelena,mtdenver,coboise,idaustin,txboston,maalbany,nytallahassee,flsanta fe,nmnashville,tntrenton,njjefferson,morichmond,vapierre,sdharrisburg,paaugusta,meprovidence,ridover,deconcord,nhmontpelier,vthartford,cttopeka,kssaint paul,mnjuneau,aklincoln,neraleigh,ncmadison,wiolympia,waphoenix,azlansing,mihonolulu,hijackson,msspringfield,ilcolumbia,scannapolis,mdcheyenne,wysalt lake city,utatlanta,gabismarck,ndfrankfort,kysalem,orlittle rock,ardes moines,iasacramento,caoklahoma city,okcharleston,wvcarson city,nv";s/,../uc"$&;"/eg;s/\b./\u$&/g;print
My first version was invalid because it used \U to convert to uppercase. This one uses \u on each letter of the state abbreviation. I also had to add a dummy capture group to avoid using 1ドル.
Edit: I was able to shave off 8 bytes by using uc() with the e flag. (Thank you Dom Hastings.)
javascript, (削除) 727 (削除ここまで) 687 bytes - 20% = 549.6
alert('baton rouge;indianapolis;columbus;montgomery;helena;denver;boise;austin;boston;albany;tallahassee;santa fe;nashville;trenton;jefferson;richmond;pierre;harrisburg;augusta;providence;dover;concord;montpelier;hartford;topeka;saint paul;juneau;lincoln;raleigh;madison;olympia;phoenix;lansing;honolulu;jackson;springfield;columbia;annapolis;cheyenne;salt lake city;atlanta;bismarck;frankfort;salem;little rock;des moines;sacramento;oklahoma city;charleston;carson city'.split`;`.map((a,i)=>a.split` `.map(b=>b[0][u='to\x55pper\x43ase']()+b.slice(-~0)).join` `+0+'lainohalmtcoidtxmanyflnmtnnjmovasdpameridenhvtctksmnaknencwiwaazmihimsilscmdwyutgandkyorariacaokwvnv'[u]().substr(i*2,2)))
javascript is particularly tough as well, considering their long function names and camelcase. splitting out the states saved a ton on delimiters, and made it easier to work with all around.
@mbomb007 nothing in the post capitalized for a reason ;)
C, (削除) 703 (削除ここまで) 700 bytes - 20% = 560 bytes
main(){int c=!0;char*p="@baton@rouge[la*indianapolis[in*columbus[oh*montgomery[al*helena[mt*denver[co*boise[id*austin[tx*boston[ma*albany[ny*tallahassee[fl*santa@fe[nm*nashville[tn*trenton[nj*jefferson[mo*richmond[va*pierre[sd*harrisburg[pa*augusta[me*providence[ri*dover[de*concord[nh*montpelier[vt*hartford[ct*topeka[ks*saint@paul[mn*juneau[ak*lincoln[ne*raleigh[nc*madison[wi*olympia[wa*phoenix[az*lansing[mi*honolulu[hi*jackson[ms*springfield[il*columbia[sc*annapolis[md*cheyenne[wy*salt@lake@city[ut*atlanta[ga*bismarck[nd*frankfort[ky*salem[or*little@rock[ar*des@moines[ia*sacramento[ca*oklahoma@city[ok*charleston[wv*carson@city[nv*";while(*++p)c+=*p<97?2+*p/91:0,printf("%c",c?--c,*p-32:*p);}
I changed the loop a bit to make it compile with non-C99 compilers. Online version
-
\$\begingroup\$ Finally, the comma operator is useful. \$\endgroup\$user46060– user460602015年10月13日 18:54:48 +00:00Commented Oct 13, 2015 at 18:54
javascript (es6) 516 (645-20%) (削除) 532 (664-20%) (削除ここまで)
test running the snippet below in any recent browser: the only es6 feature used is template strings
alert(`
labaton rouge
inindianapolis
ohcolumbus
almontgomery
mthelena
codenver
idboise
txaustin
maboston
nyalbany
fltallahassee
nmsanta fe
tnnashville
njtrenton
mojefferson
varichmond
sdpierre
paharrisburg
meaugusta
riprovidence
dedover
nhconcord
vtmontpelier
cthartford
kstopeka
mnsaint paul
akjuneau
nelincoln
ncraleigh
wimadison
waolympia
azphoenix
milansing
hihonolulu
msjackson
ilspringfield
sccolumbia
mdannapolis
wycheyenne
utsalt lake city
gaatlanta
ndbismarck
kyfrankfort
orsalem
arlittle rock
iades moines
casacramento
okoklahoma city
wvcharleston
nvcarson city
`.replace(/(\n..)(.)| ./g,(w,x,y)=>(y?x+','+y:w)['to\x55pper\x43ase']()))
-
\$\begingroup\$ very clever! hadn't thought of replace for whatever reason... \$\endgroup\$Mwr247– Mwr2472015年10月14日 13:09:48 +00:00Commented Oct 14, 2015 at 13:09
Funciton, 5045 − 20% = 4036 bytes
This code contains only one number, and it’s not in the range 65 through 90. Nor is it the number 1. In fact, this number is 4187 decimal digits, which cleanly factorizes into primes ×ばつ53.
As always, get nicer rendering by executing $('pre').css('line-height',1); in your browser console.
╔═══════════════════════════════════════════════════════════════════════════════╗
║7136715096855386138244201921379984522081157959387689102965666099527710666770872║
║8632405046019650473694855863386057142772501332293800147289916078651647760772443║
║8725652766505885348060772769789231580343563435533130895917300237406562638030980║
║3711194146648873765244744781953334585902685570475123886704870369061449702689564║
║3595572359214492754563209811697465519112054922140302657793458997381684588970868║
║7793823212145990790477442216616349142872430200820970858787998435483524660584416║
║6164882066597488329789212167115912389108306700132767580336075847661452995278441║
║4608506136620095732142590833871485553260077395557115141102093496100483811080395║
║6552804273104384398276311006450509670233242612250087379855689038722276735360412║
║6878753848057526563710344191563893599886868947829201220173418232286377514939888║
║5826479634935379423693839085984565815131964110239432620200938530722481854602826║
║9037704900171802579729347376622932167603510862768435434759967894116610786905139║
║7412487476129828359043674372610945304257752777678880166233522176263310236004692║
║0559345181857154078616512980811741354072155133642234106705715867670036797456411║
║3264775046807948785891163930492821367841190494057926544207551600789781134233199║
║4931373746463823081063091455500394879663289567724955802959562627212816895887920║
║2489552640528826478935177736926106383314641517898028085103843993947923512080284║
║1297634633899484758145253947029431905171166312060063580822580997396575916969283║
║8159188436765390151074141915725490631912068692580040188837785831216953037087556║
║0321645257600479747768084542577912902995339088536912361110657756023624089620615║
║5158613866208649015722071421838484405731207470388752536584022013701916919845375║
║3209922919010373613440766178725948038885270419846274466164969481905438092706837║
║6125745847739006120558864887675350117798119205719776692338137137532239709753293║
║8995102505657504327982204450387974737246780507128822708181598416111438056330283║
║4785530759635414792062372089201435348108257958259667891277855066169836153935818║
║4849044313927545256942990267263122642672090579649898429311837755460330426123991║
║0865666851722460685754104973378688314066186075716326618952555696686125861179585╟
║7767008528632788251800639156553539356488180142086268151130154661765322967918167║
║6359863162328432204277806522752416226370770476079674225817370337594249020946663║
║1822184578010876426310754786368155838502939742370374540683825491575130213369657║
║2120804668997619419445916101731942338784683470192383635854329364775377151471990║
║2655205750667024595911951526939478313795716952326483704217123605616832952264503║
║8356212760984291960912048067411637475389334580447270650407546381067041317195274║
║3658815060537830411410963930585836537141345277217896786840243174681916988181583║
║8390084258839955570465021603546831767108002881554379542200508579678822598563892║
║8621176190864640015677903257299296220003472794175916462345690686103548377723578║
║6760505049046712538526435515066511975271300115330547105472335029933058732991785║
║5589232894601143279598099962031945524489480851133384138840761826907713777131329║
║9653475711559777326388996740771947433446060772704682592783253818915955015393899║
║8513366910314301930539317844646403762279062435716757707854074235922915355490960║
║9007713445763282900095169953058848056683723033266818136479787173846475991012202║
║9462375527766882809250645176534521094942659081258046722219759280486004661723805║
║6786432900677055552677470564184679327084173152258835307889916896828977570843423║
║3265510347632679682249919679555731735198061941806081777484490821424077128775482║
║4866960679621740266038712499696089430677992126743925060145440886995190894304525║
║3469457565680576996559817327023534136403178656947913819462072799063875416015296║
║0646268276069839972076911667210841845209380552353634062961962574981823297845248║
║7817510295701815725710777747052257272070773995280590130309991890195320939352205║
║3629070121725848802522009518874134452415909082137665653417182020188245139223466║
║1804690429428088774753298257855093982064922470661344462996583642233273038068537║
║5899655675409028134860922908216970845189239846431322757349357911553610461726138║
║9065104191927373357937390905721074233359257891159853454407258925428691711525208║
║0898360915775189300266760522953739009955921695946386500512104598494398514200642║
╚═══════════════════════════════════════════════════════════════════════════════╝
Edit: Kiri-ban! This answer is codegolf.SE post #61000!
-
1\$\begingroup\$ Uncaught TypeError: $(...).css is not a function(...) \$\endgroup\$anna328p– anna328p2016年08月08日 19:13:52 +00:00Commented Aug 8, 2016 at 19:13
x86 machine code, 764 bytes
612 if bonus awarded
Totally self-contained program. Only relies upon (a) Bios int 0x10 being available to print each char and (b) DS, ES, SP and SS being initialized before program is called, DOS does this.(and DOS-Box too) Otherwise, the code relies on nothing. The absolute minimum without any dependencies at all except for the BIOS rom, would be about 2 floppy disk sectors @512 bytes each.
It doesn't seem to exploit any of the standard loop-holes, though while some bytes of the program are 01, these are not numbers in the source. However, since I'd like to submit the binary code as my solution, I imagine that would disallow the 01 bytes.?
Hex-editor view of binary:
68 98 01 E8 1D 00 CD 20 B3 62 FE CB 88 DF 80 C7 19 38 D8 72 0D 38 F8 77 09 30 DB FE C3 C0 E3 05 - h ̃.è..Í 3bþˈ߀Ç.8Ør.8øw.0ÛþÃÀã.
28 D8 C3 55 89 E5 81 C5 04 00 8B 76 00 89 F7 AC A8 FF 74 3E 80 3E 96 01 00 75 0A E8 CA FF AA A2 - (ØÃU‰å.Å..‹v.‰÷¬ ̈ÿt>€>–..u.èÊÿa¢
96 01 E9 EA FF 3C 2C 75 18 AA AC E8 BA FF AA AC E8 B5 FF AA AC AA AC E8 AE FF AA A2 96 01 E9 CE - –.éêÿ<,u.a¬èoÿa¬èμÿa¬a¬è®ÿa¢–.éÎ
FF 80 3E 96 01 20 75 03 E8 9D FF AA A2 96 01 E9 BD FF 8B 76 00 AC A8 FF 74 1A 3C 2D 75 0F B0 0D - ÿ€>–. u.è.ÿa¢–.é1⁄2ÿ‹v.¬ ̈ÿt.<-u.°.
B4 0E CD 10 B0 0A B4 0E CD 10 E9 E8 FF B4 0E CD 10 E9 E1 FF 5D C3 00 00 62 61 74 6F 6E 72 6F 75 - ́.Í.°. ́.Í.éèÿ ́.Í.éáÿ]Ã..batonrou
67 65 2C 6C 61 2D 69 6E 64 69 61 6E 61 70 6F 6C 69 73 2C 69 6E 2D 63 6F 6C 75 6D 62 75 73 2C 6F - ge,la-indianapolis,in-columbus,o
68 2D 6D 6F 6E 74 67 6F 6D 65 72 79 2C 61 6C 2D 68 65 6C 65 6E 61 2C 6D 74 2D 64 65 6E 76 65 72 - h-montgomery,al-helena,mt-denver
2C 63 6F 2D 62 6F 69 73 65 2C 69 64 2D 61 75 73 74 69 6E 2C 74 78 2D 62 6F 73 74 6F 6E 2C 6D 61 - ,co-boise,id-austin,tx-boston,ma
2D 61 6C 62 61 6E 79 2C 6E 79 2D 74 61 6C 6C 61 68 61 73 73 65 65 2C 66 6C 2D 73 61 6E 74 61 66 - -albany,ny-tallahassee,fl-santaf
65 2C 6E 6D 2D 6E 61 73 68 76 69 6C 6C 65 2C 74 6E 2D 74 72 65 6E 74 6F 6E 2C 6E 6A 2D 6A 65 66 - e,nm-nashville,tn-trenton,nj-jef
66 65 72 73 6F 6E 2C 6D 6F 2D 72 69 63 68 6D 6F 6E 64 2C 76 61 2D 70 69 65 72 72 65 2C 73 64 2D - ferson,mo-richmond,va-pierre,sd-
68 61 72 72 69 73 62 75 72 67 2C 70 61 2D 61 75 67 75 73 74 61 2C 6D 65 2D 70 72 6F 76 69 64 65 - harrisburg,pa-augusta,me-provide
6E 63 65 2C 72 69 2D 64 6F 76 65 72 2C 64 65 2D 63 6F 6E 63 6F 72 64 2C 6E 68 2D 6D 6F 6E 74 70 - nce,ri-dover,de-concord,nh-montp
65 6C 69 65 72 2C 76 74 2D 68 61 72 74 66 6F 72 64 2C 63 74 2D 74 6F 70 65 6B 61 2C 6B 73 2D 73 - elier,vt-hartford,ct-topeka,ks-s
61 69 6E 74 20 70 61 75 6C 2C 6D 6E 2D 6A 75 6E 65 61 75 2C 61 6B 2D 6C 69 6E 63 6F 6C 6E 2C 6E - aint paul,mn-juneau,ak-lincoln,n
65 2D 72 61 6C 65 69 67 68 2C 6E 63 2D 6D 61 64 69 73 6F 6E 2C 77 69 2D 6F 6C 79 6D 70 69 61 2C - e-raleigh,nc-madison,wi-olympia,
77 61 2D 70 68 6F 65 6E 69 78 2C 61 7A 2D 6C 61 6E 73 69 6E 67 2C 6D 69 2D 68 6F 6E 6F 6C 75 6C - wa-phoenix,az-lansing,mi-honolul
75 2C 68 69 2D 6A 61 63 6B 73 6F 6E 2C 6D 73 2D 73 70 72 69 6E 67 66 69 65 6C 64 2C 69 6C 2D 63 - u,hi-jackson,ms-springfield,il-c
6F 6C 75 6D 62 69 61 2C 73 63 2D 61 6E 6E 61 70 6F 6C 69 73 2C 6D 64 2D 63 68 65 79 65 6E 6E 65 - olumbia,sc-annapolis,md-cheyenne
2C 77 79 2D 73 61 6C 74 20 6C 61 6B 65 20 63 69 74 79 2C 75 74 2D 61 74 6C 61 6E 74 61 2C 67 61 - ,wy-salt lake city,ut-atlanta,ga
2D 62 69 73 6D 61 72 63 6B 2C 6E 64 2D 66 72 61 6E 6B 66 6F 72 74 2C 6B 79 2D 73 61 6C 65 6D 2C - -bismarck,nd-frankfort,ky-salem,
6F 72 2D 6C 69 74 74 6C 65 20 72 6F 63 6B 2C 61 72 2D 64 65 73 20 6D 6F 69 6E 65 73 2C 69 61 2D - or-little rock,ar-des moines,ia-
73 61 63 72 61 6D 65 6E 74 6F 2C 63 61 2D 6F 6B 6C 61 68 6F 6D 61 20 63 69 74 79 2C 6F 6B 2D 63 - sacramento,ca-oklahoma city,ok-c
68 61 72 6C 65 73 74 6F 6E 2C 77 76 2D 63 61 72 73 6F 6E 20 63 69 74 79 2C 6E 76 00 - harleston,wv-carson city,nv.
'Un-golfed' version (source - 3126 bytes)
[section .text]
[bits 16]
[org 0x100]
entry_point:
push word capital_list
call output_string
int 0x20
; input:
; al = char
; outpt:
; if al if an alpha char, ensures it is in range [capital-a .. capital-z]
toupper:
mov bl, 98
dec bl ; bl = 'a'
mov bh, bl
add bh, 25 ; bh = 'z'
cmp al, bl ;'a'
jb .toupperdone
cmp al, bh
ja .toupperdone
xor bl, bl
inc bl
shl bl, 5 ; bl = 32
sub al, bl ;capital'a' - 'a' (32)
.toupperdone:
ret
;void outputstring(char *str)
outputstring:
push bp
mov bp, sp
add bp, 4
mov si, [bp + 0] ; si --> string
mov di, si
; I run over the text in two passes - because I'm too tired right now to make it
; a tighter, more efficient loop. Perhaps after some sleep.
; In the first pass, I just convert the appropriate chars to upper-case
.get_char_pass_1:
lodsb
test al, 0xff
jz .pass_1_done
cmp [last_char], byte 0
jne .not_first_char
call toupper
stosb
mov [last_char], al
jmp .get_char_pass_1
.not_first_char:
.check_if_sep:
cmp al, ',' ; if this char is a comma, the next 2 need to be uppercase
jne .not_seperator
stosb ; spit out the comma, unchanged
lodsb
call toupper
stosb
lodsb
call toupper
stosb
.gobble_delim:
lodsb ; take care of the '-' delimiter
stosb
.capitalize_first_letter_of_city:
lodsb ; the following char is the first char of the city, capitalize it
call toupper
stosb
mov [last_char], al
jmp .get_char_pass_1 ; go back for more
.not_seperator:
cmp [last_char], byte ' '
jne .output_this_char
call toupper
.output_this_char:
stosb
mov [last_char], al
jmp .get_char_pass_1
.pass_1_done:
; In the second pass, I print the characters, except for the delimiters, which are skipped and
; instead print a CRLF pair so that each city/state pair begins on a new line.
;
pass_2:
mov si, [bp+0] ; point to string again
.pass_2_load_char:
lodsb
test al, 0xff
jz .pass_2_done
cmp al, '-' ; current char is a delimiter, dont print it - instead,
; print a carriage-return/line-feed pair
jne .not_delim_2
mov al, 0xd ; LF
mov ah, 0xe
int 0x10
mov al, 0xa ; CR
mov ah, 0xe
int 0x10
jmp .pass_2_load_char
.not_delim_2:
mov ah, 0xe
int 0x10
jmp .pass_2_load_char
.pass_2_done:
pop bp
ret
last_char db 0
[section .data]
capital_list db 'batonrouge,la-indianapolis,in-columbus,oh-montgomery,al-helena,mt-denver,co-boise,id-'
db 'austin,tx-boston,ma-albany,ny-tallahassee,fl-santafe,nm-nashville,tn-trenton,nj-'
db 'jefferson,mo-richmond,va-pierre,sd-harrisburg,pa-augusta,me-providence,ri-dover,de-'
db 'concord,nh-montpelier,vt-hartford,ct-topeka,ks-saint paul,mn-juneau,ak-lincoln,ne-'
db 'raleigh,nc-madison,wi-olympia,wa-phoenix,az-lansing,mi-honolulu,hi-jackson,ms-'
db 'springfield,il-columbia,sc-annapolis,md-cheyenne,wy-salt lake city,ut-atlanta,ga-'
db 'bismarck,nd-frankfort,ky-salem,or-little rock,ar-des moines,ia-sacramento,ca-'
db 'oklahoma city,ok-charleston,wv-carson city,nv',0
Output:
Baton Rouge,LA
Indianapolis,IN
Columbus,OH
Montgomery,AL
Helena,MT
Denver,CO
Boise,ID
Austin,TX
Boston,MA
Albany,NY
Tallahassee,FL
Santa Fe,NM
Nashville,TN
Trenton,NJ
Jefferson,MO
Richmond,VA
Pierre,SD
Harrisburg,PA
Augusta,ME
Providence,RI
Dover,DE
Concord,NH
Montpelier,VT
Hartford,CT
Topeka,KS
Saint Paul,MN
Juneau,AK
Lincoln,NE
Raleigh,NC
Madison,WI
Olympia,WA
Phoenix,AZ
Lansing,MI
Honolulu,HI
Jackson,MS
Springfield,IL
Columbia,SC
Annapolis,MD
Cheyenne,WY
Salt Lake City,UT
Atlanta,GA
Bismarck,ND
Frankfort,KY
Salem,OR
Little Rock,AR
Des Moines,IA
Sacramento,CA
Oklahoma City,OK
Charleston,WV
Carson City,NV
Python 3, (削除) 1416 (削除ここまで) (削除) 793 (削除ここまで) (削除) 785 (削除ここまで) (削除) 779 (削除ここまで) (削除) 771 (削除ここまで) (削除) 755 (削除ここまで) 734 characters - 20% = 587.2
No algorithmic cleverness here, I just took the required output, sorted it (this lets zlib do a better job), compressed it (using zopfli --deflate), base64-encoded the result, and then changed the encoding around to avoid capital letters.
import zlib,base64;print(zlib.decompress(base64.b64decode('>_"@sq*w%>yf^+?!|#-#rii*hezbdf9()#_&m&",s;bb74@n7_93,t>d09rek;+~<l1":+>sr!m~qgv?0[,)z;?>$|p5.i)hegtak<&:db9hg9(xat3yp%x_(j}m]<j7^d?-2$g]5.l:-:g/{da?ow+ykpu}..8g)9"b+h7/[p]ex%x#rp!7u0w3*66|/%:{idbsh|$v/&0^9l!?v8hn-m8%"l^7wx]%_k>h1k(xh~1))h/<x0wdr7")7024.f6~qb;<;5ドル{tby$>_nid-d!x+,pl0zt[yj5bv"/<+^,$ti>}]3q!gd6>:h/sw}<#x>-lj5#h@w:i01d?m^ks2|,v"^coy^p.l{l{6jxbs,a??m14/h0%/m3j-q_zm@;uu[rgx<(4{{s,en/":1oc|!]fvpsjt$}9z?b&#^;58%@m78i8wf<*u",mizg7;3.3*l7o{0,._oyz0&y5d#afpgc38_-ww_7jx;xd;,:ooaj<u;i5~y]^%u]{.},@_|h[,8^>zt54ohq@y,aw2|20s)$k"|dso*<ra](%%jm<+&upl%[)y/?+{[|<jr8!w=='.translate({ord(x):y+60+5 for x,y in zip('!"#$%&()*,-.:;<>?@[]^_{|}~',range(26))})),-9).decode('u8'))
Un-golfed:
import zlib, base64
DATA = '>_"@sq*w%>yf^+?!|#-#rii*hezbdf9()#_&m&",s;bb74@n7_93,t>d09rek;+~<l1":+>sr!m~qgv?0[,)z;?>$|p5.i)hegtak<&:db9hg9(xat3yp%x_(j}m]<j7^d?-2$g]5.l:-:g/{da?ow+ykpu}..8g)9"b+h7/[p]ex%x#rp!7u0w3*66|/%:{idbsh|$v/&0^9l!?v8hn-m8%"l^7wx]%_k>h1k(xh~1))h/<x0wdr7")7024.f6~qb;<;5ドル{tby$>_nid-d!x+,pl0zt[yj5bv"/<+^,$ti>}]3q!gd6>:h/sw}<#x>-lj5#h@w:i01d?m^ks2|,v"^coy^p.l{l{6jxbs,a??m14/h0%/m3j-q_zm@;uu[rgx<(4{{s,en/":1oc|!]fvpsjt$}9z?b&#^;58%@m78i8wf<*u",mizg7;3.3*l7o{0,._oyz0&y5d#afpgc38_-ww_7jx;xd;,:ooaj<u;i5~y]^%u]{.},@_|h[,8^>zt54ohq@y,aw2|20s)$k"|dso*<ra](%%jm<+&upl%[)y/?+{[|<jr8!w=='
TR = { ord(x) : y+60+5
for x,y in zip('!"#$%&()*,-.:;<>?@[]^_{|}~', range(26)) }
print(zlib.decompress(base64.b64decode(DATA.translate(TR)),
-9)
.decode('utf-8'))
There is probably more to be squeezed out of this, especially if you can express the argument to translate() more compactly. Note that the punctuation in there is carefully chosen to avoid base64's own punctuation (+/=) and anything that would need backwhacking in a string literal.
Fun fact: the bz2 and lzma modules both do worse on this input than zlib:
>>> z = base64.b64decode('>_"@sq*w%>yf^+?!|#-#rii*hezbdf9()#_&m&",s;bb74@n7_93,t>d09rek;+~<l1":+>sr!m~qgv?0[,)z;?>$|p5.i)hegtak<&:db9hg9(xat3yp%x_(j}m]<j7^d?-2$g]5.l:-:g/{da?ow+ykpu}..8g)9"b+h7/[p]ex%x#rp!7u0w3*66|/%:{idbsh|$v/&0^9l!?v8hn-m8%"l^7wx]%_k>h1k(xh~1))h/<x0wdr7")7024.f6~qb;<;5ドル{tby$>_nid-d!x+,pl0zt[yj5bv"/<+^,$ti>}]3q!gd6>:h/sw}<#x>-lj5#h@w:i01d?m^ks2|,v"^coy^p.l{l{6jxbs,a??m14/h0%/m3j-q_zm@;uu[rgx<(4{{s,en/":1oc|!]fvpsjt$}9z?b&#^;58%@m78i8wf<*u",mizg7;3.3*l7o{0,._oyz0&y5d#afpgc38_-ww_7jx;xd;,:ooaj<u;i5~y]^%u]{.},@_|h[,8^>zt54ohq@y,aw2|20s)$k"|dso*<ra](%%jm<+&upl%[)y/?+{[|<jr8!w=='.translate({ord(x):ord(y)-32 for x,y in zip('!"#$%&()*,-.:;<>?@[]^_{|}~','abcdefghijklmnopqrstuvwxyz')}))
>>> u = zlib.decompress(x,-9)
>>> len(u)
663
>>> len(z)
427
>>> len(zlib.compress(z))
437
>>> len(bz2.compress(z))
456
>>> len(lzma.compress(z))
620
-
1\$\begingroup\$ At least it's nice and readable. ;-) \$\endgroup\$AdmBorkBork– AdmBorkBork2015年10月13日 19:01:03 +00:00Commented Oct 13, 2015 at 19:01
-
\$\begingroup\$ You can remove the
import zlib,base6at the beginning and doDATA.translate(tr).decode('base64').decode('zlib').decode('utf-8')Why do you need thatdecode('utf-8')at all? \$\endgroup\$The Fifth Marshal– The Fifth Marshal2015年11月20日 02:13:22 +00:00Commented Nov 20, 2015 at 2:13 -
\$\begingroup\$ @ppperry Sadly, your suggestion only works in Python 2; and in Python 2,
.translateworks differently and{ x:y for x,y in ... }is not available. Without the.decode('u8'), in Python 3, the output is the repr() of the byte string, which is far enough off from the requested output that I didn't think it should count. \$\endgroup\$zwol– zwol2015年11月20日 13:18:20 +00:00Commented Nov 20, 2015 at 13:18
Pyth, (631 -20%) = 504.8
=k!kmrd=k-6kc"baton rouge,la,indianapolis,in,columbus,oh,montgomery,al,helena,mt,denver,co,boise,id,austin,tx,boston,ma,albany,ny,tallahassee,fl,santa fe,nm,nashville,tn,trenton,nj,jefferson,mo,richmond,va,pierre,sd,harrisburg,pa,augusta,me,providence,ri,dover,de,concord,nh,montpelier,vt,hartford,ct,topeka,ks,saint paul,mn,juneau,ak,lincoln,ne,raleigh,nc,madison,wi,olympia,wa,phoenix,az,lansing,mi,honolulu,hi,jackson,ms,springfield,il,columbia,sc,annapolis,md,cheyenne,wy,salt lake city,ut,atlanta,ga,bismarck,nd,frankfort,ky,salem,or,little rock,ar,des moines,ia,sacramento,ca,oklahoma city,ok,charleston,wv,carson city,nv"","
Output:
['Baton Rouge', 'LA', 'Indianapolis', 'IN', 'Columbus', 'OH', 'Montgomery', 'AL', 'Helena', 'MT', 'Denver', 'CO', 'Boise', 'ID', 'Austin', 'TX', 'Boston', 'MA', 'Albany', 'NY', 'Tallahassee', 'FL', 'Santa Fe', 'NM', 'Nashville', 'TN', 'Trenton', 'NJ', 'Jefferson', 'MO', 'Richmond', 'VA', 'Pierre', 'SD', 'Harrisburg', 'PA', 'Augusta', 'ME', 'Providence', 'RI', 'Dover', 'DE', 'Concord', 'NH', 'Montpelier', 'VT', 'Hartford', 'CT', 'Topeka', 'KS', 'Saint Paul', 'MN', 'Juneau', 'AK', 'Lincoln', 'NE', 'Raleigh', 'NC', 'Madison', 'WI', 'Olympia', 'WA', 'Phoenix', 'AZ', 'Lansing', 'MI', 'Honolulu', 'HI', 'Jackson', 'MS', 'Springfield', 'IL', 'Columbia', 'SC', 'Annapolis', 'MD', 'Cheyenne', 'WY', 'Salt Lake City', 'UT', 'Atlanta', 'GA', 'Bismarck', 'ND', 'Frankfort', 'KY', 'Salem', 'OR', 'Little Rock', 'AR', 'Des Moines', 'IA', 'Sacramento', 'CA', 'Oklahoma City', 'OK', 'Charleston', 'WV', 'Carson City', 'NV']
The second parameter for r alternates between 5 (capwords()) and 1 (upper())
-
\$\begingroup\$ Oops, bad variable name. Luckily, they can be changed to lower case
k\$\endgroup\$Fabian Schmengler– Fabian Schmengler2015年10月13日 20:46:12 +00:00Commented Oct 13, 2015 at 20:46
PowerShell, (削除) 1038 (削除ここまで) (削除) 976 (削除ここまで) (削除) 925 (削除ここまで) (削除) 904 (削除ここまで) (削除) 813 (削除ここまで) (削除) 768 (削除ここまで) (削除) 758 (削除ここまで) (削除) 749 (削除ここまで) 745 -20% = 596
"labaton rouge;inindianapolis;ohcolumbus;almontgomery;mthelena;codenver;idboise;txaustin;maboston;nyalbany;fltallahassee;nmsanta fe;tnnashville;njtrenton;mojefferson;varichmond;sdpierre;paharrisburg;meaugusta;riprovidence;dedover;nhconcord;vtmontpelier;cthartford;kstopeka;mnsaint paul;akjuneau;nelincoln;ncraleigh;wimadison;waolympia;azphoenix;milansing;hihonolulu;msjackson;ilspringfield;sccolumbia;mdannapolis;wycheyenne;utsalt lake city;gaatlanta;ndbismarck;kyfrankfort;orsalem;arlittle rock;iades moines;casacramento;okoklahoma city;wvcharleston;nvcarson city"-split";"|%{$a=-split$_;$b={$n,$i=$args;if($a[$n]){" "+(""+$a[$n][$i++]).toupper()+$a[$n].substring($i)}};$(&$b(0)2).trim()+$(&$b(3-2)0)+$(&$b(2)0)+","+$_.substring(0,2).toupper()}
Ungolfed:
"labaton rouge;inindianapolis;ohcolumbus;almontgomery;mthelena;codenver;idboise;txaustin;maboston;nyalbany;fltallahassee;nmsanta fe;tnnashville;njtrenton;mojefferson;varichmond;sdpierre;paharrisburg;meaugusta;riprovidence;dedover;nhconcord;vtmontpelier;cthartford;kstopeka;mnsaint paul;akjuneau;nelincoln;ncraleigh;wimadison;waolympia;azphoenix;milansing;hihonolulu;msjackson;ilspringfield;sccolumbia;mdannapolis;wycheyenne;utsalt lake city;gaatlanta;ndbismarck;kyfrankfort;orsalem;arlittle rock;iades moines;casacramento;okoklahoma city;wvcharleston;nvcarson city"-split";"|%{
$a=-split$_;
$b={
$n,$i=$args;
if($a[$n]){
" "+
(""+$a[$n][$i++]).toupper()+
$a[$n].substring($i)
}
};
$(&$b(0)2).trim()+
$(&$b(3-2)0)+
$(&$b(2)0)+
","+
$_.substring(0,2).toupper()
}
-
\$\begingroup\$ @TessellatingHeckler Thanks, but I can't use a literal 1 without losing the bonus. And also, thanks for the earlier suggestions that enabled the 749 599.2 entry. \$\endgroup\$Bevo– Bevo2016年08月09日 22:42:10 +00:00Commented Aug 9, 2016 at 22:42
-
\$\begingroup\$ @TessellatingHeckler I did use your idea to use $_ on that last segment of the string - thanks! \$\endgroup\$Bevo– Bevo2016年08月10日 14:14:49 +00:00Commented Aug 10, 2016 at 14:14
Minkolang 0.7, (削除) 660 (削除ここまで) (削除) 705 (削除ここまで) 708 * 0.8 = 566.4
99*32-+58*0p467+35*44*55*d8+d5+(99*2-23-r32-p)"baton rouge, laindianapolis, incolumbus, ohmontgomery, alhelena, mtdenver, coboise, idaustin, txboston, maalbany, nytallahassee, flsanta fe, nmnashville, tntrenton, njjefferson, morichmond, vapierre, sdharrisburg, paaugusta, meprovidence, ridover, deconcord, nhmontpelier, vthartford, cttopeka, kssaint paul, mnjuneau, aklincoln, neraleigh, ncmadison, wiolympia, waphoenix, azlansing, mihonolulu, hijackson, msspringfield, ilcolumbia, scannapolis, mdcheyenne, wysalt lake city, utatlanta, gabismarck, ndfrankfort, kysalem, orlittle rock, ardes moines, iasacramento, caoklahoma city, okcharleston, wvcarson city, nv"032-w
48*-o(d","=2&o)oo22$[48*-o]d?.25*o48*-o)
Thanks to Sp3000 for reminding me that I can use p to put capital Os in the code!
Explanation
The bit of the first line before the " does nothing but put a R (rotate stack) in place of r and then replace all of the instances of o with O on the second line.
After that, it's the list of capitals without newlines and all letters lowercased, which is pushed onto the stack in reverse order by Minkolang. There is a 01w at the end which is a "wormhole" to the beginning of the second line. All capital letters are outputted by subtracting 32 from the lowercase letter, which is why 48*- shows up four times.
48*-O outputs B, then ( begins a while loop. The top of stack is checked against ,. If it's not ,, then O) outputs the character and jumps back to the beginning of the loop. If the top of stack is ,, then the program counter jumps over O) because of 2&, a conditional trampoline that jumps two spaces.
Now, I jump when I encounter a , because I know the next six characters are , AB\nC, which is what the rest of the loop does. There is a check to see if the stack is empty in the middle (after AB is printed, before \nC): d?. If it is, then the conditional trampoline is not taken and the program exits upon hitting the .. Otherwise, it's skipped and the loop continues.
PHP 520 bytes (650 bytes - 20%)
foreach(explode(',','baton rouge,indianapolis,columbus,montgomery,helena,denver,boise,austin,boston,albany,tallahassee,santa fe,nashville,trenton,jefferson,richmond,pierre,harrisburg,augusta,providence,dover,concord,montpelier,hartford,topeka,saint paul,juneau,lincoln,raleigh,madison,olympia,phoenix,lansing,honolulu,jackson,springfield,columbia,annapolis,cheyenne,salt lake city,atlanta,bismarck,frankfort,salem,little rock,des moines,sacramento,oklahoma city,charleston,carson city')as$k=>$v)echo ucwords($v).','.strtoupper(substr('lainohalmtcoidtxmanyflnmtnnjmovasdpameridenhvtctksmnaknencwiwaazmihimsilscmdwyutgandkyorariacaokwvnv',$k*2,2)).'_';
Result
Baton Rouge,LA_Indianapolis,IN_ ...
Ungolfed:
$cities = 'baton rouge,indianapolis,columbus,montgomery,helena,denver,boise,austin,boston,albany,tallahassee,santa fe,nashville,trenton,jefferson,richmond,pierre,harrisburg,augusta,providence,dover,concord,montpelier,hartford,topeka,saint paul,juneau,lincoln,raleigh,madison,olympia,phoenix,lansing,honolulu,jackson,springfield,columbia,annapolis,cheyenne,salt lake city,atlanta,bismarck,frankfort,salem,little rock,des moines,sacramento,oklahoma city,charleston,carson city';
$states = 'lainohalmtcoidtxmanyflnmtnnjmovasdpameridenhvtctksmnaknencwiwaazmihimsilscmdwyutgandkyorariacaokwvnv';
foreach(explode(',',$cities) as $k => $v)
echo ucwords($v)
. ','
. strtoupper(
substr($states, $k * 2, 2)
)
. '_';
I tried various ways to compress the string, but in the end all solutions were longer than this straight forward approach.
Python 2, 658 bytes * 0.8 = 526.4
print zip([c.title()for c in"baton rouge.indianapolis.columbus.montgomery.helena.denver.boise.austin.boston.albany.tallahassee.santa fe.nashville.trenton.jefferson.richmond.pierre.harrisburg.augusta.providence.dover.concord.montpelier.hartford.topeka.saint paul.juneau.lincoln.raleigh.madison.olympia.phoenix.lansing.honolulu.jackson.springfield.columbia.annapolis.cheyenne.salt lake city.atlanta.bismarck.frankfurt.salem.little rock.des moines.sacramento.oklahoma city.charleston.carson city".split('.')],[s.upper()for s in map(''.join,zip(*[iter("lainohalmtcoidtxmanyflnmtnnjmovasdpameridenhvtctksmnaknencwiwaazmihimsilscmdwyutgandkyorariacaokwvnv")]*2))])
Prints the result as a Python list of Python tuples. They are also enclosed in quotes. This definitely qualifies for the bonus since the only number in the code is 2.
Output:
[('Baton Rouge', 'LA'), ('Indianapolis', 'IN'), ('Columbus', 'OH'), ('Montgomery', 'AL'), ('Helena', 'MT'), ('Denver', 'CO'), ('Boise', 'ID'), ('Austin', 'TX'), ('Boston', 'MA'), ('Albany', 'NY'), ('Tallahassee', 'FL'), ('Santa Fe', 'NM'), ('Nashville', 'TN'), ('Trenton', 'NJ'), ('Jefferson', 'MO'), ('Richmond', 'VA'), ('Pierre', 'SD'), ('Harrisburg', 'PA'), ('Augusta', 'ME'), ('Providence', 'RI'), ('Dover', 'DE'), ('Concord', 'NH'), ('Montpelier', 'VT'), ('Hartford', 'CT'), ('Topeka', 'KS'), ('Saint Paul', 'MN'), ('Juneau', 'AK'), ('Lincoln', 'NE'), ('Raleigh', 'NC'), ('Madison', 'WI'), ('Olympia', 'WA'), ('Phoenix', 'AZ'), ('Lansing', 'MI'), ('Honolulu', 'HI'), ('Jackson', 'MS'), ('Springfield', 'IL'), ('Columbia', 'SC'), ('Annapolis', 'MD'), ('Cheyenne', 'WY'), ('Salt Lake City', 'UT'), ('Atlanta', 'GA'), ('Bismarck', 'ND'), ('Frankfurt', 'KY'), ('Salem', 'OR'), ('Little Rock', 'AR'), ('Des Moines', 'IA'), ('Sacramento', 'CA'), ('Oklahoma City', 'OK'), ('Charleston', 'WV'), ('Carson City', 'NV')]
I hope this is within the acceptable bounds of formatting.
Groovy, (削除) 724 (削除ここまで) 681 - 20% = 545 bytes
c={it.capitalize()}
'labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfort,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city'.split(',').each{it.substring(2).split(' ').each{print c(it) + ' '}println c(it[0])+c(it[3-2])}
Inspired by Edc65's clever smushing together of state and city name!
-
\$\begingroup\$ Sorry about that. The code should now qualify for the bonus. I guess I should have read the bonus section more closely. \$\endgroup\$K. Klassen– K. Klassen2015年11月24日 15:23:05 +00:00Commented Nov 24, 2015 at 15:23
PowerShell, 627 -20% = 502 bytes
[regex]::replace('baton rougela;indianapolisin;columbusoh;montgomeryal;helenamt;denverco;boiseid;austintx;bostonma;albanyny;tallahasseefl;santa fenm;nashvilletn;trentonnj;jeffersonmo;richmondva;pierresd;harrisburgpa;augustame;providenceri;doverde;concordnh;montpeliervt;hartfordct;topekaks;saint paulmn;juneauak;lincolnne;raleighnc;madisonwi;olympiawa;phoenixaz;lansingmi;honoluluhi;jacksonms;springfieldil;columbiasc;annapolismd;cheyennewy;salt lake cityut;atlantaga;bismarcknd;frankfortky;salemor;little rockar;des moinesia;sacramentoca;oklahoma cityok;charlestonwv;carson citynv;','\b\w|..;',{"$args,"[3]+"$args".toupper()})
Which is this pattern:
[regex]::replace('baton rougela;','\b\w|..;',{"$args,"[3]+"$args".toupper()})
Uppercase the single letter after a word boundary, or the double letters before a colon. The "$args,"[3] selects either the comma in the case of a double letter state code, or overselects and returns null, and adds the state separators, saving ~50 in separators from the code line.
Ruby, (925 * 80%) = 740 bytes
require "zlib";eval "puts \x5alib::inflate('789c35925db2da300c85dfb50a16a04d98044a203f0ca450faa64b44e2892333b6c394dd57e1b66fdfb1251fe98c8dfb2279637d0323424fef6cc42a07931c4922fc61c0ccfd1c15ab8d624c56b0fd056b4a5e56273ff78ca581b58d1385fb88750e6b6f2363b140d422ac0c6414a2966736a9d305b28182e3cfe57551fc6611c6eb0d32efe6e9cb129eb37f3c476c76ca72f7a1c37a0739cb8b03668d525c55de0a472c0ce47e39ce37b00d24e3c38784871bec28041bbfe6d0e3d12c2a3d9677b21676ec58742b252f6ae566dc15504867e97f0e450d7bba8f7159e20c7b7e3c387c4403fb59986634072849a2951eab024aab533ac17aa39892630d48333127a8a8b34be7b580ca4beafdc4e18da6fca8273baba35f5aa8290e2feb1c635b43333a1afc44dfb1350768dc7b7a6a365703c7c1b3d83f687ec3517b03e3398763f02fdbb1dc194f059cc8b1ed07ac3338d9fb3079e9f062e04cf740134bf2982dca4a5a1d697658d5aa1c4fd89c1648ab9246fef6fed9ea89fe86d596b1aee0fc0cbaf0c3b2ebb028a125a783528cccb855e99f3c121eced086c546e3d8c35f3dcecbfd'.scan(/.{2}/).map {|i|i.hex.chr}.join)"
Oof, this one was hard. This is a Zlib compressed string in hex encoded bytes, which is then decompressed, turned into an array of strings by the scan regex, then each string is converted to a decimal integer, then to a character, and finally this array is joined into a string. I might post a better version later that uses a modified base64 encoding.
Though the encoded string may have some instances of 65-90 or 1's, I don't count those because the string is one huge number in hexadecimal. Thus this qualifies for the 20% bonus.
Python 2, 639 bytes - 20% = 511.2
t="labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfurt,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city".split(",");print[(t[n][:2].upper(),t[n][2:].title())for n in range(50)]
The version bellow (675 bytes) has ''.join([w.capitalize()for w in t[n][2:].split()]) in it, which I just discovered can be replace by .title(), and is an anonymous function. In both answers, the state abbreviations are attached to the capitals.
lambda t="labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfurt,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city".split(","):[(t[n][:2].upper(),''.join([w.capitalize()for w in t[n][2:].split()]))for n in range(50)]
x86 machine-code - 585 bytes, 468 with bonus
Dissapointed with how large my last entry was, I decided to try something very different this time. Drawing on insertusernamehere's idea of separating the city names from the state names, thus avoiding unnecessary logic and unneeded terminators, I still thought I've gotta be able to make the program smaller than the raw strings are. UPX wouldn't help me to cheat, complaining that the program was already too small. Thinking about compression, I tried to compress the 662 byte text output with WinRar but still only got 543 bytes - and that was without anything to decompress it with. It still seemed far too large, given that it was just the result, without any code.
Then I realized - I'm only using 26 chars for the letters and another 2 for the spaces and the commas. Hmm, that fits into 32, which needs just 5 bits. So, I wrote a quick javascript program to encode the strings, assigning a-z to 0-25 and space and comma got 26 and 27. To keep things simple, every character is encoded in 5 bits, whether it needs this many or not. From there, I just stuck all the bits together and broke them back into byte-sized chunks. This allowed me to pack the 563 bytes of strings into 353 bytes - a saving of 37.5% or some 210 bytes. I didn't quite manage to squeeze the program and data into the same space as just the unpacked data, but I came close enough to be happy.
Hxd view of binary:
68 3F 00 68 E8 01 68 4F 03 E8 1C 00 68 22 01 68 27 02 68 B3 03 E8 10 00 - h?.hè.hO.è..h".h'.h3.è..
BE 83 05 C6 04 00 68 4F 03 68 B3 03 E8 62 00 C3 55 89 E5 81 C5 04 00 8B - 3⁄4ƒ.Æ..hO.h3.èb.ÃU‰å.Å..‹
76 02 8B 7E 00 B6 05 30 DB AC B2 08 D0 D0 D0 D3 FE CA FE CE 75 1E 80 FB - v.‹~.¶.0Û¬2.ÐÐÐÓþÊþÎu.€û
1A 75 05 B3 20 E9 0D 00 80 FB 1B 75 05 B3 2C E9 03 00 80 C3 61 88 1D 47 - .u.3 é..€û.u.3,é..€Ãaˆ.G
B6 05 30 DB 08 D2 75 D4 FF 4E 04 75 CC 5D C2 06 00 53 B3 62 FE CB 88 DF - ¶.0Û.ÒuÔÿN.uÌ]Â..S3bþˈß
80 C7 19 38 D8 72 08 38 F8 77 04 B3 20 28 D8 5B C3 55 89 E5 81 C5 04 00 - €Ç.8Ør.8øw.3 (Ø[ÃU‰å.Å..
8B 76 00 31 C0 88 C2 89 C1 AC A8 FF 74 46 80 FA 20 74 35 08 D2 74 31 3C - ‹v.1ÀˆÂ‰Á¬ ̈ÿtF€ú t5.Òt1<
2C 75 30 B4 0E CD 10 89 CB 01 DB 03 5E 02 8A 07 E8 B6 FF CD 10 43 8A 07 - ,u0 ́.Í.‰Ë.Û.^.Š.è¶ÿÍ.CŠ.
E8 AE FF CD 10 B0 0D CD 10 B0 0A CD 10 C6 06 4C 03 00 30 D2 41 E9 C1 FF - è®ÿÍ.°.Í.°.Í.Æ.L..0ÒAéÁÿ
E8 96 FF B4 0E CD 10 88 C2 E9 B5 FF 5D C2 04 00 58 10 D7 1C 0B 64 C4 E4 - è–ÿ ×ばつ..dÄä
0E 77 60 1B 82 AD AC 9B 5A 96 3A A0 90 DE 06 12 28 19 1A 7A CC 53 54 98 - .w`.‚.¬›Z–: .Þ..(..zÌST ̃
D0 29 A4 68 AC 8B 00 19 62 0E 86 49 0B 90 98 3B 62 93 30 1A 35 61 D1 04 - Ð)¤h¬‹..b.†I.. ̃;b"0.5aÑ.
50 01 01 CA B5 5B 50 08 26 E6 EA 2E A1 89 B4 34 68 03 40 F7 2D 12 D8 9C - P..Êμ[P.&æê.¡‰ ́4h.@÷-.Øœ
BA 30 34 96 D8 E6 CC CE 61 23 8D 9C 8B 23 41 B1 91 B5 24 76 17 22 44 D8 - o04–ØæÌÎa#.œ‹#A±‘μ$v."DØ
29 29 A1 BB 0B A5 37 37 60 58 40 DC 6E 60 5A C0 70 4A 44 26 E4 06 CC 1A - ))¡».77円`X@Ün`ZÀpJD&ä.Ì.
29 36 D0 48 F5 42 D6 4D CE 24 6C DC DD A4 85 29 23 27 37 71 40 8E C7 34 - )6ÐHõBÖMÎ$lÜݤ...)#'7q@ŽÇ4
7B 7A 09 18 93 67 04 62 89 06 91 36 C1 43 52 53 06 DF 17 55 03 23 44 4D - {z.."g.b‰.‘6ÁCRS.ß.U.#DM
8D D5 24 76 27 34 4E 88 F6 C7 36 6F 22 D0 48 EC E0 8C CA E8 8F 73 73 C8 - .Õ$v'4NˆöÇ6o"ÐHìàŒÊè.ssÈ
A0 6E 40 43 67 A7 82 8B DA 68 D2 02 9B 5A 1A 27 2D BB 88 16 44 18 FB 60 - n@Cg§‚‹ÚhÒ.›Z.'-»ˆ.D.û`
06 89 39 BB 72 F0 C7 A0 1B 79 DC 46 A2 FB 58 1B 24 34 DB 3B 9A E5 D1 74 - .‰9»rðÇ .yÜF¢ûX.4ドルÛ;šåÑt
DA 40 25 49 CD DC 9F 14 34 C5 41 16 3D 89 CB A3 02 80 6C 0D 68 1E E5 A2 - Ú@%IÍÜŸ.4ÅA.=‰Ë£.€l.h.å¢
5B 11 C9 82 35 A4 DC 80 B9 E9 60 51 34 24 4F 1B 04 D6 06 CC 1B 0A 24 C0 - [.É‚5¤Ü1ドルé`Q4$O..Ö.Ì..$À
44 4A D9 62 06 A8 AE 8C F7 20 2C 8C DA D1 39 AC 9A 8B 84 AD 8C 92 D3 1C - DJÙb. ̈®Œ÷ ,ŒÚÑ9¬š‹„.Œ’Ó.
86 92 5B 90 05 10 30 8D 9B B6 E5 2C 07 73 01 A1 22 78 D8 8E 08 AC 92 9B - †’[...0.›¶å,.s.¡"xØŽ.¬’›
9B B1 02 32 73 74 24 4F 1B - ›±.2st$O.
Source-code:
[section .text]
[bits 16]
[org 0x100]
entry_point:
push word 63 ; no of bytes of packed data = (5/8) * unpacked_length - rounded up tp nearest byte
push word states_packed
push word states_unpacked
call unpack_bytes
push word 290 ; no bytes of packed data
push word capitals_packed
push word capitals_unpacked
call unpack_bytes
; ensure there's a terminating null after the capitals
mov si, nullTerminator
mov [si], byte 0
;void outputStrings(char *cities, char *states)
push word states_unpacked
push word capitals_unpacked
call output_strings
; int 0x20
ret
;void unpack_states(char *unpackedDest, char *packedInput, int packed_length)
;unpack_capitals:
unpack_bytes:
push bp
mov bp, sp
add bp, 4
mov si, [bp + 2] ; point to the packed input
mov di, [bp + 0] ; point to the output buffer
mov dh, 5 ; number of bits remaining until we have a full output byte, ready to be translated from [0..25] --> [A..Z] (+65) or 26-->' ' or 27-->','
xor bl, bl ; clear our output accumalator
.unpack_get_byte:
lodsb
mov dl, 8 ; number of bits remaining in this packed byte before we need another one
.unpack_get_next_bit:
rcl al, 1 ; put most significant bit into carry flag
rcl bl, 1 ; and put it into the least significant bit of our accumalator
dec dl ; 1 bit less before we need another packed byte
dec dh ; 1 bit less until this output byte is done
jnz .checkInputBitsRemaining
.transform_output_byte:
cmp bl, 26 ; space is encoded as 26
jne .notSpace
mov bl, ' '
jmp .store_output_byte
.notSpace:
cmp bl, 27 ; comma is encoded as 27
jne .notComma
mov bl, ','
jmp .store_output_byte
.notComma:
.alphaChar:
add bl, 'a' ; change from [0..25] to [A..Z]
.store_output_byte:
mov [di], bl ; store it
inc di ; point to the next output element
mov dh, 5 ; and reset the count of bits till we get here again
xor bl, bl
.checkInputBitsRemaining:
or dl,dl ; see if we've emptied the packed byte yet
jnz .unpack_get_next_bit
dec word [bp + 4] ; decrement the number of bytes of input remaining to be processed
jnz .unpack_get_byte ; if we still have some, go back for more
.unpack_input_processed:
pop bp
ret 6
; input:
; al = char
; outpt:
; if al if an alpha char, ensures it is in range [capital-a .. capital-z]
toupper:
push bx
mov bl, 98
dec bl ; bl = 'a'
mov bh, bl
add bh, 25 ; bh = 'z'
cmp al, bl ;'a'
jb .toupperdone
cmp al, bh
ja .toupperdone
mov bl, 32
sub al, bl ;'A' - 'a'
.toupperdone:
pop bx
ret
;void outputStrings(char *cities, char *states)
output_strings:
push bp
mov bp, sp
add bp, 4
mov si, [bp + 0] ; si --> array of cities
xor ax, ax
; mov [lastChar], al ; last printed char is undefined at this point - we'll use this to know if we're processing the first entry
mov dl, al
; mov [string_index], ax ; zero the string_index too
mov cx, ax ; zero the string_index too
.getOutputChar:
lodsb
test al, 0xff
jz .outputDone ; if we've got a NULL, it's the string terminator so exit
; cmp byte [lastChar], ' ' ; if the last char was a space, we have to capitalize this one
cmp dl, ' ' ; if the last char was a space, we have to capitalize this one
je .make_ucase
; cmp byte [lastChar], 0
or dl, dl ; if this is 0, then it's the first char we've printed, therefore we know it should be capitalized
jz .make_ucase
cmp al, ',' ; if this is a comma, the city is done, so print the comma then do the state and a crlf, finally, increment the string_index
jne .printChar
mov ah, 0xe ; code for print-char, teletype output
int 0x10 ; print the char held in al
; mov bx, [string_index]
mov bx, cx;[string_index]
add bx,bx ; x2 since each state is 2 bytes long
add bx, [bp+2] ; bx --> states_unpacked[string_index]
mov al, [bx] ; get the first char of the state
call toupper ; upper case it
; mov ah, 0xe ;not needed, still set from above
int 0x10 ; and print it
inc bx
mov al, [bx] ; get the 2nd char of the state
call toupper ; uppercase it
; mov ah, 0xe ;not needed, still set from above
int 0x10 ; and print it
mov al, 0x0d ; print a CRLF
int 0x10
mov al, 0x0a
int 0x10
mov byte [lastChar], 0 ; zero this, so that the first letter of the new city will be capitalized, just like the first char in the string was
xor dl, dl ; zero this, so that the first letter of the new city will be capitalized, just like the first char in the string was
; inc word [string_index] ; increment our index, ready for the next city's state
inc cx ;word [string_index] ; increment our index, ready for the next city's state
jmp .getOutputChar ; go back and get the next char of the next city
.make_ucase:
call toupper
.printChar:
mov ah, 0xe
int 0x10
; mov [lastChar], al
mov dl, al
jmp .getOutputChar ; go back and get the next char of the next city
.outputDone:
pop bp
ret 4 ; return and clean-up the two vars from the stack
[section .data]
; 63 packed bytes, 100 unpacked (saved 37)
states_packed:
db 01011000b, 00010000b, 11010111b, 00011100b, 00001011b, 01100100b, 11000100b, 11100100b
db 00001110b, 01110111b, 01100000b, 00011011b, 10000010b, 10101101b, 10101100b, 10011011b
db 01011010b, 10010110b, 00111010b, 10100000b, 10010000b, 11011110b, 00000110b, 00010010b
db 00101000b, 00011001b, 00011010b, 01111010b, 11001100b, 01010011b, 01010100b, 10011000b
db 11010000b, 00101001b, 10100100b, 01101000b, 10101100b, 10001011b, 00000000b, 00011001b
db 01100010b, 00001110b, 10000110b, 01001001b, 00001011b, 10010000b, 10011000b, 00111011b
db 01100010b, 10010011b, 00110000b, 00011010b, 00110101b, 01100001b, 11010001b, 00000100b
db 01010000b, 00000001b, 00000001b, 11001010b, 10110101b, 01011011b, 01010000b
; 290 packed bytes, 463 unpacked (saved 173)
capitals_packed:
db 00001000b, 00100110b, 11100110b, 11101010b, 00101110b, 10100001b, 10001001b, 10110100b, 00110100b, 01101000b, 00000011b, 01000000b, 11110111b, 00101101b
db 00010010b, 11011000b, 10011100b, 10111010b, 00110000b, 00110100b, 10010110b, 11011000b, 11100110b, 11001100b, 11001110b, 01100001b, 00100011b, 10001101b
db 10011100b, 10001011b, 00100011b, 01000001b, 10110001b, 10010001b, 10110101b, 00100100b, 01110110b, 00010111b, 00100010b, 01000100b, 11011000b, 00101001b
db 00101001b, 10100001b, 10111011b, 00001011b, 10100101b, 00110111b, 00110111b, 01100000b, 01011000b, 01000000b, 11011100b, 01101110b, 01100000b, 01011010b
db 11000000b, 01110000b, 01001010b, 01000100b, 00100110b, 11100100b, 00000110b, 11001100b, 00011010b, 00101001b, 00110110b, 11010000b, 01001000b, 11110101b
db 01000010b, 11010110b, 01001101b, 11001110b, 00100100b, 01101100b, 11011100b, 11011101b, 10100100b, 10000101b, 00101001b, 00100011b, 00100111b, 00110111b
db 01110001b, 01000000b, 10001110b, 11000111b, 00110100b, 01111011b, 01111010b, 00001001b, 00011000b, 10010011b, 01100111b, 00000100b, 01100010b, 10001001b
db 00000110b, 10010001b, 00110110b, 11000001b, 01000011b, 01010010b, 01010011b, 00000110b, 11011111b, 00010111b, 01010101b, 00000011b, 00100011b, 01000100b
db 01001101b, 10001101b, 11010101b, 00100100b, 01110110b, 00100111b, 00110100b, 01001110b, 10001000b, 11110110b, 11000111b, 00110110b, 01101111b, 00100010b
db 11010000b, 01001000b, 11101100b, 11100000b, 10001100b, 11001010b, 11101000b, 10001111b, 01110011b, 01110011b, 11001000b, 10100000b, 01101110b, 01000000b
db 01000011b, 01100111b, 10100111b, 10000010b, 10001011b, 11011010b, 01101000b, 11010010b, 00000010b, 10011011b, 01011010b, 00011010b, 00100111b, 00101101b
db 10111011b, 10001000b, 00010110b, 01000100b, 00011000b, 11111011b, 01100000b, 00000110b, 10001001b, 00111001b, 10111011b, 01110010b, 11110000b, 11000111b
db 10100000b, 00011011b, 01111001b, 11011100b, 01000110b, 10100010b, 11111011b, 01011000b, 00011011b, 00100100b, 00110100b, 11011011b, 00111011b, 10011010b
db 11100101b, 11010001b, 01110100b, 11011010b, 01000000b, 00100101b, 01001001b, 11001101b, 11011100b, 10011111b, 00010100b, 00110100b, 11000101b, 01000001b
db 00010110b, 00111101b, 10001001b, 11001011b, 10100011b, 00000010b, 10000000b, 01101100b, 00001101b, 01101000b, 00011110b, 11100101b, 10100010b, 01011011b
db 00010001b, 11001001b, 10000010b, 00110101b, 10100100b, 11011100b, 10000000b, 10111001b, 11101001b, 01100000b, 01010001b, 00110100b, 00100100b, 01001111b
db 00011011b, 00000100b, 11010110b, 00000110b, 11001100b, 00011011b, 00001010b, 00100100b, 11000000b, 01000100b, 01001010b, 11011001b, 01100010b, 00000110b
db 10101000b, 10101110b, 10001100b, 11110111b, 00100000b, 00101100b, 10001100b, 11011010b, 11010001b, 00111001b, 10101100b, 10011010b, 10001011b, 10000100b
db 10101101b, 10001100b, 10010010b, 11010011b, 00011100b, 10000110b, 10010010b, 01011011b, 10010000b, 00000101b, 00010000b, 00110000b, 10001101b, 10011011b
db 10110110b, 11100101b, 00101100b, 00000111b, 01110011b, 00000001b, 10100001b, 00100010b, 01111000b, 11011000b, 10001110b, 00001000b, 10101100b, 10010010b
db 10011011b, 10011011b, 10110001b, 00000010b, 00110010b, 01110011b, 01110100b, 00100100b, 01001111b, 00011011b
[section .bss]
lastChar resb 1 ; last printed char - used to capitalize chars after a space (i.e the 2nd or third word of a city name)
string_index resw 1 ; used to index into the array of states, which are each two bytes
states_unpacked resb 100 ; 50 states, 2 bytes each
capitals_unpacked resb 464
nullTerminator resb 1
-
2\$\begingroup\$ I see a lot of uppercase chars in your dump. \$\endgroup\$edc65– edc652015年10月17日 02:18:55 +00:00Commented Oct 17, 2015 at 2:18
-
\$\begingroup\$ Ugggh. Of course, so do I now that I look. I was so obsessed with generating them I've overlooked the fact I've inadvertently created some. The first 232 bytes is code the rest data. I see I've got caps in each. I may just have sunk myself, with no chance of fixing it. :( I'll investigate some self-modifying code later, though the offset table I'll need may consume any gains made. :sighs: - oh well.Thanks for pointing it out though,I appreciate it. \$\endgroup\$enhzflep– enhzflep2015年10月17日 02:54:01 +00:00Commented Oct 17, 2015 at 2:54
Explore related questions
See similar questions with these tags.
alert(...)is traditionally the JS equivalent of STDOUT. \$\endgroup\$