# Code Crosswords - Solutions

This is the companion question for Code Crosswords. Robber answers go here.

See Where should we put robbers? for meta-info.

# Solution to es1024's C puzzle

I had to fudge a bit on 7-Down by invoking undefined behavior. es1024 has indicated that this use of UB was the intended solution. It will work on most people's computers though. I came up with various expressions achieving the desired result such as -1 << 30, 3 << 30, 6 << 29, and ~(~0U/4) but all of them made it impossible for me to get 5-Across. So I used the Intel architecture-specific property that only the least significant 5 bits are used to determine the size of a left shift. Note that it needs to be ~_ and not ~1 so that the amount to shift by is not a compile-time constant. I tested the expressions with the following code:

#define T(X) _ = c; _ = X; printf("%d\n", _);
z[4] = {9};
int main(c)
{
int _;

T("01"[0])
T(-8)
T(-2)
T(11<-328111)
T(+2+71)
T(9+0)
T(0**z)
T(5;)
T(0<-000)
T(2+~3)
T(!91)
T(!_)
T(2**z)
T('_T;')

T("11"?5*9:2)
T(15<<9)
T(0+22)
T(-211*0-97;)
T(-17*0)
T(3+0<<~_)
T(8+000)
T(+0)
T(42)
T(+!z)
T(~_)
}

• Where does the macro come from? I avoided posting the solution because I couldn't get M-across. – COTO Oct 25 '14 at 22:58
• @COTO I don't understand your question, "Where does the macro come from?" – feersum Oct 25 '14 at 23:29
• Nevermind. I mistook the #define T as a necessary component to your solution. The question remains, though, why does M-across work? Does defining a multiple-character constant just concatenate the byte values? If so, I learned something new today. :) – COTO Oct 25 '14 at 23:34
• @COTO Yes, it is like making a base-256 number. Character literals have type int, so you can put in up to four bytes without loss of information. – feersum Oct 25 '14 at 23:40
• I surely did not know that. (Most likely because anyone who's used it in production code has been strangled to death by the people responsible for maintaining their code.) Props for getting it right. :) – COTO Oct 25 '14 at 23:53

## professorfish, CJam, 41 darks

(This solution actually requires several spaces, so it's not the one professorfish was looking for.)

#K###I#'32
#HDJ*s\ ##
2##2###-
4Zm*##L#3
m##6##]'
f####e##'
#0#'d1+eu
## #!####9
## '{;'"'m
C5(#}####q


That was great fun. Note that the # beneath the 6 is actually code and not a dark cell. Let's go through this:

### Across

Hint 2: [[4 3]]. This was one of the trickier ones, because I really got stuck on trying 4Z]] or similar. Turns out you can use the Cartesian product m* on stuff that isn't an array, and it will make an array for you. So here it is:

4Zm*


Hint 4: 24717. By the time I got to this, the H, J, s and trailing space were already in place. The H gave away that I could probably just reuse the 17 and do \ at the end. The J pushes a 19 and 247 == 13 * 19, so:

HDJ*s\


Hint 7: 32. There are a bunch of ways to do this: Y5#, 3 2, ZY, YZ\, 4(2, 2)2, '32. I went with the last one, because starting with a character seemed promising for 7-down, and that turned out to be right.

Hint 8: E. I already had the 'd when I got there, so it was between choosing 'd1+eu, 'deu1+ or a variant where I used ) and a space instead of 1+ (for the non-CJam people, this taking the d character and increment and upper-casing it, in either order). However, the u in the final column looked useful for A-down. So I picked the first of those. In the end, 'd) eu would have worked, too.

Hint 9: "". Well, this had to be "empty string, get string representation, push a space". But also needed the  for string representation in 7-down, and a space in A-down seemed useful, too, so I chose

]'


Note that ] might also have been one of LMOQR.

Hint B: "m. I just really had to fit this one in with the rest, but there were few characters that mattered. I already had the { and the m. So instead of using a block, I turned { into a character, discarded it, and then pushed the two required characters:

 '{;'"'m


Hint D: 124. I solved this one together with C-down, which was easiest with a decrement at the end. So I push a 12, a 5, and decrement the latter:

C5(


### Down

Hint 1: [2 2 2 3]. That looked too suspiciously like a prime factorisation for it not to be one. :)

24mf


Hint 3: 3010936384. Factoring this showed that it's actually 386. The only question was how to get the 38 in compliance with 2-across. In the end I needed a * in the third place, so doubling 19 it was:

J2*6#


Hint 5: 2017. Two characters for such a large number? Just use built-in two-digit variables:

KH


Hint 6: "18". I think there's only a single way to do this in 3 characters. Use the built-in 18, convert it to a string, and then to its string representation.

Is


Hint 7: ' "\"\"". Probably the hardest part of the puzzle. In particular, I needed to get the "\"\"" in only three characters. The trick was to get the string representation of the empty string twice. That led to:

' L+


THe + isn't necessary, but was needed by 8-across.

Hint 8: !{}. The block needed to go in the code, so that left only two characters for !, which meant using another literal:

'!{}


Hint A: -3u3. With the u in place from 8-across, I started to put -3 and 3 in the corners where no other hint cared about them. But then I needed an m at the bottom. I think there are multiple ways to get a 3 with _m_, but the simplest was taking the square root of 9:

-3 'u9mq


Hint C: -1. I already had the decrement there, so I just put a 0 where no one else cared about:

0  (


Hint E: Stack: "". Well that was the simplest one. Just call the debugger:

ed

• Calvin's Hobbies has spoken, the answer is valid. I'll edit it into my post – user16402 Oct 25 '14 at 19:18

COTO, Javascript ES4, 37 Darks

 __________
|{}=51###6#|
|a##.#I-9<4|
|:##-##"#<#|
|5+Math.PI#|
|}##+##.#+#|
|["9"+0][0]|
|'##p##"###|
|a+-a#a=-10|
|'##c##=###|
|]##"\x48I"|
¯¯¯¯¯¯¯¯¯¯

• 6 across is 5+Math.PI or Math.PI+5; but the latter would leave 'M' and 'h' crossing over into other expressions, seemed unlikely.
• A across had to be a string; with 4 in the middle it looked like an escape, the only way you have room for that is with "\x48I".
• 2 down now ends in a string, so probably is "pac" appended to a number; we'll come back to that.
• 8 ac is now xxxa, evaluating to zero, so -a+a? a+-a? 3+-a? a+-a looked best since it gave me what looked like a char in a string in 1dn.
• 1 down contained :5, which could only be legal grammar in {x:5}xxa'x. Since the value returned is 5, it must be pulling it out of the object, so {x:5}['a'], which means the final missing character is also a: {a:5}['a']
• 1 across now has { at the start. I guessed this was a red herring assignment, tried t={}=51, and it worked. Did not know that!
• 2 down now has 5xxax"pac"=>"2pac". This has to be 5-a+"pac", somehow, so the second char has to be '.' for the floating point literal.
• 7 ac is now [xx"xxxx], returning "90". So this has to be an array literal with the value pulled out; there's only room for one value so we have [xx"xx][0]. There's not room for two strings in there, but either "9"+0 or 9+"0" fit.
• 3 dn; 3072 is 3*1024; the power of 2 is suspicious, and I already had 'I' in there blocking other ways of getting large numbers (like 1eX). So, guessed bitshift; 6<<I turned out to be the answer, leaving +0 to add on to the end.
• 4 ac now contained a comparison operator; and the second char had to be a valid unary operator (to fit in after both 't=' and 'I'). I guessed '-', and there's several possible solutions left (I-I<4, I-6<4, etc)
• 5 dn now contained -x..]xxx4. The ".." threw me - there's only a couple of ways that can be legal syntax and is why I asked if ES4 is what was intended - was this some odd feature of that abandoned spec? But then I saw that this was a red herring; -"" is NaN, so -"..]"xx4 must be what's there - a comparison to NaN, returning false; '==' will do, but need to look at the last answer for confirmation...
• 9ac had several possible solutions, but the restriction on characters that would be allowed for 5dn made me think this was yet another red herring assignment; something =-10. To be honest I also looked at the earlier version of 9dn, and realised that must be something =top (to get a Window back). The variable assigned to could be a or I, it doesn't matter.

Tricky puzzle!

# grc's Python puzzle

For all the lengthy floating-point expressions, I made a C++ program to generate Python mathematical expressions by force and evaluates them. It assumes all numbers are floating-point and only supports operators +, -, *, /, //, **, and ~. I used it to get every clue longer than 5 characters except a**9*27%b and the hash. With 6 or less blanks it finishes within a couple of seconds, while there is a bit of a wait for 7.

# Solution to COTO's MATLAB puzzle

I guess I golfed this one pretty well, as there are 14 spaces.

This test script:

g=4;
o=magic(3);
D=@disp;

D(max([  2]));
D( i^3);
D(o^0);
D(6 -7+eye  );
D((i));
D(.1  ^5* g );
D(~2);
D(diag(~o)  );

D(asin (1)*i);
D((93+7) +~g);
D(  10e15);
D(2*ones (2));
D(02 ^  9 );
D(-i );
D(~o);


produces the following output:

     2

0 - 1.0000i

1     0     0
0     1     0
0     0     1

0

0 + 1.0000i

4.0000e-05

0

0
0
0

0 + 1.5708i

100

1.0000e+16

2     2
2     2

512

0 - 1.0000i

0     0     0
0     0     0
0     0     0
`
• Good show. A few spaces I didn't expect, but there are also quite a few in the key. I'll post that now. ;) – COTO Oct 26 '14 at 22:52