• OK, it's on.
  • Please note that many, many Email Addresses used for spam, are not accepted at registration. Select a respectable Free email.
  • Done now. Domine miserere nobis.

Learning programming languages

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
i decided i wanna learn a bunch of new programming languages and get a feel for how the various ones work.

i made small problem to try them on. It's simple but it contains a couple of aspects of practical interest: a bit of data i/o (reading JSON lines), data processing, and some basic calculation.

the program, if implemented correctly, will print the Mona Lisa:

Code:
          ____
        o8%8888,  
      o88%8888888.
     8'-    -:8888b 
    8'         8888
   d8.-=. ,==-.:888b
   >8 `~` :`~' d8888 
   88         ,88888 
   88b. `-~  ':88888
   888b ~==~ .:88888
   88888o--:':::8888    
   `88888| :::' 8888b
   8888^^'       8888b
  d888           ,%888b. 
 d88%            %%%8--'-.
/88:.__ ,       _%-' ---  -
    '''::===..-'   =  --.

the program needs to do the following:
1. take a command-line argument with a path to the text file containing the JSON lines (provided below in the spoiler).
2. read the file
3. for each line, calculate the value x = vf * vi
4. sort the entire data by x
5. the "mona" field is an integer representing a UTF8 character. Convert it to UTF8 and print everything in the sorted order.

at least for me, the goal here is to solve it without relying on any non-builtin libraries (libraries come and go, language stays more or less the same).

feel free to join in and provide your own solutions

JSONL data:
Code:
{"vf":0.63305535982,"vi":43,"mona":32}
{"vf":0.85782771534,"vi":40,"mona":32}
{"vf":0.39544885908,"vi":7,"mona":98}
{"vf":0.686375082,"vi":40,"mona":32}
{"vf":0.26752143214,"vi":39,"mona":56}
{"vf":0.8819775593,"vi":23,"mona":32}
{"vf":0.4566147353,"vi":45,"mona":32}
{"vf":0.40683259326,"vi":10,"mona":56}
{"vf":0.41764677968,"vi":46,"mona":44}
{"vf":0.94772694004,"vi":12,"mona":32}
{"vf":0.37223806023,"vi":37,"mona":56}
{"vf":0.06492829998,"vi":13,"mona":32}
{"vf":0.49752726709,"vi":31,"mona":94}
{"vf":0.11940477998,"vi":35,"mona":45}
{"vf":0.18769111927,"vi":18,"mona":32}
{"vf":0.75845953752,"vi":20,"mona":56}
{"vf":0.18529644189,"vi":24,"mona":45}
{"vf":0.87104341364,"vi":2,"mona":56}
{"vf":0.70650190115,"vi":17,"mona":10}
{"vf":0.97134245024,"vi":4,"mona":10}
{"vf":0.28252833011,"vi":25,"mona":56}
{"vf":0.46596245025,"vi":17,"mona":32}
{"vf":0.2249853292,"vi":1,"mona":32}
{"vf":0.69000710151,"vi":30,"mona":100}
{"vf":0.59414202045,"vi":32,"mona":32}
{"vf":0.59304565168,"vi":3,"mona":56}
{"vf":0.88953931606,"vi":35,"mona":32}
{"vf":0.1110964613,"vi":48,"mona":58}
{"vf":0.30878683273,"vi":38,"mona":32}
{"vf":0.55143501447,"vi":39,"mona":32}
{"vf":0.45245839423,"vi":43,"mona":37}
{"vf":0.25296492851,"vi":48,"mona":32}
{"vf":0.40439918102,"vi":26,"mona":111}
{"vf":0.19337867992,"vi":15,"mona":32}
{"vf":0.64881812432,"vi":33,"mona":37}
{"vf":0.91399544966,"vi":5,"mona":58}
{"vf":0.71327900072,"vi":6,"mona":46}
{"vf":0.22507335083,"vi":39,"mona":56}
{"vf":0.37270939443,"vi":10,"mona":56}
{"vf":0.61277100327,"vi":6,"mona":32}
{"vf":0.06072057155,"vi":32,"mona":32}
{"vf":0.21625478962,"vi":3,"mona":95}
{"vf":0.055301926332,"vi":7,"mona":32}
{"vf":0.79434232111,"vi":16,"mona":124}
{"vf":0.24361947272,"vi":19,"mona":56}
{"vf":0.78229430132,"vi":17,"mona":58}
{"vf":0.16307032923,"vi":18,"mona":32}
{"vf":0.1007215823,"vi":7,"mona":32}
{"vf":0.77906588279,"vi":12,"mona":98}
{"vf":0.56025326368,"vi":16,"mona":10}
{"vf":0.22011888516,"vi":12,"mona":56}
{"vf":0.69280340616,"vi":30,"mona":56}
{"vf":0.98214037367,"vi":27,"mona":58}
{"vf":0.41068977653,"vi":26,"mona":39}
{"vf":0.65983844968,"vi":41,"mona":44}
{"vf":0.96235893643,"vi":36,"mona":32}
{"vf":0.93731408915,"vi":2,"mona":56}
{"vf":0.73779740301,"vi":1,"mona":32}
{"vf":0.23909995565,"vi":47,"mona":56}
{"vf":0.38790902984,"vi":37,"mona":32}
{"vf":0.7533078643,"vi":13,"mona":56}
{"vf":0.73518430581,"vi":8,"mona":32}
{"vf":0.27054487239,"vi":35,"mona":61}
{"vf":0.11791384127,"vi":10,"mona":56}
{"vf":0.69737376622,"vi":26,"mona":32}
{"vf":0.31244816491,"vi":47,"mona":32}
{"vf":0.14711364731,"vi":38,"mona":56}
{"vf":0.54682615655,"vi":32,"mona":32}
{"vf":0.32334499317,"vi":8,"mona":58}
{"vf":0.052843942773,"vi":35,"mona":56}
{"vf":0.70829032222,"vi":28,"mona":56}
{"vf":0.4348927415,"vi":48,"mona":56}
{"vf":0.61801787326,"vi":10,"mona":32}
{"vf":0.67418684252,"vi":38,"mona":10}
{"vf":0.26085685706,"vi":46,"mona":32}
{"vf":0.042059533531,"vi":17,"mona":10}
{"vf":0.40451028175,"vi":4,"mona":32}
{"vf":0.41274611861,"vi":2,"mona":32}
{"vf":0.054629109101,"vi":20,"mona":37}
{"vf":0.14280002238,"vi":20,"mona":32}
{"vf":0.88044056878,"vi":45,"mona":45}
{"vf":0.047663627425,"vi":30,"mona":32}
{"vf":0.31982061709,"vi":28,"mona":32}
{"vf":0.18384952401,"vi":47,"mona":56}
{"vf":0.35398610262,"vi":8,"mona":32}
{"vf":0.48316766927,"vi":41,"mona":56}
{"vf":0.70853046817,"vi":3,"mona":32}
{"vf":0.91568353842,"vi":29,"mona":95}
{"vf":0.24572367803,"vi":16,"mona":32}
{"vf":0.16806081054,"vi":45,"mona":32}
{"vf":0.91443818691,"vi":6,"mona":56}
{"vf":0.33633120591,"vi":41,"mona":56}
{"vf":0.40897692181,"vi":22,"mona":32}
{"vf":0.99940452795,"vi":9,"mona":32}
{"vf":0.72670253902,"vi":15,"mona":58}
{"vf":0.96935641114,"vi":45,"mona":45}
{"vf":0.53767718305,"vi":23,"mona":56}
{"vf":0.88646906079,"vi":44,"mona":46}
{"vf":0.006300783949,"vi":40,"mona":32}
{"vf":0.46647237684,"vi":8,"mona":56}
{"vf":0.14704832458,"vi":37,"mona":32}
{"vf":0.59998895926,"vi":44,"mona":56}
{"vf":0.1422942956,"vi":27,"mona":32}
{"vf":0.95450364915,"vi":30,"mona":32}
{"vf":0.82095132396,"vi":20,"mona":56}
{"vf":0.46466594189,"vi":35,"mona":32}
{"vf":0.76919391123,"vi":29,"mona":32}
{"vf":0.54928465607,"vi":32,"mona":56}
{"vf":0.97187563567,"vi":41,"mona":39}
{"vf":0.89035022212,"vi":50,"mona":45}
{"vf":0.72839442827,"vi":7,"mona":96}
{"vf":0.0082155198324,"vi":49,"mona":32}
{"vf":0.79892484564,"vi":49,"mona":46}
{"vf":0.28915973729,"vi":17,"mona":32}
{"vf":0.89139411715,"vi":10,"mona":56}
{"vf":0.2741666215,"vi":5,"mona":32}
{"vf":0.83405430918,"vi":28,"mona":37}
{"vf":0.8930511144,"vi":36,"mona":32}
{"vf":0.37981653772,"vi":47,"mona":32}
{"vf":0.21048707911,"vi":11,"mona":39}
{"vf":0.40947495261,"vi":24,"mona":32}
{"vf":0.883017404,"vi":44,"mona":61}
{"vf":0.10359964496,"vi":13,"mona":10}
{"vf":0.17217174638,"vi":33,"mona":32}
{"vf":0.58548335312,"vi":30,"mona":56}
{"vf":0.14190690778,"vi":48,"mona":56}
{"vf":0.38999443525,"vi":16,"mona":32}
{"vf":0.57286705822,"vi":38,"mona":32}
{"vf":0.61925648339,"vi":48,"mona":32}
{"vf":0.68078755122,"vi":37,"mona":32}
{"vf":0.1370674714,"vi":42,"mona":32}
{"vf":0.7259830269,"vi":31,"mona":32}
{"vf":0.67437638808,"vi":33,"mona":32}
{"vf":0.21976763126,"vi":46,"mona":32}
{"vf":0.89504535915,"vi":31,"mona":32}
{"vf":0.35544538079,"vi":46,"mona":32}
{"vf":0.97709899629,"vi":10,"mona":56}
{"vf":0.95683334535,"vi":37,"mona":39}
{"vf":0.90229904512,"vi":40,"mona":39}
{"vf":0.17064523511,"vi":11,"mona":56}
{"vf":0.90530958166,"vi":32,"mona":37}
{"vf":0.13880606345,"vi":39,"mona":39}
{"vf":0.47784537985,"vi":22,"mona":56}
{"vf":0.81660588761,"vi":25,"mona":32}
{"vf":0.66231764201,"vi":17,"mona":32}
{"vf":0.89673868264,"vi":11,"mona":32}
{"vf":0.36948886584,"vi":40,"mona":56}
{"vf":0.44980248413,"vi":38,"mona":98}
{"vf":0.51644489425,"vi":45,"mona":32}
{"vf":0.10380668822,"vi":28,"mona":32}
{"vf":0.78819583403,"vi":33,"mona":56}
{"vf":0.24608773435,"vi":21,"mona":96}
{"vf":0.21799066872,"vi":30,"mona":32}
{"vf":0.99123655586,"vi":8,"mona":96}
{"vf":0.36330054351,"vi":15,"mona":100}
{"vf":0.058478488587,"vi":31,"mona":56}
{"vf":0.64998515882,"vi":38,"mona":45}
{"vf":0.83570883702,"vi":17,"mona":32}
{"vf":0.10292468267,"vi":12,"mona":32}
{"vf":0.17505265027,"vi":45,"mona":98}
{"vf":0.072057123994,"vi":14,"mona":32}
{"vf":0.73707773793,"vi":38,"mona":32}
{"vf":0.04555649939,"vi":28,"mona":32}
{"vf":0.26503273146,"vi":28,"mona":32}
{"vf":0.69826159487,"vi":22,"mona":94}
{"vf":0.15234661684,"vi":7,"mona":56}
{"vf":0.98335018079,"vi":41,"mona":32}
{"vf":0.86364411144,"vi":7,"mona":56}
{"vf":0.25721674645,"vi":36,"mona":56}
{"vf":0.31170220207,"vi":49,"mona":56}
{"vf":0.093594986713,"vi":20,"mona":56}
{"vf":0.4025733422,"vi":24,"mona":46}
{"vf":0.66877151746,"vi":47,"mona":32}
{"vf":0.33839128376,"vi":46,"mona":32}
{"vf":0.29589545541,"vi":46,"mona":39}
{"vf":0.40894399793,"vi":40,"mona":32}
{"vf":0.35390457185,"vi":34,"mona":32}
{"vf":0.86810680688,"vi":26,"mona":32}
{"vf":0.96302423254,"vi":42,"mona":32}
{"vf":0.41473533446,"vi":19,"mona":46}
{"vf":0.63013185281,"vi":7,"mona":44}
{"vf":0.98564088438,"vi":47,"mona":46}
{"vf":0.83192756283,"vi":30,"mona":46}
{"vf":0.61835122737,"vi":33,"mona":32}
{"vf":0.38831911515,"vi":25,"mona":56}
{"vf":0.64392291498,"vi":5,"mona":32}
{"vf":0.19281594688,"vi":37,"mona":56}
{"vf":0.62190229516,"vi":4,"mona":32}
{"vf":0.29774178262,"vi":16,"mona":32}
{"vf":0.23162578535,"vi":29,"mona":32}
{"vf":0.23959462903,"vi":24,"mona":10}
{"vf":0.31427078042,"vi":30,"mona":126}
{"vf":0.071904097218,"vi":36,"mona":56}
{"vf":0.54208036722,"vi":50,"mona":32}
{"vf":0.10286464426,"vi":33,"mona":32}
{"vf":0.89241904439,"vi":43,"mona":58}
{"vf":0.13654019707,"vi":5,"mona":95}
{"vf":0.53376487363,"vi":4,"mona":32}
{"vf":0.39522013464,"vi":31,"mona":32}
{"vf":0.010467111832,"vi":39,"mona":32}
{"vf":0.47157627763,"vi":28,"mona":58}
{"vf":0.52810548805,"vi":29,"mona":56}
{"vf":0.42842150875,"vi":44,"mona":32}
{"vf":0.62997305347,"vi":11,"mona":56}
{"vf":0.30772001087,"vi":3,"mona":32}
{"vf":0.2862853487,"vi":34,"mona":56}
{"vf":0.96739837062,"vi":8,"mona":56}
{"vf":0.13069569157,"vi":10,"mona":32}
{"vf":0.26597264037,"vi":18,"mona":10}
{"vf":0.51507180789,"vi":2,"mona":111}
{"vf":0.4398316876,"vi":28,"mona":96}
{"vf":0.31818100763,"vi":20,"mona":32}
{"vf":0.76082362537,"vi":11,"mona":58}
{"vf":0.78457526653,"vi":30,"mona":37}
{"vf":0.86648331466,"vi":3,"mona":56}
{"vf":0.37471395661,"vi":20,"mona":32}
{"vf":0.45333415619,"vi":43,"mona":56}
{"vf":0.23774940497,"vi":48,"mona":32}
{"vf":0.48641176405,"vi":5,"mona":32}
{"vf":0.31186974677,"vi":23,"mona":32}
{"vf":0.81006435305,"vi":50,"mona":32}
{"vf":0.15244474774,"vi":8,"mona":44}
{"vf":0.19774473668,"vi":24,"mona":98}
{"vf":0.11113542435,"vi":15,"mona":56}
{"vf":0.44220007421,"vi":11,"mona":32}
{"vf":0.24644899415,"vi":39,"mona":126}
{"vf":0.67028203956,"vi":14,"mona":32}
{"vf":0.66511519463,"vi":22,"mona":32}
{"vf":0.97982191737,"vi":15,"mona":32}
{"vf":0.32792071928,"vi":12,"mona":32}
{"vf":0.10105849407,"vi":50,"mona":32}
{"vf":0.47779597109,"vi":13,"mona":32}
{"vf":0.65675812797,"vi":28,"mona":32}
{"vf":0.39589268831,"vi":7,"mona":32}
{"vf":0.39715195331,"vi":8,"mona":32}
{"vf":0.41454633581,"vi":30,"mona":56}
{"vf":0.020024300553,"vi":1,"mona":32}
{"vf":0.78830513544,"vi":34,"mona":95}
{"vf":0.33282354032,"vi":8,"mona":56}
{"vf":0.60873498232,"vi":10,"mona":32}
{"vf":0.98421920347,"vi":6,"mona":56}
{"vf":0.56094798376,"vi":2,"mona":56}
{"vf":0.8474531651,"vi":8,"mona":44}
{"vf":0.21689276281,"vi":11,"mona":32}
{"vf":0.27438364457,"vi":16,"mona":32}
{"vf":0.28757752012,"vi":36,"mona":56}
{"vf":0.87468234287,"vi":6,"mona":32}
{"vf":0.96746949432,"vi":12,"mona":32}
{"vf":0.67299909261,"vi":25,"mona":56}
{"vf":0.79883161117,"vi":10,"mona":45}
{"vf":0.58175009978,"vi":40,"mona":37}
{"vf":0.70399206132,"vi":14,"mona":10}
{"vf":0.12189925998,"vi":44,"mona":126}
{"vf":0.59434319404,"vi":49,"mona":39}
{"vf":0.44851634139,"vi":36,"mona":32}
{"vf":0.9860542973,"vi":44,"mona":32}
{"vf":0.23116178205,"vi":46,"mona":58}
{"vf":0.96384333191,"vi":40,"mona":61}
{"vf":0.71018240135,"vi":28,"mona":98}
{"vf":0.78568783426,"vi":10,"mona":56}
{"vf":0.62922113156,"vi":12,"mona":32}
{"vf":0.65570579912,"vi":47,"mona":32}
{"vf":0.8537633738,"vi":44,"mona":58}
{"vf":0.23872602684,"vi":44,"mona":56}
{"vf":0.045831166673,"vi":42,"mona":46}
{"vf":0.033727773,"vi":6,"mona":32}
{"vf":0.05795856053,"vi":9,"mona":32}
{"vf":0.30122889997,"vi":6,"mona":56}
{"vf":0.35188863846,"vi":2,"mona":32}
{"vf":0.81464003888,"vi":5,"mona":46}
{"vf":0.67757063545,"vi":33,"mona":32}
{"vf":0.88024654123,"vi":4,"mona":32}
{"vf":0.091043999884,"vi":42,"mona":56}
{"vf":0.83976776479,"vi":6,"mona":56}
{"vf":0.57630183757,"vi":39,"mona":32}
{"vf":0.64146235399,"vi":11,"mona":56}
{"vf":0.4137243263,"vi":41,"mona":56}
{"vf":0.66805558745,"vi":3,"mona":32}
{"vf":0.45510805096,"vi":7,"mona":32}
{"vf":0.7862815517,"vi":4,"mona":39}
{"vf":0.65310192504,"vi":42,"mona":32}
{"vf":0.95409123856,"vi":27,"mona":47}
{"vf":0.42184495018,"vi":25,"mona":45}
{"vf":0.21640793583,"vi":38,"mona":32}
{"vf":0.09496241319,"vi":25,"mona":32}
{"vf":0.36884545092,"vi":48,"mona":56}
{"vf":0.26501780609,"vi":32,"mona":56}
{"vf":0.48091082997,"vi":15,"mona":32}
{"vf":0.69070527842,"vi":42,"mona":45}
{"vf":0.18382849079,"vi":21,"mona":32}
{"vf":0.80341854203,"vi":37,"mona":45}
{"vf":0.56459043478,"vi":47,"mona":46}
{"vf":0.15663685137,"vi":19,"mona":56}
{"vf":0.5765190213,"vi":38,"mona":32}
{"vf":0.98595416523,"vi":42,"mona":61}
{"vf":0.79546741769,"vi":32,"mona":32}
{"vf":0.51502972725,"vi":34,"mona":32}
{"vf":0.094840660924,"vi":30,"mona":10}
{"vf":0.91885734815,"vi":14,"mona":32}
{"vf":0.34351647226,"vi":24,"mona":39}
{"vf":0.46677904157,"vi":9,"mona":61}
{"vf":0.50281304563,"vi":16,"mona":32}
{"vf":0.08250274579,"vi":20,"mona":32}
{"vf":0.30811955431,"vi":15,"mona":56}
{"vf":0.35179790924,"vi":16,"mona":32}
{"vf":0.64789347933,"vi":24,"mona":39}
{"vf":0.034874804085,"vi":33,"mona":56}
{"vf":0.28823928069,"vi":23,"mona":32}
{"vf":0.43943153624,"vi":22,"mona":58}
{"vf":0.5115054599,"vi":11,"mona":32}
{"vf":0.39658459462,"vi":2,"mona":32}
{"vf":0.92570795584,"vi":17,"mona":32}
{"vf":0.46653270232,"vi":48,"mona":32}
{"vf":0.076691165334,"vi":15,"mona":56}
{"vf":0.9018743895,"vi":1,"mona":32}
{"vf":0.62329754629,"vi":21,"mona":58}
{"vf":0.10541774612,"vi":45,"mona":56}
{"vf":0.4753165741,"vi":50,"mona":56}
{"vf":0.48861303367,"vi":50,"mona":39}
{"vf":0.34280880168,"vi":36,"mona":56}
{"vf":0.91318822303,"vi":20,"mona":32}
{"vf":0.37446277589,"vi":30,"mona":56}
{"vf":0.52113572578,"vi":36,"mona":32}
{"vf":0.94046728429,"vi":41,"mona":61}
{"vf":0.23303409945,"vi":10,"mona":45}
{"vf":0.81238950952,"vi":33,"mona":32}
{"vf":0.65923032421,"vi":49,"mona":10}
{"vf":0.61723526963,"vi":37,"mona":32}
{"vf":0.48290239717,"vi":29,"mona":98}
{"vf":0.35478309751,"vi":4,"mona":32}
{"vf":0.37021479849,"vi":23,"mona":56}
{"vf":0.28221841739,"vi":32,"mona":56}
{"vf":0.20887634857,"vi":24,"mona":32}
{"vf":0.75424740207,"vi":12,"mona":56}
{"vf":0.074384513311,"vi":9,"mona":95}
{"vf":0.52983568585,"vi":17,"mona":32}
{"vf":0.44476800202,"vi":43,"mona":32}
{"vf":0.74656800414,"vi":23,"mona":32}
{"vf":0.41891589691,"vi":23,"mona":32}
{"vf":0.52602966013,"vi":33,"mona":32}
{"vf":0.20653138962,"vi":19,"mona":32}
{"vf":0.22924484033,"vi":49,"mona":56}
{"vf":0.17169849388,"vi":26,"mona":46}
{"vf":0.22588643292,"vi":29,"mona":32}
{"vf":0.12753165024,"vi":13,"mona":111}
{"vf":0.95016697934,"vi":10,"mona":61}
{"vf":0.32148275641,"vi":11,"mona":32}
{"vf":0.26568668685,"vi":8,"mona":32}
{"vf":0.74033436039,"vi":6,"mona":61}
{"vf":0.15288722282,"vi":23,"mona":32}
{"vf":0.22178793466,"vi":45,"mona":32}
{"vf":0.0094299050979,"vi":41,"mona":32}
{"vf":0.40660786629,"vi":44,"mona":32}
{"vf":0.80281227292,"vi":10,"mona":126}
{"vf":0.024613684509,"vi":26,"mona":95}
{"vf":0.75447515864,"vi":49,"mona":39}
{"vf":0.75859316951,"vi":3,"mona":56}
{"vf":0.57193531399,"vi":9,"mona":126}
{"vf":0.39893982466,"vi":36,"mona":10}
{"vf":0.78529167129,"vi":38,"mona":45}
{"vf":0.099041829351,"vi":20,"mona":32}
{"vf":0.96110479371,"vi":45,"mona":32}
{"vf":0.53368794546,"vi":14,"mona":10}
{"vf":0.33931258018,"vi":33,"mona":56}
{"vf":0.22110293782,"vi":18,"mona":100}
{"vf":0.60136572598,"vi":23,"mona":56}
{"vf":0.14709469094,"vi":9,"mona":32}
{"vf":0.70085308747,"vi":34,"mona":45}
{"vf":0.8998249704,"vi":34,"mona":45}
{"vf":0.72059627343,"vi":19,"mona":32}
{"vf":0.73213520553,"vi":19,"mona":56}
{"vf":0.32037324249,"vi":39,"mona":56}
{"vf":0.36409186479,"vi":29,"mona":45}
{"vf":0.53107039887,"vi":33,"mona":100}
{"vf":0.61999331019,"vi":20,"mona":56}
{"vf":0.14381704363,"vi":11,"mona":32}
{"vf":0.48204260552,"vi":50,"mona":45}
{"vf":0.017765811877,"vi":15,"mona":32}
{"vf":0.77033407427,"vi":26,"mona":46}
{"vf":0.54406602471,"vi":18,"mona":56}
{"vf":0.34732463141,"vi":8,"mona":32}
{"vf":0.72455434641,"vi":26,"mona":32}
{"vf":0.72939065192,"vi":8,"mona":32}
{"vf":0.77459154208,"vi":37,"mona":95}
{"vf":0.84272931889,"vi":37,"mona":45}
{"vf":0.49229332875,"vi":39,"mona":32}
{"vf":0.66828464973,"vi":8,"mona":96}
{"vf":0.98495697998,"vi":11,"mona":58}
{"vf":0.64050681377,"vi":25,"mona":32}
{"vf":0.85688542016,"vi":3,"mona":45}
{"vf":0.82180546015,"vi":25,"mona":10}
{"vf":0.0006247733254,"vi":2,"mona":10}
{"vf":0.57263340196,"vi":19,"mona":58}
{"vf":0.99426977662,"vi":50,"mona":10}
{"vf":0.13710608101,"vi":40,"mona":56}
{"vf":0.97785340482,"vi":36,"mona":32}
{"vf":0.9544738275,"vi":5,"mona":32}
{"vf":0.91506376164,"vi":19,"mona":10}
{"vf":0.164211225,"vi":12,"mona":10}
{"vf":0.83525531995,"vi":1,"mona":32}
{"vf":0.15420230082,"vi":36,"mona":56}
{"vf":0.78394647874,"vi":42,"mona":32}
{"vf":0.5849000935,"vi":3,"mona":37}
{"vf":0.48128980049,"vi":35,"mona":56}
{"vf":0.38958711154,"vi":23,"mona":32}
{"vf":0.93529980327,"vi":11,"mona":56}
{"vf":0.29630217538,"vi":15,"mona":61}
{"vf":0.3839696378,"vi":10,"mona":56}
{"vf":0.49256654782,"vi":4,"mona":32}
{"vf":0.50229956326,"vi":10,"mona":62}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Python version to start with (have used Python before but by no means an expert in it)
Code:
import json
import sys

if len(sys.argv) > 1:
    path = sys.argv[1]
else:
    raise ValueError("missing arg")

data = []

with open(path, 'r') as f:
    for l in f:
        d = json.loads(l)
        d["sc"] = d["vi"] * d["vf"]
        data.append(d)

data.sort(key = lambda x: x['sc'], reverse = False)

s = ""
for d in data:
    s += chr(d['mona'])

print(s)
solution greatly aided by the fact that Python has built-in json support, and that Python dictionaries are practically the same as json objects
 

fluffy

Blake Belladonna
Local time
Today 2:04 PM
Joined
Sep 21, 2024
Messages
772
---
After figuring out how the CPU works.

The way I think about things is not really in laungauge.

But more like how the kernel operates.

Classes functions interactions variables folders files

These are all data structures of a kernel.

I never saw how all the code of a laungauge goes together because most of it is implicit and hidden.

There are languages for creating language.

Has to do with monads.

Where in basic

1 x = 0

2 print hello

3 x = x + 1

4 if x = 5 end

5 go to line 2

Which is as data recursion but a process of encapsulation for monads. (In math it's the reverse of a function inside a function k = f(f n) -> k(k n) putting them inside each other)
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Awk version.

one thing's for sure; the beloved unix text-procesing language is specialized for processing csv-type text, not json. Practically no utilities beyond text-manipulation stuff so had to write a sort manually. The hyper-loose dynamic typing where you never really know if you have a number or a string also is quite challenging for numerical operations

the number-parsing can cause some funny situations; what it chooses for decimal separator depends on your locale, so this program doesn't even work outside US unless you set e.g. LC_NUMERIC=POSIX before running it.

verdict: great command-line tool, but it's primarily a command-line tool for a reason

Code:
function swap(arr, i, j){
    tmp = arr[i]
    arr[i] = arr[j]
    arr[j] = tmp
}

function isort(y, x){
    n = length(y)
    for(i = 1; i <= n; i++){
        j = i
    while(j > 1 && y[j-1] > y[j]){
        swap(y, j, j-1)
        swap(x, j, j-1)
        j--
        }
    }
}

BEGIN {FS = ","} {
    gsub(/[{}]/, "")
    gsub(/\"[[:alpha:]]*\"\:/, "")
    xvals[FNR] = ($1 + 0) * ($2 + 0)
    mvals[FNR] = $3
}

END {
    isort(xvals, mvals)
    for(i = 1; i <= length(xvals); i++){
        printf "%c", mvals[i]
    }
}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
did a quick one in C. I know C well but interesting for comparison. Here of course there's no sort available, no regular expressions, no json, no nothing. Yet it's all beautiful.


C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


// assumes this exact order and types in each json
// {"vf":0.63305535982,"vi":43,"mona":32}
void parseline(double* vf, int* vi, int* mo, char* json){

    char* token = strtok(json, ":,");
    int i = 0;
    while(token){
    switch(i){
        case 1: *vf = atof(token); break;
        case 3: *vi = atoi(token); break;
        case 5: *mo = atoi(token); break;
        }
    i++;
        token = strtok(NULL, ":,");
    }
}

size_t linecount(FILE* file){
    fseek(file, 0, SEEK_SET);
    size_t out = 0;
    char c;
    while((c = fgetc(file)) != EOF){
    out += c == '\n';
    }
    fseek(file, 0, SEEK_SET);
    return out;
}


void swapd(double* arr, size_t i, size_t j){
    double tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp;
}

void swapi(int* arr, size_t i, size_t j){
    int tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp;
}


void isort(double* y, int* x, size_t n){
    for(size_t i = 0; i != n; ++i){
        size_t j = i;
    while(j > 0 && y[j-1] > y[j]){
        swapd(y, j, j-1);
        swapi(x, j, j-1);
        j--;
        }
    }
}


int main(int argc, char* argv[]){

    if(argc != 2){
        printf("usage: %s <file_path>\n", argv[0]);
    return 1;
    }

    FILE* file = fopen(argv[1], "r");
    if(!file){
        printf("failed open-file %s\n", argv[1]);
    return 1;
    }

    size_t lc = linecount(file);

    double* x = malloc(lc * sizeof(double));
    int* mo   = malloc(lc * sizeof(int));

    char linebuf[64];
    double vf;
    int vi;
    size_t i = 0;

    while(fgets(linebuf, sizeof(linebuf), file)){
    parseline(&vf, &vi, mo + i, linebuf);
    x[i++] = vi * vf;
    }

    fclose(file);
    isort(x, mo, lc);

    for(size_t i = 0; i != lc; ++i){
        printf("%c", mo[i]);
    }

    free(x); free(mo);
    return 0;
}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
this one is crazy. Wanted to do it in bash and came across this tool "jq". Maybe it's cheating since it's a library. But it was pre-installed on my linux, so... let's called it bash/jq

the crazy part is that it's 1 line of code lol

Bash:
jq -sr '[.[] | {x: (.vf * .vi), mo: .mona}] | sort_by(.x) | .[] | .mo' $1 | awk '{printf "%c", $1}'
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Perl.
really damn nice language. Has everything you need for this problem and super concise syntax.

extremely lenient on type-related bugs, a lot of weird things you can write and it just runs without saying anything. Not necessarily a bad thing - just means such error checks are up to the programmer.

Perl:
use JSON;

my $fh;
if(@ARGV){
    open($fh, '<', $ARGV[0]) or die "read-file err";
} else {
    die "missing arg";
}

my @data;
push @data, decode_json($_) while <$fh>;

for(@data) {
    $_->{x} = $_->{vi} * $_->{vf};
}

@data = sort {$a->{x} <=> $b->{x}} @data;

for(@data){
    print chr($_->{mona});
}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
C++

obvious simplification over the C version on account of builtin dynamic array, std::string, sorting utilities, etc.

string-operations like tokenization is still kinda annoyingly low-level though. No json support.

and, in typical C++ style you're often met with completely incomprehensible compiler errors. For example, if you forget "#include <fstream>", you get
Code:
error: variable ‘std::ifstream file’ has initializer but incomplete type
wtf does that mean? in C this would say very clearly: the type is undefined, you're missing a header. But since C++ allows for a lot of funky-ass stuff with forward-declaration, the problem becomes more ambiguous. That's both the utility and downside of C++; too many options and too much flexibility.


C++:
#include <iostream>
#include <string>
#include <fstream>
#include <regex>

using namespace std;

void parseline(double& vf, int& vi, int& mo, const string& json){

    regex re(":|,");
    sregex_token_iterator it(json.begin(), json.end(), re, -1);
    sregex_token_iterator end;
    int i = 0;
    for(; it != end; ++it){
    switch(i){
        case 1: vf = stof(*it); break;
        case 3: vi = stoi(*it); break;
        case 5: mo = stoi(*it); break;
        }
    i++;
    }
}

struct obs_t {
    double vf;
    int vi;
    int mo;
    double x;
};

int main(int argc, char** argv){

    if(argc != 2){
        printf("usage: %s <file_path>\n", argv[0]);
    return 1;
    }

    ifstream file(argv[1]);
    if(!file){
        printf("failed open-file %s\n", argv[1]);
    return 1;
    }

    std::vector<obs_t> vals;
    string line;

    while(getline(file, line)){
    obs_t o;
    parseline(o.vf, o.vi, o.mo, line);
    o.x = o.vf * o.vi;
    vals.push_back(o);
    }

    sort(vals.begin(), vals.end(), [](const obs_t& a, const obs_t& b){
    return a.x < b.x;
    });

    for(const auto& o : vals){
        cout << static_cast<char>(o.mo);
    }

    return 0;
}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Ruby.

programming in ruby is supposed to be a joyous experience. Gotta admit it didn't disappoint. Reminded me of Perl a bit but with more human-readable syntax

Ruby:
require 'json'

abort("missing arg") unless ARGV[0]

data = []

File.foreach(ARGV[0]) do |line|
  h = JSON.parse(line)
  h["x"] = h["vf"] * h["vi"]
  data << h
end

data = data.sort_by {|o| o["x"]}

data.each {|o| print o["mona"].chr("UTF-8")}
 

ZenRaiden

One atom of me
Local time
Today 9:04 PM
Joined
Jul 27, 2013
Messages
5,430
---
Location
Between concrete walls
I am pivoting towards computer programing myself, but I got stuck at installing java, I have no idea what or how to install the damn thing. Either way I want to learn a lot about computers. I have always been a standard computer user with minor interest in fixing surface level issues, and it hit me that in this day and age I might as well learn something.

Currently I am wondering what languages I want to learn and what literature to read to get grasp of theory.

Unfortunately lately I have felt unmotivated and apathetic and it made me avoid any kind of mental activity.

Currently feel a little more real about it and want to continue.

I always wanted to know C++
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
@ZenRaiden
i generally don't like java namely for the reason you describe - too much hassle to set it up

a little fun fact about all the programs written above is that with the exception of Ruby all languages came pre-installed on a plain Ubuntu Linux installation. If you want to get into programming i highly recommend switching to linux if you are on windows. Unix-based operating systems were created by programmers to do programmering - whereas windows was made for the consumer market for people who don't know anything about computers. That's not a value judgment, it's just that they are very different things and suited for 2 very separate purposes, and windows puts huge constraints on what you can do with your machine

as for learning, i have never been able to read a single page of a programming book in my life, it's boring and unnecessary. My method is: just pick a problem to solve - preferably something more complex than "hello world", then try to figure out how to implement it bit by bit, filling in the gaps of knowledge as you go. Nowadays with LLMs that process is made even more effective
 

ZenRaiden

One atom of me
Local time
Today 9:04 PM
Joined
Jul 27, 2013
Messages
5,430
---
Location
Between concrete walls
a little fun fact about all the programs written above is that with the exception of Ruby all languages came pre-installed on a plain Ubuntu Linux installation. If you want to get into programming i highly recommend switching to linux if you are on windows. Unix-based operating systems were created by programmers to do programmering - whereas windows was made for the consumer market for people who don't know anything about computers. That's not a value judgment, it's just that they are very different things and suited for 2 very separate purposes, and windows puts huge constraints on what you can do with your machine
Well well well so you are telling me I had ubuntu installed on my laptop this whole time and did not know about this lol. I knew I should have read the linux webpage. Thanx for telling me though I kind of feel silly now. All I did was play computer games on my ubuntu and watch netflix lmao.

as for learning, i have never been able to read a single page of a programming book in my life, it's boring and unnecessary. My method is: just pick a problem to solve - preferably something more complex than "hello world", then try to figure out how to implement it bit by bit, filling in the gaps of knowledge as you go. Nowadays with LLMs that process is made even more effective
Thanks for the tip.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Well well well so you are telling me I had ubuntu installed on my laptop this whole time and did not know about this lol
lmao yep

to be fair it's not well advertised what comes with it
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
javascript (Node.js)

it's very clear that javascript is not suitable for anything beyond running client-side web apps (if that, even).

inconsistent in-place/by-copy behavior, confusing mix of imperative and functional-like patterns. The type system is of course the loosest ever, you're mostly guessing as to wtf is going on at any point in time.

what was the other language they considered for client-side scripting again? Lisp? Whatever it was, im guessing the world would have been decades ahead in web technology if they chose anything other than javascript

JavaScript:
const fs = require("fs");

// 'data' is entire file as one string, '\n'-separated
function read_handler(err, data){
    if(err){
    console.error(err);
    return;
    }

    const docs = data.split('\n').filter(l => l.trim() !== '').map(l => JSON.parse(l));

    docs.forEach(d => d.x = d.vf * d.vi)
    docs.sort((a, b) => a.x - b.x);
    docs.forEach(d => process.stdout.write(String.fromCharCode(d.mona)));

}

if(process.argv.length < 3){
    throw new Error("missing arg");
}

fs.readFile(process.argv[2], 'utf8', read_handler);
 

Puffy

"Wtf even was that"
Local time
Today 9:04 PM
Joined
Nov 7, 2009
Messages
4,000
---
Location
Path with heart
I am pivoting towards computer programing myself, but I got stuck at installing java, I have no idea what or how to install the damn thing. Either way I want to learn a lot about computers. I have always been a standard computer user with minor interest in fixing surface level issues, and it hit me that in this day and age I might as well learn something.

Currently I am wondering what languages I want to learn and what literature to read to get grasp of theory.

Unfortunately lately I have felt unmotivated and apathetic and it made me avoid any kind of mental activity.

Currently feel a little more real about it and want to continue.

I always wanted to know C++

I studied javascript (node.js too herp derp) and the web stack needed to set up a basic web app. I got into a junior software developer role and then transitioned into user experience design which is what I do now. I'm definitely still junior in programming and not as experienced as dr froyd.

I found a mix of resources and approaches helpful in learning like online courses, competitive coding websites, textbooks, stackoverflow, meetup groups, contributing to github projects, building my own pet projects.

I got into a coding bootcamp off the back of that and it did help in creating a structured learning environment and in learning from working with other peers as well. I never studied it at university formally and at least when I entered the field 10 years ago I didn't need to to get a job. I don't know if that's changed since then, I get the sense that it's a more competitive environment now at least in the UK.

I'd just do an online course in a chosen language to learn the basic syntax. Then as froyd says I think it's about building pet projects and researching through free resources like AI/LLMs and stackoverflow how to build it and resolve issues as you go along. Even if you didn't join a bootcamp, school or similar, I do think there's benefit in being a part of a peer group of people who are also learning and working on projects together.

Also, p.s., I know tonnes and tonnes of people in engineering who are neurodiverse with ASD, ADHD or both. You'll meet a lot of other neurodiverse people through programming.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
user experience design which is what I do now.
what are the most common problems in ux? And why is it that most web interfaces are slow af like we're still in the 90s lol

I've gotten more into ui/web stuff recently, it's quite interesting. I might be unusually concerned with speed and responsiveness but it find it surprising that people consider it normal/acceptable in 2025 that it takes several seconds to render a basic web page that loads a few kilobytes of data. Isn't that a huge part of user experience
 

ZenRaiden

One atom of me
Local time
Today 9:04 PM
Joined
Jul 27, 2013
Messages
5,430
---
Location
Between concrete walls
Also, p.s., I know tonnes and tonnes of people in engineering who are neurodiverse with ASD, ADHD or both. You'll meet a lot of other neurodiverse people through programming.
Yeah, factually, part of reasoning behind this choice to find someone with similar mindset or similar interests. I don't expect to get along with all neurodiverse people by default tho, but I feel like some of my thinking and way of doing things will be more congruent with machines and I think I can get personally invested into this without really losing much life because I already spend all the time on computer when not doing something else.
Might as well then be something productive and interesting. Word is that dev jobs and all round IT job market is saturated, but I do think there are ways to make it work regardless.
 

fluffy

Blake Belladonna
Local time
Today 2:04 PM
Joined
Sep 21, 2024
Messages
772
---
I am not sure programing is right for me.

It is a technology that I cannot learn by myself.

When I read up on people that do it for a living they began at 8 years old with a natural proclivity towards it.

Me I see it as a tool, something interesting to explore but unless it's for a purpose other than making money I would not want to do it.

Like how many videogames I am good at but not others. If you had me playing Minecraft all day I suck at it and not get enough money. The same with programming. What is programming for? Money? Then I don't want to do it.

Rather I can fix technical problems more creatively. Not in French or Japanese. Because if I needed to learn those first I just be homeless. Instead just put things together without laungauge. You don't need a computer laungauge to understand computers. I figured out how the CPU works as a model I could build if I had the parts. I could draw all the parts in a circuit.

I just don't know, memorization is hard. I just do stuff with what is in front of me. I don't type fast or I could be a data entry person. But I am in the bottom 5% for speed. I would fix cars but I don't want to get poisoned or cut. Most things I am sure I could do. I wonder what?
 

Puffy

"Wtf even was that"
Local time
Today 9:04 PM
Joined
Nov 7, 2009
Messages
4,000
---
Location
Path with heart
Also, p.s., I know tonnes and tonnes of people in engineering who are neurodiverse with ASD, ADHD or both. You'll meet a lot of other neurodiverse people through programming.
Yeah, factually, part of reasoning behind this choice to find someone with similar mindset or similar interests. I don't expect to get along with all neurodiverse people by default tho, but I feel like some of my thinking and way of doing things will be more congruent with machines and I think I can get personally invested into this without really losing much life because I already spend all the time on computer when not doing something else.
Might as well then be something productive and interesting. Word is that dev jobs and all round IT job market is saturated, but I do think there are ways to make it work regardless.
You should def meet some similar people lol.

Where there’s a will there’s a way I’d say, if it’s what you’re passionate about don’t let the job saturation put you off, just plan that it will prob take longer. Maybe you could ask @dr froyd for what his views are on gaps in the market atm to target.

I am not sure programing is right for me.

It is a technology that I cannot learn by myself.

When I read up on people that do it for a living they began at 8 years old with a natural proclivity towards it.

Me I see it as a tool, something interesting to explore but unless it's for a purpose other than making money I would not want to do it.

Like how many videogames I am good at but not others. If you had me playing Minecraft all day I suck at it and not get enough money. The same with programming. What is programming for? Money? Then I don't want to do it.

Rather I can fix technical problems more creatively. Not in French or Japanese. Because if I needed to learn those first I just be homeless. Instead just put things together without laungauge. You don't need a computer laungauge to understand computers. I figured out how the CPU works as a model I could build if I had the parts. I could draw all the parts in a circuit.

I just don't know, memorization is hard. I just do stuff with what is in front of me. I don't type fast or I could be a data entry person. But I am in the bottom 5% for speed. I would fix cars but I don't want to get poisoned or cut. Most things I am sure I could do. I wonder what?
I first started learning when I was 25 and I had my first paid freelance web development work when I was 26. The market was booming then and it’s a different more competitive landscape now so that’s not a fair timeline to compare to but you def don’t need to see starting late as a barrier. I studied humanities before this and had only been good at creative stuff like writing and music so I didn’t think I’d be able to do it either. I think you probably just need a good learning environment. Also don’t compare yourself to others, who cares if someone else is a child prodigy it’s about you and what you want.

I think it’s about thirst and continual daily effort really. I was at rock bottom when I started and for me it’s what I focused on to climb out of the pit so I went all in 100%. If you don’t have the desire for it then it won’t happen and that’s also okay as you don’t have to pursue programming if you don’t want to.
 

Puffy

"Wtf even was that"
Local time
Today 9:04 PM
Joined
Nov 7, 2009
Messages
4,000
---
Location
Path with heart
user experience design which is what I do now.
what are the most common problems in ux? And why is it that most web interfaces are slow af like we're still in the 90s lol

I've gotten more into ui/web stuff recently, it's quite interesting. I might be unusually concerned with speed and responsiveness but it find it surprising that people consider it normal/acceptable in 2025 that it takes several seconds to render a basic web page that loads a few kilobytes of data. Isn't that a huge part of user experience
That’s more of a front end dev’s problem to solve than purely UX. :happydolphin:

My job is more doing research to understand user and business requirements and then translating those requirements into wireframes or prototypes to test with users to see how they perform. A lot of that you can do using different tools without code. Once we’ve defined the requirements then it will get built by engineers and they’ll be optimising things like performance while people in my team continue to define and design the features coming up next in the roadmap. If it was truly underperforming then we’d work with engineers to understand why and design an alternative if necessary.

The main challenge in UX right now is finding a job unless you already have one like me. :dolphin: :rainbow:
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
The main challenge in UX right now is finding a job unless you already have one like me. :dolphin: :rainbow:
got it lol.

well now i understand the difference between ux and ui. Sounds like an interesting challenge to coordinate between the different parties involved. I've mostly operated at the smaller level where i'm one of the users, the ui designer and the backend engineer simultaneously.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
on the subject of jobs, i personally don't have much clue in terms of the supply/demand situation. But what im more sure about is that the entire world is running on computers and the development/maintainance of programs will never end. If things become easier with LLMs, it just means people will make more stuff and produce things at an even higher speed.

i also think LLMs will change the nature of programming jobs quite a bit. It will allow for much more creativity on the part of each programmer, via the ability to glue together many different solutions in many different langauges. In fact that's one of the rationales for this thread.
 

Puffy

"Wtf even was that"
Local time
Today 9:04 PM
Joined
Nov 7, 2009
Messages
4,000
---
Location
Path with heart
The main challenge in UX right now is finding a job unless you already have one like me. :dolphin: :rainbow:
got it lol.

well now i understand the difference between ux and ui. Sounds like an interesting challenge to coordinate between the different parties involved. I've mostly operated at the smaller level where i'm one of the users, the ui designer and the backend engineer simultaneously.

I thought that full stack engineers were meant to be mythological creatures like unicorns or fairies lol :star:
 

scorpiomover

The little professor
Local time
Today 9:04 PM
Joined
May 3, 2011
Messages
3,458
---
I thought that full stack engineers were meant to be mythological creatures like unicorns or fairies lol :star:
Full-stack engineers are like most IT job applications that ask for 50 different skills, each of which are incredibly rare to begin with. It's been a fad for a while for IT job applications to ask for lots of skills, so that (in theory) they'll be able to get the candidates with the most skills.
 

scorpiomover

The little professor
Local time
Today 9:04 PM
Joined
May 3, 2011
Messages
3,458
---
on the subject of jobs, i personally don't have much clue in terms of the supply/demand situation. But what im more sure about is that the entire world is running on computers and the development/maintainance of programs will never end. If things become easier with LLMs, it just means people will make more stuff and produce things at an even higher speed.
This all goes back to the Black Death in the 14th Century. The Black Death killed 50% of Europe. This meant that there just wasn't the people to do many jobs that were necessary. As a result, employees had a LOT more power, and thus reduced the power of employers, who at the time, were the aristocracy. This upended society and caused the death of the aristocracy, to be replaced by mercantile capitalism, which put the merchants in charge.

Ever since then, there's been a big worry that the same thing could happen again.

Humans were replaced with machines, because then human workers would be replaceable, which reduced the power of employees.

Then in the late 19th Century and early 20th Century, Taylorisation, aka mechanisation, was introduced, partly because the skilled craftsmen who maintained and repaired factory machines, had tremendous power, because without them, the machines would eventually stop working and the entire factory would grind to a halt, and so could not be fired. As a result, they could demand any salary they wanted. In addition, they used to encourage the regular factory workers to strike for better pay and conditions. So they became seen as the enemy of the management.

So they tried to make machine parts easily replaceable, so factories didn't need workers to maintain the machines. But this of course just passed the buck onto those who made the machine parts and those who replaced them.

Computing was introduced, partly to have general all-purpose machines, so you didn't need to rely on those who made the machine parts you needed. But this passed the problem onto the programmers, as now, the programmers could understand all the computing, but the business people who owned and managed companies, didn't have a clue what the computers were doing. So then, the programmers had all the power, which was why programmers ended up being paid big bucks.

Then automation was introduced, in order to solve that problem, as was lots of computer languages to make the task of computing easier and easier.

Making anyone in the world able to work with computers, and making it easy to immigrate from anywhere in the world, and remote computing, were all made so that businesses could hire anyone in the world, and thus reduce the power of programmers.

This gets very complex. But in a nutshell, the people running businesses, use technology to make money. But someone has to learn that technology, which requires a lot of effort and a lot of time. You see, if tech was easy, then anyone could start a business using the same tech, and then businesses would get too much competition and most of them would not survive.

So tech's value is in that it's hard to learn.

But equally, the harder tech is to learn, the harder it will be to both run the business and learn the tech. So tech and business have ended up being split. That gives techies great power, which threatens the power of the management.

So it's a push-me-pull-you situation. Management compete with tech, by trying to make tech easier to learn and getting as many people as possible to be able to do that tech for their company. At the same time, the easier it is to get someone to do the tech, the more other companies can do the same, and the harder it becomes to make money from that tech, due to competition from other companies doing the same.

So management are in a never-ending war with themselves.

Techies can make a lot of money in the meantime. But only when they're in a new tech field, where there are very few people who can do that tech. Once a lot of people can do that tech for a company, then techies are in for massive competition.

Right now, due to mass immigration, globalisation and remote working, anyone in the world might be available to do new tech, and that's 8,000,000,000 people. So nowadays, even new tech quickly develops the same problems as old tech, which is massive competition for tech jobs, but also massive competition for businesses that make money from that tech.

i also think LLMs will change the nature of programming jobs quite a bit. It will allow for much more creativity on the part of each programmer, via the ability to glue together many different solutions in many different langauges. In fact that's one of the rationales for this thread.
If you look through your examples, you'll see that you've described many different ways for doing the same job in different languages. Most programming languages start out being incredibly specialised, but end up being extended repeatedly to add more and more functionality that is already available in other languages. So all programming languages end up heading towards the same goal, which is to be able to do everything that you'd want a programmer to do. So the end result is that most programming languages only differ in the syntax, and thus are only semantically different for the most part.

So once a programmer has picked up several languages, he feels more like a translator, rather than a programmer.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
OCaml

first time im using a functional language so this one required actual effort. Still have little clue what im doing, but managed to get the correct output


Code:
type mo_t = {
    vf   : float;
    vi   : int;
    mo   : int;
     x   : float;
}

let read_lines (file : string) : string list =
  let contents = In_channel.with_open_text file In_channel.input_all in
  String.split_on_char '\n' contents


(* get the rhs value v in string "k:v" *)
let jvalstr (kvstr : string) : string = 
  let kv = String.split_on_char ':' kvstr in
  if List.length kv >= 2 then
    List.nth kv 1
  else
    ""


let trimbrace (s : string) : string = 
  if String.length s >= 2 then
    String.sub s 1 (String.length s - 2)
  else
    s  


let parse_record (json : string) : mo_t =
  let json = trimbrace json in
  let kvps = String.split_on_char ',' json in
  let vs = List.map jvalstr kvps in
  {
    vf = float_of_string (List.nth vs 0);
    vi = int_of_string (List.nth vs 1);
    mo = int_of_string (List.nth vs 2);
    x = (float_of_string (List.nth vs 0)) *. (float_of_string (List.nth vs 1));
  }


let main () = 
  if Array.length Sys.argv <> 2 then
    print_endline "missing arg"
  else
    let lines = read_lines Sys.argv.(1) in
    let lines = List.filter (fun line -> line <> "") lines in
    let mos = List.map parse_record lines in
    let mos = List.sort(fun a b -> compare a.x b.x) mos in
    List.iter (fun m -> print_char (char_of_int m.mo)) mos


let () = main ()
 

birdsnestfern

Earthling
Local time
Today 4:04 PM
Joined
Oct 7, 2021
Messages
2,156
---

I took COBOL I and II. It is a Business program language, and I don’t really use or know it anymore, but studied it in 1998 or so. It looks like the below garble. I was not that good, but I passed both classes and then went back to accounting.​


F12
chgjob out q wrkobjpdm
pf src cbl ok

When control break
do control-break actions
When first-record
do first record-actions
When end of file
do end-of-file actions
Perform 150-Read-Input-Record
Until S1-End-Of-File.
150-READ-INPUT-RECORD
READ SALES-FILE INTO SR-SALES-RECORD
AT END
MOVE “E” TO S1-END-OF-FILE-SWITCH
PERFORM 250-PROCESS BREAK.
IF NOT END-OF-FILE
PERFORM 250-PROCESS-BREAK
PERFORM 200-PROCESS-DETAIL-RECORD.
250-PROCESS-BREAK
IF FIRST-RECORD
MOVE SR-SALES-REP TO RC-PREV-SALES-REP
PERFORM 870-PRINT-REPORT-HEADINGS
MOVE “N” TO S2-FIRST-RECORD-SWITCH
ELSE
IF SR-SALES-REP TO RC-PREV-SALES-REP
PERFORM 610-PROCESS-END-OF-SALES-REP
ELSE
IF END-OF-FILE
PERFORM 610-PROCESS-END-OF-SALES-REP
PERFORM 700-PRINT-REPORT-TOTAL-LINE.
250-PROCESS-BREAK
IF S2-FIRST-RECORD
AND S1-END-OF-FILE
PERFORM 990-EMPTY-FILE-ERROR
ELSE
IF FIRST-RECORD
AND S2-NOT-END-OF-FILE
MOVE SR-SALES-REP TO RC-PREV-SALES-REP
PERFORM 870-PRINT-REPORT-HEADINGS
MOVE “N”TO S2-FIRST-RECORD-SWITCH
ELSE
IF SR-SALES-REP NOT= RC-PREV-SALES-REP
AND S1-NOT-FIRST-RECORD
AND S2-NOT-END-OF-FILE
PERFORM 610-PROCESS-END-OF-SALES-REP
ELSE
IF END-OF-FILE
AND S2-NOT-FIRST-RECORD
PERFORM 610-PROCESS-END-OF-SALES-REP
PERFORM 700-PRINT-REPORT-TOTAL-LINE.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
it's crazy how low-abstraction COBOL is for a business-oriented language. But it makes sense, it was released in 1958 when people had to deal with like 1 kilobyte of computer memory. I really like these old low-abstraction languages though, one can write super efficient stuff in them
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Nim

nim is a very interesting language from a practical point of view. It looks almost like python but it's a compiled, statically typed language.

Code:
import os
import json
import std/[sequtils]
import algorithm

let args = commandLineParams()
if args.len < 1:
  echo "missing arg"
  quit(1)


let lines: seq[string] = lines(args[0]).toSeq()
var jseq: seq[JsonNode]

for l in lines:
  let h: JsonNode = parseJson(l)
  h["x"] = %* (h["vf"].getFloat() * h["vi"].getFloat())
  jseq.add(h)


proc mycmp(x, y: JsonNode): int =
  cmp(x["x"].getFloat(), y["x"].getFloat())

jseq.sort(mycmp)

for j in jseq:
  stdout.write(chr(j["mona"].getInt()))
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Go

i have avoided this language for a long time, quite simply because it's made by google.

but as far as statically-typed high-level languages go, it does seem very good. The json parsing is very cleverly designed. Absence of implicit type conversion also a very nice touch - this makes it more strongly typed than even C++.

i spent like 1 hour debugging this thing because it kept parsing all json values to just 0. Turns out it was because i used lower-case letters in the struct member names. No compiler errors, no compiler warnings, no runtime errors, no nothing - it just parsed them as 0. That's a weird design but apparently there's a reason for it.


Code:
package main

import (
    "fmt"
    "os"
    "log"
    "encoding/json"
    "bufio"
    "sort"
)

type mo_t struct {
    Vf  float64  `json:"vf"`
    Vi  int      `json:"vi"`
    Mo  int      `json:"mona"`
    X   float64
}

var jl []mo_t

func main(){
    if len(os.Args) != 2 {
        fmt.Println("missing arg")
        os.Exit(1)
    }
   
    file, err := os.Open(os.Args[1])
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    scanner := bufio.NewScanner(file)
   
    for scanner.Scan() {
        var obj mo_t
        err := json.Unmarshal(scanner.Bytes(), &obj)

        if err != nil {
            log.Printf("err %v\n", err)
            break
        }

        obj.X = float64(obj.Vi) * obj.Vf
        jl = append(jl, obj)
    }

    sort.Slice(jl, func(i, j int) bool {return jl[i].X < jl[j].X})

    for _, obj := range jl {
        fmt.Printf("%c", obj.Mo)
    }
}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
D

first, a note on Go; just learned that Google gathers "telemetry" from this language, i.e. user data. So basically you have spyware on your machine just to use that fookin language. Apparently it's optional (for now) but who knows when they decide to make it mandatory, or whether they do it regardless or what data they gather. Big fucking suprise that google sees the need to do shady shit to gather data. But that makes for an easy decision: never use this language (or anything made by google for that matter).

now that the rant is out the way, we have a pleasant surprise. This language, D, is fucking brilliant. In the domain of high-level compiled statically-typed languages this is the best thing I've seen. Oh and it has built-in json parsing.


Code:
import std.stdio;
import std.file;
import std.json;
import std.algorithm;


int main(string[] args){
    if(args.length != 2){
        writeln("missing arg");
    return 1;
    }

    auto file = File(args[1], "r").byLine();

    JSONValue[] vals;

    foreach(line; file){
    JSONValue j = parseJSON(line);
    j["x"] = j["vf"].floating * j["vi"].integer;
    vals ~= j;
    }

    vals.sort!((a, b) => a["x"].floating < b["x"].floating);
    foreach(v ; vals){
        write(cast(char) v["mona"].integer);
    }

    return 0;
}
 

scorpiomover

The little professor
Local time
Today 9:04 PM
Joined
May 3, 2011
Messages
3,458
---
I wonder which programming language would use the least lines of code to do this task.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Assembly

(x86-64 nasm on Linux)

this will definitely not win for least number of lines.. but perhaps least number of machine-code lines?

ngl this was painful. But fascinating... First time im actually writing assembly and boy was i happy when that mona lisa finally popped up. Took me about 3 days to just be able to read the file correctly.

interesting quote i heard while learning assembly:
"My experience is that if you really want to understand something, you want to understand it to the level that’s necessary, and then one level below that; it’s not that you’ll necessarily use that one level below it, but that gives you insight as to why that layer is what it is, and what’s really going on"

Code:
section .data
        msg_error db 'missing arg', 0xa
        len_error equ $ - msg_error
        filepath dq 0
        dataarr dq 0
        filebuf times 131072 db 0 ; buf for entire file, 128 * 1024 bytes
        filebuf_sz equ $ - filebuf
        vf dq 0
        vi dq 0
        mo dq 0
        xm dq 0                 ; to hold x = vf * vi, and mo
        itoa_buffer times 10 db 0


section .text
        global _start


;; string pointer taken as rdi
strlen: 
        mov rax, 0
        mov r8, rdi
.loop_len:
        cmp byte [r8], 0
        je .end_loop
        inc rax
        inc r8
        jmp .loop_len
.end_loop:       
        ret


;; open file at [filepath], put fd, byteread into r8, r9
openread:       
        ;; open file
        mov rax, 2              ; syscall open
        mov rdi, [filepath]
        mov rsi, 0
        mov rdx, 0
        syscall
        mov r8, rax             ; filedescriptor to r8

        ;; read file
        mov rax, 0              ; syscall no. for read
        mov rdi, r8             ; file descriptor
        mov rsi, filebuf
        mov rdx, filebuf_sz     ; buffer size FIXME: use real filebuf size
        syscall
        mov r9, rax             ; "save no. of bytes read" ?
        ret

;; input (string pointer) in rdi, output in rax
;; rsi as no. of bytes to read
;; alters rax, rcx, rsi, rdx, r11
atoi:   
        xor rax, rax
        mov rcx, rdi
        mov r11, 0              ; charcount
.nextchar:
        movzx edx, byte [rcx]
        cmp r11, rsi
        je .done
        inc r11
        sub edx, '0'
        imul rax, 10
        add rax, rdx
        inc rcx
        jmp .nextchar
.done:
        ret


;; rdi, rsi, rdx
;; addr, offset, len
parse_int:
        add rdi, rsi
        mov rsi, rdx
        call atoi
        ret


;; input: rdi is end address
isort:  
        mov rax, [dataarr]
.outer:
        cmp rax, rdi
        je .break
        mov rsi, rax            ; rsi inner counter (j)
        add rax, 8              ; increment outer counter
.inner:
        ;; check condition j > 0
        cmp rsi, [dataarr]
        jle .outer

        ;; check condition y[j-1] > y[j]
        sub rsi, 8              ; move to j-1
        mov rcx, qword [rsi]    ; rcx =  y[j-1]
        add rsi, 8              ; move back to pos j
        cmp rcx, qword [rsi]    ; compare y[j-1], y[j]
        jle .outer              ; break to outer if y[j-1] <= y[j]

        ;; body of inner loop
        ;; note: rcx still contains y[j-1]
        mov rbx, [rsi]            ; rbx = y[j]

        ;; swap values at j and j-1
        sub rsi, 8
        mov [rsi], rbx
        add rsi, 8
        mov [rsi], rcx

        sub rsi, 8              ; j--
        jmp .inner
.break:
        ret

_start: 
        ;; check cmd arg count
        pop rcx                 ; cmd args len put onto stack at start
        cmp rcx, 2
        jl arg_error

        ;; get path as cmdarg
        pop rcx                 ; argv[0]
        pop rcx                 ; argv[1]
        mov [filepath], rcx

        ;; calc length of filepath str
        mov rdi, [filepath]
        call strlen
        mov rdx, rax

        ;; print cmd-arg-supplied filepath
        mov rax, 1              ; syscall 1 = write
        mov rdi, 1              ; file descriptor, 1 = stdout
        mov rsi, [filepath]     ; buffer address of msg to rsi
        ;; still using rdx for write length..
        syscall

        ;; -------malloc ---------
        mov rsi, 65536          ; 1024 * 64 (TODO: dont hardcode)
        call malloc
        cmp rax, 0              ; check alloc
        jl alloc_error

        mov [dataarr], rax       ; store data-array address
        ;; --------------------

        ;; puts entire file into filebuf.
        ;; fd will be in r8, bytes read in r9
        call openread

        ;; print file
        mov rax, 1              ; syscall 1 = write
        mov rdi, 1              ; file descriptor, 1 = stdout
        mov rsi, filebuf        ; buffer address of msg to rsi
        mov rdx, r9             ; writelength; no. of bytes read by openread
        ;; syscall

        ;; ----- filebuf parse ------
        ;; from here using r9 as count of remaining bytes to read.
        ;; r10 is current byte.
        mov r10, filebuf
        push qword [dataarr]    ; arr pointer at current index
.lineloop:
        cmp r9, 0               ; check for EOF
        je .end
        mov al, [r10]           ; load current byte
        ;; -----------
        cmp byte [r10], '.'     ; <<<<===============  '.'

;; ---- parse_vf -------:
        jne .skip_parse_vf
        mov rdi, r10
        mov rsi, 1
        mov rdx, 6
        call parse_int
        mov [vf], rax            ; *** vf ***
;; ---- /parse_vf -------:
.skip_parse_vf:
        cmp byte [r10], 'i'
        jne .skip_store_vi_start

;; ------ store_vi_start -------
        mov r14, r10
        add r14, 3              ; start of vi int
.skip_store_vi_start:
        cmp byte [r10], 'm'     ; <<<<===============  'm'
        jne .skip_store_vi_end
;; ------ .store_vi_end -------
        mov r15, r10
        add r15, -3             ; end of vi int

        mov rdi, r14            ; start of vi int to rdi for parse_int
        mov rsi, 0
        mov rdx, r15
        sub rdx, r14
        inc rdx
        call parse_int
        mov [vi], rax            ; *** vi  ***

.skip_store_vi_end:

        cmp byte [r10], '}'
        jne .skip_handle_closebrace

        add r15, 9              ;r15 still at end of vi int; move to start of mo int
        mov rdi, r15
        mov rsi, 0
        mov rdx, r10
        sub rdx, r15
        call parse_int
        mov [mo], rax

        ;; pack xm = [ vf * vi, mo ]
        mov rax, [vf]
        mov rsi, [vi]
        mul rsi
        ;; dont really need 32 bits for mo, it's a char
        sal rax, 32          ; shift the product to upper 32 bits
        mov rbx, [mo]        ; load mo into rbx so as to get ebx
        or rax, rbx          ; put [mo] into lower bits
        mov [xm], rax

        ;; store to array
        ;; there should be just 1 element on the stack
        pop rsi                 ; get current-position arr ptr
        mov [rsi], rax          ; rax still contains xm from above
        add rsi, 8              ; increment arr ptr
        push rsi                ; push address back onto stack

.skip_handle_closebrace: 
        inc r10
        dec r9
        jmp .lineloop
        ;; ----- /filebuf parse ------   


.end:
        ;; close file
        mov rax, 3      
        mov rdi, r8
        syscall

        pop r15
        mov rdi, r15
        call isort   
        ;; ----- print arr -----
        ;; recall this is little-endian so the lower bytes
        ;; are at lower memory addresses. Therefore the char byte
        ;; is at the *beginning* of each 8-byte value in the array
        sub r15, 8              ; point at last element instead of one beyond
        mov r10, [dataarr]      ; r10 to contain running addr
.moprint:
        mov rax, 1              ; syscall write
        mov rdi, 1              ; stdout
        mov rsi, r10            ; the char
        mov rdx, 1              ; print length
        syscall

        add r10, 8              ; increment position in array 
        cmp r10, r15
        je .moprint_end
        jmp .moprint
.moprint_end:
        ;; ----- /print arr -----

        ;; free
        mov rdi, [dataarr]
        mov rsi, 65536
        call free

        ;; exit 
        mov rax, 60             ; 60 = exit
        xor rdi, rdi            ; exit status code 0 (xor same value results in 0)
        syscall


;; takes no. of bytes via rsi
malloc: 
        mov rax, 9              ; mmap syscall number
        xor rdi, rdi            ; addr 0 (kernel chooses)
        mov rdx, 3              ; prot read | write
        mov r10, 34             ; MAP_PRIVATE | MAP_ANONYMOUS
        mov r8, -1              ; fd (-1 = no fd)
        xor r9, r9              ; offset 0
        syscall
        ret

;; in: 
;; rdi = addr, rsi = bytecount
free:   
        mov rax, 11             ; 11 = munmap syscall no.
        syscall
        ret


arg_error:  
        ;; write to stderr and exit
        mov rax, 1
        mov rdi, 2
        mov rsi, msg_error
        mov rdx, len_error
        syscall
        
        mov rax, 60
        xor rdi, rdi
        syscall


alloc_error:    
        mov rax, 60
        xor rdi, rdi
        syscall
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Lua

quirky language with a strange mix of modern and old-school patterns, but super lightweight and simple af. Very minimalistic so doesn't have any json support. It does have regex and sort though, that's good enough

Code:
if not arg[1] then
    print("missing arg"); os.exit(1)
end

file = io.open(arg[1], "r")
if not file then
   error("file-open error")
end


vals = {}
for l in file:lines() do
   local vf = string.gsub(l, "{\"vf\":([^,]+),\"vi.*", "%1")
   local vi = string.gsub(l, ".*\"vi\":([^,]+),.*", "%1")
   local mo = string.gsub(l, ".*\"mona\":([^,]+)}", "%1")

   table.insert(vals, {x = vf * vi, mo = mo})
end

file:close()

table.sort(vals, function(a, b) return(a.x < b.x) end)

for _, v in pairs(vals) do
   io.write(string.char(v.mo))
end
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Emacs Lisp

Lisp is an ancient language, and i don't really understand it. But if you want to do cool shit in emacs, you have to know lisp. And this was actually much less painful than i expected. Turns out it even has a built-in json parser.


Code:
;; return hash table
(defun parse_line (line)
  (setq j (json-parse-string line))
  (setq x (* (gethash "vi" j) (gethash "vf" j)))
  (puthash "x" x j)
  j)


(defun readfile (fpath)

  (setq vals (list)) ; list to contain parsed objects

  (with-temp-buffer
    (insert-file-contents-literally fpath)
    (goto-char (point-min))

    (while (not (eobp))
      (progn
        (setq l (buffer-substring (point) (line-end-position)))
        (push (parse_line l) vals)
        (forward-line))))

  (setq vals (sort vals (lambda (a b) (< (gethash "x" a) (gethash "x" b)))))

  (dolist (v vals)
    (princ (string (gethash "mona" v)))))


;; -------- main -------
(if (>= (length command-line-args) 4)
    (progn
      (setq fpath (nth 3 command-line-args))
      (readfile fpath))
  (message "missing arg"))
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Bash

what a "pure" bash implementation even is, is a bit hard to define because ultimately it is a shell language for unix. But one can look at it this way: the essence of unix shell is arguably manipulation of text streams via stdin/stdout by means of the standard commands like sed, grep etc. This set of "standard" commands can be taken as those which are mandated by POSIX, which includes sed, bc, sort, awk. So this particular solution aims at a pure stream/pipe design using those

Bash:
#json key patterns
NUM='\([\.0-9]*\)'
FLD1='\("vf":\)'
FLD2='\("vi":\)'
FLD3='\("mona":\)'

sed "s/{${FLD1}${NUM},${FLD2}${NUM},${FLD3}${NUM}}/\2*\4;\6/" $1 |
    bc -l |
    sed 'N; s/\n/,/' |
    sort -t, -k1 -n |
    sed 's/.*,//' |
    awk '{printf "%c", $1}'
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Julia

ngl this language seems pretty well designed. Aimed at statistical computing, but even as general-purpose it seems pretty damn slick. Super well-documented and with some very handy features like easy vectorization. Dynamic typing but allowing for type annotation is also a nice touch

the only thing i find weird about this language is its name. Like, what's up with "Julia". It's like calling a language "Jim", or "Bob"

Code:
struct mo_t
    x :: Float32
    mo :: Char
end

function parse_line(s :: String) :: mo_t
    pat = r"\"vf\":([.0-9]*),\"vi\":([0-9]*),\"mona\":([0-9]*)"
    m = match(pat, s).captures

    return mo_t(
        parse(Int32, m[2]) * parse(Float32, m[1]),
        Char(parse(Int32, m[3])))
end


if length(ARGS) != 1
    println("missing arg")
    exit(1)
end

lines = readlines(ARGS[1])
vals = parse_line.(lines)
sort!(vals, by = o -> o.x)

print(String(getfield.(vals, :mo)))
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Java

im sorry but this languages is absolutely terrible
- you can't write functions, since everything has to be either a class or method
- in fact i couldn't even write classes because JRE couldn't figure out which class is the main one
- the sorting interface is so horrifically convoluted that i ended up using same trick as in Assembly lol, i.e. packing the product/char values into a single 64-bit value
- you can't store regular ints in a list, you have to store references to ints (e.g. Long instead of long)
- etc

my condolences to all the dotcom-boom programmers who had to deal with this mess

Java:
import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;


public class mona {


static long parseline (String line, Pattern pat){

    Matcher mtc;

    mtc = pat.matcher(line);
    mtc.find();

    float vf = Float.parseFloat(mtc.group(1));
    int vi   = Integer.parseInt(mtc.group(2));
    int mo   = Integer.parseInt(mtc.group(3));

    float x = vf * vi;

    long xlong = (long) Math.round(1e12 * x);
    long k = 1000;
    xlong = k * (xlong / k);

    xlong += mo;

    return xlong;
}



public static void main(String[] args){

    if(args.length != 1){
    System.out.println("missing arg");
    return;
    }

    File file = new File(args[0]);
    Scanner sc;

    try {
    sc = new Scanner(file);
    } catch (FileNotFoundException e) {
    System.out.println("file not found: " + args[0]);
    return;
    }

    Pattern pat = Pattern.compile("\"vf\":([.0-9]*),\"vi\":([0-9]*),\"mona\":([0-9]*)");

    ArrayList<Long> vals = new ArrayList<Long>();

    while(sc.hasNextLine()){
    vals.add(parseline(sc.nextLine(), pat));
    }

    sc.close();
    Collections.sort(vals);

    for(Long v : vals){
        char c = (char) (v % 1000);
    System.out.print(c);
    }

}}
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
SQL

using SQLite allows for creating an in-memory database on the fly. Very handy stuff


SQL:
----- make 'parsed' table -----
CREATE TABLE input (raw JSON);

.mode line
.import "data/mona.jsonl" input

CREATE TABLE parsed AS
SELECT 
       CAST(json_extract(raw, '$.vi') AS INTEGER) AS vi,
       CAST(json_extract(raw, '$.vf') AS REAL) AS vf,
       CHAR(CAST(json_extract(raw, '$.mona') AS INTEGER)) AS mo
FROM input;
----------------------------


SELECT group_concat(mo, '') AS result FROM (
SELECT mo FROM (
SELECT mo, vi * vf AS x
FROM parsed
ORDER BY x));
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
R

R makes an interesting compromise as a language. It's very difficult to crash it, but on the other hand you never really know what it will produce. It basically tries to give you something no matter what you do. It makes sense though, having been made for interactive statistical work.

Code:
path <- commandArgs(trailingOnly = TRUE)[1]
if(is.na(path))
    stop("missing arg")

jsonl <- readLines(path)

vals <- regmatches(jsonl, regexec(
    "\"vf\":(?<vf>[.0-9]*),\"vi\":(?<vi>[0-9]*),\"mona\":(?<mo>[0-9]*)", 
    perl = TRUE, jsonl))

df <- as.data.frame(t(sapply(vals, function(x) x[-1])))

df$vf <- as.numeric(df$vf)
df$vi <- as.integer(df$vi)
df$mo <- intToUtf8(as.integer(df$mo), multiple = TRUE)

df <- df[order(df$vi * df$vf), ]
cat(df$mo, sep = "")
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Prolog

logic-programming is a real brainfuck when you're coming from regular programming. The language itself is super interesting though

Code:
:- set_prolog_flag(verbose, silent).
:- initialization(main).
:- use_module(library(http/json)).


read_file(Stream, Dicts) :-
    read_line_to_string(Stream, Line),
    (   Line \= end_of_file
    ->  (
        atom_json_dict(Line, Dict, []) ->
            read_file(Stream, Rest),
            Dicts = [Dict|Rest]
        ;   format("invalidjson ~n"),
            read_file(Stream, Dicts)
    )
    ;   Dicts = []
    ).


sort_dicts(Dicts, SortedMos) :-
    findall(
        X-Di, %% X-Di will be a numeric,dict pair
        (
            member(Di, Dicts),
            Di = _{vf: Vf, vi: Vi, mona: Mona},
            X is Vf * Vi
        ),
        Vals),

    %% "standard order" will result in comparing on X, the first arg,
    %% and compared numerically since X is numerical
    sort(Vals, SortedVals),

    %% extract just the dicts, without the X
    findall(Mona, (
        member(_-Di, SortedVals),
        get_dict(mona, Di, Mona)
    ), SortedMos).


print_chars([]).
print_chars([Mona|Mos]) :-
    format('~c', [Mona]),
    print_chars(Mos).

main :-
    current_prolog_flag(argv, Argv),
    nth0(0, Argv, FilePath),
    open(FilePath, read, Stream),
    read_file(Stream, Dicts),
    close(Stream),
    sort_dicts(Dicts, SortedMos),
    print_chars(SortedMos),
    halt.
main :-
    halt(0).
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
PHP

yo what the hell. This language is actually really nice. Super easy and concise

PHP:
if($argc != 2){
    echo "missing arg"; exit;
}

$vals = array_map(
    fn($l) => json_decode($l, true),
    file($argv[1])
);

usort($vals, function($a, $b) {
    return $a['vi'] * $a['vf'] <=> $b['vi'] * $b['vf'];
});

$mo_ints = array_column($vals, 'mona');
echo implode('', array_map('chr', $mo_ints));
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
Rust

many people are creaming their pants over this language nowadays. I suppose it does pretty much as advertised; a memory-safe C++ alterantive with an insanely pedantic compiler


Code:
use std::env;
use std::fs::File;
use std::io::{BufReader, BufRead};

//json: {"vf":0.85782771534,"vi":40,"mona":32}
fn parse_line(
    vf: &mut f32,
    vi: &mut i32,
    mo: &mut u8,
    json: &str) -> ()
{
    let s = json.trim_matches('{').trim_matches('}');
    for kv_str in s.split(',') {
        let kv_str = kv_str.trim();
        let mut kv = kv_str.split(':');
        let k = kv.next().unwrap();
        let v = kv.next().unwrap();
        match k {
            "\"vi\""   => *vi = v.parse().unwrap(),
            "\"vf\""   => *vf = v.parse().unwrap(),
            "\"mona\"" => *mo = v.parse().unwrap(),
            &_ => panic!("unexpected key: {}", k)
        }
    }
}


struct MoT {
    mo: u8,
    x: f32
}


fn main(){

    let args: Vec<String> = env::args().collect();

    if args.len() != 2 {
        println!("missing arg");
        return;
    }

    let file = match File::open(&args[1]) {
        Ok(file) => file,
        Err(err) => {panic!("fail open {}: {}", &args[1], err);}
    };

    let reader = BufReader::new(file);

    let mut mo: u8  = 0;
    let mut vf: f32 = 0.0;
    let mut vi: i32 = 0;

    let mut vals: Vec<MoT> = Vec::new();

    for line in reader.lines() {
        match line {
            Ok(line) => parse_line(&mut vf, &mut vi, &mut mo, &line),
            Err(err) => panic!("fail lineread {}", err)
        }

        vals.push(MoT {
            mo: mo,
            x : vf * vi as f32
        });
    }

    vals.sort_by(|a, b| a.x.total_cmp(&b.x));

    for v in vals {
        print!("{}", v.mo as char);
    }
}
 

kuoka

Member
Local time
Today 10:04 PM
Joined
Mar 24, 2023
Messages
37
---
Which one felt like easiest to express your ideas in? I'm asking both in terms of time, but also about how easy it was to convert your ideas to code.

From experience Python is probably the fastest to prototype, but not the clearest. C-family is very clear, but not the fastest to write. Java is C-like, but my least favorite to read and work with.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
the ones that stood out to me in terms of how smooth and intuitive the
experience was, were D, Julia, Ruby, Perl, and PHP.

in terms of compiled, statically typed languages D just seems like a severely underrated language imo.

Julia had superb documentation and some very elegant designs, I will definitely be using that for data/statistical stuff

Python is of course the bread-and-butter of prototyping, especially nowadays when practically everything has a Python binding. It's probably not the best tool for any particular problem, but it's the most ubiquitous one

Java was just shockingly unpleasant. Java was actually the first langauge I learned back in the day, but I forgot how terrible it is.

Rust seems good and will probably kill C++ eventually. Will it kill C though, i somehow doubt it. If you have to deal with low-level memory and pointer arithmetic then C is the most direct tool.
 

dr froyd

__________________________________________________
Local time
Today 9:04 PM
Joined
Jan 26, 2015
Messages
1,675
---
the most rewarding experience though, was Assembly lol. Like, I felt genuine joy when it actually worked.

at some point i realized it's useless to try to print-debug it because you can't even print numbers (everything is raw bytes), so then you are forced to pull out a debugger. And then, behold.. you see the actual CPU registers and everything. It was cool af, highly recommended
 
Top Bottom