The Woz Monitor

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&]*(?:&lt;(?:s&gt;[^&]*&lt;\/s&gt;|[^&]+&gt;)[^\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>

user49188

Posted 2016-10-01T08:45:07.950

Reputation:

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.570

However 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 to 22, 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

>

  • Does it have to be STDIN or can we just take two command line arguments? 2. I guess you mean two digits, not two bytes ... but 3. How do 00, 02 and 0D from your example fit in there? 4. And how does that match your answer from Oct, 2 betweeen $100 and $FFF?
  • < – Titus – 2017-03-21T02:47:29.327

    @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 and 0D 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

    Answers

    3

    Jelly, 24 21 bytes

    w@€ØHḅ⁴
    ɠǵɠÇr@b⁴ịØHK
    

    Chosen values: [00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 1F 10 11 12 13 14 15]

    TryItOnline

    If the second input is less than the first it outputs the reversed sequence.
    Out of bounds behaviour is undefined (e.g. "foo", "14" returns 38 values, most of which are not even in the array and many of which are not length 2)

    How?

    w@€ØHḅ⁴ - Link 1, parse a string as a 1-based hex value e.g. "14"
    w@€      - first index (1-based) of each character in
       ØH    - hex digits: "0123456789ABCDEF"                   [2,5]
         ḅ⁴ - convert from base 16                                 37
    
    ɠǵɠÇr@b⁴ịØHK - Main link
    ɠ  ɠ          - read a line from stdin               e.g. "04"  "14"
     Ç  Ç         - call the last link (1) as a monad          21    37
      µ           - monadic chain separation
         r@       - inclusive range, with reversed arguments  [   21,   22,...,   36,   37] 
           b⁴     - convert to base 16                        [[1,5],[1,6],...,[2,4],[2,5]]
             ị    - index into
              ØH  - hex digits: "0123456789ABCDEF"            [ "04", "05",..., "13", "14"]
                K - join with spaces
    

    Jonathan Allan

    Posted 2016-10-01T08:45:07.950

    Reputation: 67 804

    Ah, pardon me. You were indeed correct. Well done, and have leaderboard position #1. :) – None – 2016-10-01T10:20:58.557

    1yes, I just moved and changed the one offset value (now 1F), meaning I did not need to "correctly" interpret the hex inputs or add 16 to give me two hex digits to convert back. – Jonathan Allan – 2016-10-01T11:49:33.813

    3

    JavaScript (ES6), 118 115 112 102 82 81 bytes

    Saved 1 byte thanks to ETHproductions

    Chosen values:

    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
    -----------------------------------------------------------------
    10 10 11 14 10 10 15 15 11 14 10 10 15 15 11 14 10 10 15 15 10 11
    
    • Prompts for the lower bound, then for the upper bound (e.g. 0x04 / 0x0f).
    • An invalid lower bound will be interpreted as 0x00 (minimum value).
    • An invalid upper bound will be interpreted as 0x15 (maximum value).
    • Outputs nothing if the lower bound is greater than the upper bound.

    alert((1/7+'789').replace(/./g,(v,i)=>i<a|i>b?'':(v|10)+' ',p=prompt,b=p(a=p())))

    Previous version (97 bytes)

    Generating a pseudo-random list of 'true' hexadecimal values:

    alert((1/7+'789').replace(/./g,(v,i)=>i<a|i>b?'':(v*7|16).toString(16)+' ',p=prompt,a=p(),b=p()))
    

    Sequence:

    10 10 17 1c 1e 38 33 31 17 1c 1e 38 33 31 17 1c 1e 38 33 31 38 3f
    

    Arnauld

    Posted 2016-10-01T08:45:07.950

    Reputation: 111 334

    "message": "Uncaught SyntaxError: Invalid destructuring assignment target" – None – 2016-10-01T10:57:46.223

    @frayment - This is Chrome, right? That's weird because it doesn't complain about [a,b]=prompt().split(' ') in the command line. Anyway, my updated answer should fix that. – Arnauld – 2016-10-01T11:08:30.963

    Well done! Works now. Thats weird that Chrome does it. I tested it on your JS tester, and in my Developer console. Same error. Welcome to the leaderboard. – None – 2016-10-01T11:09:17.663

    You could save some bytes with inputs like 0x04 – Hedi – 2016-10-01T11:15:34.073

    @Hedi - I was actually editing my answer accordingly when you posted your comment. :-) However, the challenge says "recognize a hexadecimal", so I'm not sure if we're allowed to do so. – Arnauld – 2016-10-01T11:21:11.917

    It doesn't need to recognise the decimal. It can automatically assume a user is inputting a decimal, so you don't have to check if they didn't. That is undefined behaviour and can simply be ignored like the rules state. – None – 2016-10-01T11:23:06.457

    Also check my answer in C, I don't bother checking for cast-errors. – None – 2016-10-01T11:23:22.027

    @frayment Would list of values be fine ? 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25
    If it is then ++i*83&255 could be replaced by 16+i
    – Hedi – 2016-10-01T11:50:14.933

    @Hedi As long as there are only 22 values, they can be anything in your wildest imagination. – None – 2016-10-01T11:54:17.483

    1Dude, theres nothing wrong with your alternate, it works fine here and is within the rules. Update your post! :) – None – 2016-10-01T12:58:24.800

    You can probably do b=p(a=p()) to save a byte. – ETHproductions – 2016-10-01T20:14:44.243

    2

    JavaScript (ES6), 107 152 137 bytes

    p=prompt,f=(a=+p(),b=+p(),[x,y,...s]='FFF4B6D7402011A4F0D0FF3D9C2165C4A22890E7D6A5')=>a?f(a-1,b-1,s):x+y+' '+(b?f(a,b-1,s):'');alert(f())
    

    var
       p=prompt,f=(a=+p(),b=+p(),[x,y,...s]='FFF4B6D7402011A4F0D0FF3D9C2165C4A22890E7D6A5')=>a?f(a-1,b-1,s):x+y+' '+(b?f(a,b-1,s):'');alert(f())
    ;
    
    //input 0x04 then 0x14 will print 40 to D6
    //input 0x00 then 0x00 will print FF
    //input 0x13 then 0x17 will print E7 D6 A5 NaN NaN

    Chosen values:

    FF F4 B6 D7 40 20 11 A4 F0 D0 FF 3D 9C 21 65 C4 A2 28 90 E7 D6 A5
    

    Inputs:

    • Input format is 0x14
    • If any input is negative or the 1st input is greater than the 2nd : InternalError: too much recursion
    • Will print NaN for out of bounds.

    Previous solutions:
    152 bytes:

    i=parseInt,p=prompt,f=(a=i(p()),b=i(p()),[x,y,...s]='FFF4B6D7402011A4F0D0FF3D9C2165C4A22890E7D6A5')=>a?f(a-1,b-1,s):x+y+' '+(b?f(a,b-1,s):'');alert(f())
    

    107 bytes, invalid solution (inputs missing):

    f=(a,b,[x,y,...s]='FFF4B6D7402011A4F0D0FF3D9C2165C4A22890E7D6A5')=>a?f(a-1,b-1,s):x+y+' '+(b?f(a,b-1,s):'')
    

    Hedi

    Posted 2016-10-01T08:45:07.950

    Reputation: 1 857

    1Close! But you need to be able to ask the user for input. I like what you did with console.log(...) though. ;) – None – 2016-10-01T10:05:04.930

    @frayment var and the last ; are not part of the answer. Its just for the snippet, that's why I added linebreak. I'll edit the answer. – Hedi – 2016-10-01T10:46:23.673

    My bad @Hedi, sorry about that. – None – 2016-10-01T10:47:49.190

    2

    Python, 88 87 86 bytes

    1 byte save thanks to @JonathanAllan
    1 byte save again to @JonathanAllan

    Also changed the base of the code, much nicer now.

    a,b=[int(x,16)for x in raw_input().split()];l=[0]*22
    while a<=b:print"%02x"%l[a],;a+=1
    

    Chosen values: 00 for everything.

    Same idea as my C answer. This time however, the code takes a single input from the user, requiring a space between both values, split them, cast them to hex values, and print every hex in the l array including and between the two inputted values. Since Python has a magnificent error-catching system, no buffer overflows are present and the code is therefore much more secure. The program is safe from undefined behaviour in a sense that it will not execute when a higher value is submitted before a lower value.

    This should work on both Python 2.x and 3.x; Please correct me if I am wrong, as I don't have access to both interpreters due to my system not supporting both of them.

    user49188

    Posted 2016-10-01T08:45:07.950

    Reputation:

    1

    C, 176 175 161 bytes

    1 byte save thanks to @JonathanAllan
    Massive help thanks to @Downvoter for saving me 14 bytes!

    int main(){int a[44]={0};char s[2];scanf("%s",s);int b=(int)strtol(s,0,16);scanf("%s",s);int c=(int)strtol(s,0,16);while(b<=c){printf("%d%d ",a[b],a[b+1]);b++;}}
    

    Try it online!

    Chosen values: 00 for everything.

    Un-golfed answer:

    int main() {
        int a[44] = {0};
        char s[2];
        scanf("%s", s);
        int b = (int) strtol(s, 0, 16);
        scanf("%s", s);
        int c = (int) strtol(s, 0, 16);
        while (b <= c) {
            printf("%d%d ", a[b], a[b+1]);
            b++;
        }
    }
    

    The trick to this, is taking in two inputs and attempting to convert them to hexadecimal strings and then cast to integers. Since there is no error-checking or anything likewise, undefined behaviour is simply throwing errors and breaking the program. The user needs to enter two inputs, however my Eclipse CDT compiler seems to let me input them both on the same line with a space between.

    They must be in the correct order, as requesting a bigger value before a smaller value will not run the while-loop at all.

    The thing is, there is also no buffer-overflow protection, so I can simply request something absurd such as a range from $0 to $FFFF, and I will get everything in my computers memory from the beginning of the allocation of memory for the a[44] array, all the way to 65536 values later.

    user49188

    Posted 2016-10-01T08:45:07.950

    Reputation:

    A single whitespace character in the input format matches any amount of whitespace in the input stream, although most scanf formats skip whitespace anyway, speaking of which, why not cut out the middle man and use %x directly? – Neil – 2016-10-01T16:34:09.743

    Why not use char s[2] instead of the malloc stuff? Casting malloc's return value isn't necessary in C anyway. – cadaniluk – 2016-10-02T10:39:37.180

    @Neil If your talking about the printf("%d%d ", ...) part, by replacing the formatting with simply %x only returns 0's instead of 00's, and doesn't space them out. – None – 2016-10-02T23:49:08.237

    @Downvoter Thankyou very much! I didn't think of that. Editing answer now. – None – 2016-10-02T23:50:06.927

    No, I'm still talking about the scanf. – Neil – 2016-10-03T00:08:30.623

    1

    PHP, 106 105 104 96+2 bytes

    eval($s='for($a=a;$a++<c;)$$a=hexdec($argv[++$i]);while($b<=$c)printf("%02X ",ord($s[$b++]));');
    

    or

    eval($s='for($a=a;$a++<c;)$$a=hexdec($argv[++$i]);');while($b<=$c)printf("%02X ",ord($s[$b++]));
    

    Run with php -nr '<code>' <lowindex> <highindex>; escape the single quotes in the code.
    ... or test it online.

    dechex interpretes input as hexadecimal strings as far as characters are hex digits,
    0 if the input starts with something else.

    prints nothing if first value is larger than second.

    chosen values:

    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
    -----------------------------------------------------------------
    66 6F 72 28 24 61 3D 61 3B 24 61 2B 2B 3C 63 3B 29 24 24 61 3D 68
    

    (first 22 ascii codes of the executed code)

    or

    for($a=a;$a++<c;)eval($s='$$a=hexdec($argv[++$i]);');while($b<=$c)printf("%02X ",ord($s[$b++]));
    

    with these values:

    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
    -----------------------------------------------------------------
    24 24 61 3D 68 65 78 64 65 63 28 24 61 72 67 76 5B 2B 2B 24 69 5D 
    

    Titus

    Posted 2016-10-01T08:45:07.950

    Reputation: 13 814

    Do answers normally incorporate the <?php chunk? – None – 2016-10-01T12:48:04.993

    @frayment not if you use -r. And if I need to store it to a file, I use the short open tag <?. – Titus – 2016-10-01T12:52:11.330

    Constants a, z, and ProgramingPuzles_CGolf are undefined. Where did ProgramingPuzles_CGolf come from anyway? :/ – None – 2016-10-01T13:08:26.690

    @frayment Those are notices. Reroute stderr to /dev/null if you don´t like them. PHP evaluates the undefined constants to strings. – Titus – 2016-10-01T13:32:26.270

    But their coming up as Syntax Errors, I can't run the program. – None – 2016-10-01T13:37:50.547

    @frayment: what PHP version? Try putting them in double quotes. – Titus – 2016-10-01T14:17:27.157

    PHP 7.0 I'll try later, going out right now. – None – 2016-10-01T22:01:20.290

    1

    Perl, 79 45 41 bytes

    "min value $10" - the example has minimum of $00- is that a typo?

    Here's a rather boring perl answer in 41 bytes (Was 46 and then I kept seeing spaces, parens I could elide). Takes input in two lines.

    printf'%02X ',$_ for(4..26)[hex<>..hex<>]
    

    The data is a list 04..1A

    Before I was being too clever with pack & unpack. Its input bytes are entered at once smushed together, eg "020E' will print the 2nd-14th entries

    printf'%02X ',$_ for sub{(4..26)[shift..shift]}->(unpack'CC',pack'H4',<>)
    

    Might try golfing it more using all 0's, substr, and printf'%*vX' ... nope that is making my answer longer. 48 characters (using a string of ascii '7', hex 37 as the data)

    printf'%*vX',' ',substr 7x22,$s=hex<>,1+hex<>-$s
    

    Yary

    Posted 2016-10-01T08:45:07.950

    Reputation: 11

    1

    Scala, 45 bytes

    (_:Int)to(_:Int)map(x=>f"$x%02X")mkString " "
    

    Ungolfed:

    (a:Int,b:Int)=>a.to(b).map(x=>f"$x%02X").mkString(" ")
    

    Uses 00 to FF as values, but works up to 2147483647.

    corvus_192

    Posted 2016-10-01T08:45:07.950

    Reputation: 1 889

    error: ')' expected but string literal found. at a.to(b).map( – None – 2016-10-02T23:56:04.213

    Don't know if it's just me or what. :/ What should I try running it in? – None – 2016-10-02T23:56:23.557

    @frayment that's probably because of the string interpolation, which were introduced in Scala 2.10.0 – corvus_192 – 2016-10-03T03:34:39.780

    So which version did you build this in? 2.9? – None – 2016-10-03T04:44:09.490

    @frayment I used the 2.11.7 REPL – corvus_192 – 2016-10-03T04:56:01.360

    1

    C++, 98 95 93 bytes

    #include <iostream>
    int _[22],a,b;int main(){for(std::cin>>a>>b;b/a++;)printf("%02x ",_[a]);}
    

    My chosen values are all 0's

    Fatih BAKIR

    Posted 2016-10-01T08:45:07.950

    Reputation: 111

    Welcome to Programming Puzzles & Code Golf! This is a well-golfed answer, but I don't think it meets the requirements of the challenge. Would you mind including your 22 chosen hexadecimal values? – ETHproductions – 2016-10-02T01:40:13.653

    Nearly there! The only problem is, when I entered values 04 and 06, I only got two values back. I'm suspecting these are the 05 and 06 values. You need to provide all values between and including the inputted values. – None – 2016-10-02T23:46:15.813

    1@frayment, oh that's right, fixed it! – Fatih BAKIR – 2016-10-03T11:24:28.200

    0

    Apple II 6502 assembly, 75 bytes

    Byte code:

    A9 46 85 36 A9 10 85 37 A0 00 98 20 DA FD A9 A0 
    20 ED FD C0 42 D0 F3 20 93 FE A2 FC 20 1B FD 9D 
    04 01 E8 D0 F7 86 31 A9 8D 8D 04 02 20 A7 FF B5 
    3C 0A 75 3C 95 3C CA 10 F6 A6 3D BD 05 02 20 ED 
    FD E8 E4 3C D0 F5 99 05 02 C8 60

    Disassembly:

      LDA    #<+
      STA    CSWL
      LDA    #>+
      STA    CSWH    ;redirect stdout
      LDY    #$00
    - TYA
      JSR    PRBYTE  ;print number
      LDA    #$A0    ;space
      JSR    COUT    ;print space
      CPY    #$42    ;22*3
      BNE    -
      JSR    SETVID  ;restore stdout
      LDX    #$FC
    - JSR    KEYIN   ;fetch a key
      STA    $0104,X ;store to $200+
      INX
      BNE    -       ;four keys
      STX    MODE    ;set internal flags
      LDA    #$8D
      STA    $0204   ;set key delimiter
      JSR    GETNUM  ;convert keys to hex values
    - LDA    A1L,X   ;fetch value
      ASL
      ADC    A1L,X   ;multiply by 3
      STA    A1L,X   ;store value
      DEX
      BPL    -       ;both inputs
      LDX    A1H     ;first input
    - LDA    $0205,X ;fetch from index
      JSR    COUT    ;print character
      INX
      CPX    A1L
      BNE    -       ;until second input
    + STA    $0205,Y ;fall through to save a byte
      INY
      RTS

    It forms an array in memory that looks like the output. The chosen values are:

    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
    -----------------------------------------------------------------
    00 03 06 09 0C 0F 12 15 18 1B 1E 21 24 27 2A 2D 30 33 36 39 3C 3F

    User presses four keys to set the inputs.

    peter ferrie

    Posted 2016-10-01T08:45:07.950

    Reputation: 804

    Oooo using Apples own code. Very nicely done. – None – 2018-03-18T09:33:23.140

    0

    CJam, 22 bytes

    {r:~Gb}2*37m!s2/\)<>S*
    

    Chosen values:

    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15
    -----------------------------------------------------------------
    13 76 37 53 09 12 26 34 50 46 31 59 79 58 15 80 90 24 00 00 00 00
    

    Try it online

    Neorej

    Posted 2016-10-01T08:45:07.950

    Reputation: 179

    0

    GNU sed, 209 + 1(r flag) = 210 bytes

    1{h
    s:.*:,00 FF,01 F4,02 B6,03 D7,04 40,05 00,06 00,07 A4,08 F0,09 00,0A FF,0B 0D,0C 9C,0D 21,0E 65,0F C4,10 02,11 28,12 90,13 E7,14 D6,15 A5:
    H;d}
    G;s:\n(.*)\n.*(,\1.*):\n\2:
    s:(.*)\n(.*,\1 ..).*:\2:
    s:,..::g
    

    Try it online! One leading space is present in the output, I hope it's allowed.

    Run examples:

    me@LCARS:/PPCG$ echo -e "06\n0F" | sed -rf table_lookup.sed
     00 A4 F0 00 FF 0D 9C 21 65 C4
    me@LCARS:/PPCG$ echo -e "13\n13" | sed -rf table_lookup.sed
     E7
    

    Explanation: the 22 hexadecimal values stored are the same as the ones from the OP's example

    value | FF F4 B6 D7 40 00 00 A4 F0 00 FF 0D 9C 21 65 C4 02 28 90 E7 D6 A5
    -------------------------------------------------------------------------
    index | 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15
    

    The start and end indexes are read on separate lines. The output is a single line with the table values in that index range (inclusive). Undefined input will write multiple lines of invalid output.

    # store START index in hold space
    1{h
    # generate the table
    s:.*:,INDEX1 VALUE1,INDEX2 VALUE2,°°°:
    # append table to hold space and delete pattern space
    H;d}
    # read END index, append hold space (pattern space format is: END\nSTART\nTABLE)
    G
    # delete table entries up to, but excluding, the START index (END\nTABLE')
    s:\n(.*)\n.*(,\1.*):\n\2:
    # delete table entries starting from, but excluding, the END index (TABLE'')
    s:(.*)\n(.*,\1 ..).*:\2:
    # remove the indexes and print (implicitly) the resulting values
    s:,..::g
    

    seshoumara

    Posted 2016-10-01T08:45:07.950

    Reputation: 2 878