17
3
Challenge
I've recently gotten into 8-bit computers and are fascinated with the workings of them and others alike; thus the objective of this code golf, is to replicate a portion of the Woz Monitor, designed by Steve Wozniak for the Apple I.
You are to store an array of 22 hexadecimal values with a width of two bytes, (min value $10, max value $FF), and then take in n-amount of inputs. (Normally two; languages like Brainfuck might have a hard time).
The inputs will refer to where in the array to start printing from, and where to stop; an input with defined behaviour will have their starting value less or equal to the ending value. Your program must then be capable of printing every hexadecimal value between, and including, the hexadecimals inputted.
An example of this:
Array
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15
Values
FF F4 B6 D7 40 00 00 A4 F0 00 FF 0D 9C 21 65 C4 02 28 90 E7 D6 A5
input first num:
04
input second num:
14
40 00 00 A4 F0 00 FF 0D 9C 21 65 C4 02 28 90 E7 D6
Now the interesting part of this exercise, is that you can use whatever you want to check the bounds of the users input. Person inputs hello
and your program has undefined behaviour? It quits without notice? They are both valid.
The only rules are:
1. You must include the values of the 22 hexadecimal values as part of your program before it starts, (can't ask the user for inputs).
2. The output of the hexadecimal values must follow the exact format:
00 FF 00 FF 00
Trailing spaces, tabs or lines are OK. Characters are not.
3. The program doesn't have to ask for the inputs with a message. Leave the "message" blank if you wish. The user must input the hex-bounds however.
4. As with the values of the 22 hexadecimals are up to you to decide, you must make a program that actually fetches the values from storage, opposed to mimicking a program by simply printing values. (such as a list of $00's).
5. n-amount of inputs, refers to the amount of inputs required for your language of choice to recognise a hexadecimal of two byte-width. eg. (Brainfuck will require two inputs per hex, making it four for the two).
Feel free to comment if you need clarification.
This is code golf, so the shortest answer in the number of bytes is the winner.
Leaderboard
Here is a leaderboard generating snippet courtesy of Martin Ender.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
# Language Name, N bytes
where N
is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:
# Ruby, <s>104</s> <s>101</s> 96 bytes
function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/95080/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){$.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(e){answers.push.apply(answers,e.items);if(e.has_more)getAnswers();else process()}})}function shouldHaveHeading(e){var t=false;var n=e.body_markdown.split("\n");try{t|=/^#/.test(e.body_markdown);t|=["-","="].indexOf(n[1][0])>-1;t&=LANGUAGE_REG.test(e.body_markdown)}catch(r){}return t}function shouldHaveScore(e){var t=false;try{t|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(n){}return t}function getAuthorName(e){return e.owner.display_name}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading);answers.sort(function(e,t){var n=+(e.body_markdown.split("\n")[0].match(SIZE_REG)||[Infinity])[0],r=+(t.body_markdown.split("\n")[0].match(SIZE_REG)||[Infinity])[0];return n-r});var e={};var t=0,c=0,p=-1;answers.forEach(function(n){var r=n.body_markdown.split("\n")[0];var i=$("#answer-template").html();var s=r.match(NUMBER_REG)[0];var o=(r.match(SIZE_REG)||[0])[0];var u=r.match(LANGUAGE_REG)[1];var a=getAuthorName(n);t++;c=p==o?c:t;i=i.replace("{{PLACE}}",c+".").replace("{{NAME}}",a).replace("{{LANGUAGE}}",u).replace("{{SIZE}}",o).replace("{{LINK}}",n.share_link);i=$(i);p=o;$("#answers").append(i);e[u]=e[u]||{lang:u,user:a,size:o,link:n.share_link}});var n=[];for(var r in e)if(e.hasOwnProperty(r))n.push(e[r]);n.sort(function(e,t){if(e.lang>t.lang)return 1;if(e.lang<t.lang)return-1;return 0});for(var i=0;i<n.length;++i){var s=$("#language-template").html();var r=n[i];s=s.replace("{{LANGUAGE}}",r.lang).replace("{{NAME}}",r.user).replace("{{SIZE}}",r.size).replace("{{LINK}}",r.link);s=$(s);$("#languages").append(s)}}var QUESTION_ID=49042;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*$)/;var NUMBER_REG=/\d+/;var LANGUAGE_REG=/^#*\s*([^,]+)/
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>Language<td>Size<tbody id=answers></table></div><div id=language-list><h2>Winners by Language</h2><table class=language-list><thead><tr><td>Language<td>User<td>Score<tbody id=languages></table></div><table style=display:none><tbody id=answer-template><tr><td>{{PLACE}}</td><td>{{NAME}}<td>{{LANGUAGE}}<td>{{SIZE}}<td><a href={{LINK}}>Link</a></table><table style=display:none><tbody id=language-template><tr><td>{{LANGUAGE}}<td>{{NAME}}<td>{{SIZE}}<td><a href={{LINK}}>Link</a></table>
Are we asking the user for two inputs or n? Do we choose what the 22 hex values are? – xnor – 2016-10-01T08:49:35.490
Yes, the 22 values are yours to decide. The input values, they can be any amount. I said
n
because Brainfuck can't take in a 2 character string, you would need to input the first byte, then the second for the first value, and then do it again for the second value, 4 inputs in total. They can be however many as you like. – None – 2016-10-01T08:53:12.570However with the values, you can't simply have them all as 00, and have a program mimic what something would that actually reads the arrays. Updating the question. – None – 2016-10-01T08:53:50.810
Should it wrap or read in reverse if input 2 is less than input 1? – Jonathan Allan – 2016-10-01T09:02:53.230
@JonathanAllan That is entirely up to you. Just remember, making sure the inputs are correct may make your code bigger. As written just above the rules, you can allow any form of input (up to you), leading to undefined behaviour or errors if you wish. – None – 2016-10-01T09:05:19.703
@Arnauld :O My calculator wronged me! Should of checked that myself. :/ Still 22 values! Edited the question. – None – 2016-10-01T09:41:07.143
Is lowercase hexa allowed? (
0a
,0b
, etc.) – Arnauld – 2016-10-01T09:51:06.357@Arnauld Whatever you want. :) – None – 2016-10-01T09:52:50.483
Let us continue this discussion in chat.
– None – 2016-10-01T13:05:08.223"the amount of inputs required for your language of choice to recognise a hexadecimal of two byte-width" why exactly? If the inputs are
0
to22
, the width is only 5 bits. – Peter Taylor – 2016-10-01T18:22:11.367@PeterTaylor No, thats how many values you have. The values themselves must be two bytes wide, between $100 and $FFF. – None – 2016-10-02T23:43:33.047
Is a single leading space allowed? – seshoumara – 2016-10-03T05:49:50.687
Can the values be randomly chosen at the beginning? Meaning for consecutive runs you get a different answers? – Magic Octopus Urn – 2017-02-10T19:54:18.590
@carusocomputing Yes it can! As long as you end up with sixteen 2 byte-wide values. – None – 2017-02-12T00:01:01.697
>
00
,02
and0D
from your example fit in there? 4. And how does that match your answer from Oct, 2betweeen $100 and $FFF
?@Titus 1. Go for it. Command line arguments it is. 2. Nope, two bytes. The 'digits' you see are the hex representation. Woz monitor worked specifically in bytes. 3. I'm not sure what your asking but if it is what I think it is, your going to need to display 16 bytes as a 2-byte-wide hex value. The
00
,02
and0D
are locations in an array (0, 2 and 13 respectively). Each location will correspond to a random 2-byte-wide value in the array. 4. If you mean between$10
and$FF
, its literally a Python translation of the same thing in my C answer. I chose the easy way by making everything- – None – 2017-03-21T11:12:33.683@Titus -
$00
and afterwards just fetch each of them from their corresponding array index. – None – 2017-03-21T11:12:54.447@Titus Woops, thats 22 bytes, not 16! – None – 2017-03-23T06:11:04.817