29
1
The Compiler Language With No Pronounceable Acronym, abbreviated INTERCAL, is a very unique programming language. Among its unreproducible qualities are its binary operators.
INTERCAL's two binary operators are interleave (also known as mingle), and select. Interleave is represented with a change (¢), and select is represented with a sqiggle (~).
Interleave works by taking two numbers in the range 0-65535 and alternating their bits. For instance:
234 ¢ 4321
234 = 0000011101010
4321 = 1000011100001
Result: 01000000001111110010001001
Output: 16841865
Select works by taking two numbers in the range 0-65535, taking the bits in the first operand which are in the same position as 1s in the second operand, and right packing those bits.
2345 ~ 7245
2345 = 0100100101001
7245 = 1110001001101
Taken : 010 0 10 1
Result: 0100101
Output: 37
In this challenge, you will be given a binary expression using either the interleave or select operation. You must calculate the result, using the fewest possible bytes.
The expression will be given as a space separated string, consisting of an integer in 0-65535, a space, either ¢ or ~, a space, and an integer in 0-65535.
Input and output may be through any standard system (STDIN, function, command line, etc.). Standard loopholes banned.
Examples:
5 ¢ 6
54
5 ~ 6
2
51234 ¢ 60003
4106492941
51234 ~ 60003
422
This is code golf - fewest bytes wins. Good luck.
EDIT: Since some languages do not support INTERCAL's change (¢) symbol, you may use the big money ($) symbol instead, at a 5 byte penalty.
I was going to suggest doing this in INTERCAL, then I saw Standard Loopholes banned. Damn! Can we use a symbol other than the "change" symbol for the interleave operator? The symbol given is not ASCII, which will be a problem for some languages. According to the linked wikipedia page
$andchave been used. – Level River St – 2015-08-10T08:07:16.2601@steveverrill I adressed the non-ASCII issue. Using INTERCAL is fine, as long as you take the input from STDIN. INTERCAL has no other concept of a string. – isaacg – 2015-08-10T08:27:14.037
10It's a bit harsh penalising people for the use of the dollar sign. That is something that cannot be helped. – Beta Decay – 2015-08-10T11:14:04.520
1@BetaDecay I don't want submissions which use the wrong symbol just because it saves a single byte - I only want languages that really need to use the
$to do so. – isaacg – 2015-08-10T11:17:08.0772@isaacg Well why don't you just penalise them for the number of times they use a dollar sign instead of a cent sign? – Beta Decay – 2015-08-10T11:18:48.627
9I just realized that CLWNPA is perfectly pronouncable in Welsh. The W is pronounced as U in Spanish or OO in English. – Level River St – 2015-08-10T11:58:23.023
9I don't get the 5 byte penalty. C-INTERCAL uses the
$. – kirbyfan64sos – 2015-08-10T14:42:06.0172Is ¢ as ASCII 155 (per the old Codepage 437) OK? If so I can remove the penalty. I'm told it works, but I am having difficulty making it work on my own (Spanish) computer due to operating system issues. C doesn't properly support the unicode value 0x00A2. BTW @betadecay, your suggestion would suit me perfectly, as none of the operator symbols appear in my code, heheh! – Level River St – 2015-08-10T16:42:49.220
13What are you all arguing about? A $ is clearly more expensive than a ¢. What, you want 99¢ for nothing? – Max – 2015-08-10T20:15:47.610
6I didn't think INTERCAL would allow you to input numbers with decimal numerals. Don't you have to write
FIVE ONE TWO THREE FOUR? And shouldn't the output be in Roman numerals? – Nate Eldredge – 2015-08-10T22:01:13.6733@NateEldredge The challenge is to implement a feature of INTERCAL, not the whole language. That horrible input format rather neatly means that in this case there is no need to invoke the standard loophole about emulating a language with the language itself. To answer the challenge in (original) INTERCAL (or CLaWNPA / CLOWNPA as I like to call it) you would have to write code for parsing decimal numbers. Some modern variants apparently have easier I/O, but I couldn't find one that takes decimal input. – Level River St – 2015-08-10T23:22:35.870