JavaScript Puzzle

Some parts of the string on the left of the following expression have been redacted. Fill them in such that that the entire expression evaluates to true.

javascript_line_enlarged

(And yes, it is one string. None of the black boxes hide a ” character.)

Have fun!

Advertisements

Respect to Sandwich

For a couple of years, I’ve had the idea of starting a comic strip called Vi, Max, and Nona, of which one of the characters, Nona, is a cartoonist who writes comics involving talking programming languages. It became gradually clear that there’s no way I have time in my life for making this idea fully become reality, but here’s a flushing out of one of the ideas for Nona’s comic.

nona0

Phonetic Alphabets

A as in aisle
B as in bdellium
C as in cnidocyte
D as in djinn
E as in ewe
F as in faze
G as in gnarl
H as in heir
I as in iamb
J as in jicama
K as in know
L as in lech
M as in mnemonic
N as in night
O as in ouija
P as in pneumatic
Q as in quiche
R as in rite
S as in scent
T as in tsunami
U as in upend
V as in vier
W as in whole
X as in xi
Y as in yin
Z as in zhug

A as in Android
B as in big-endian
C as in Coke
D as in dogs
E as in emacs
F as in Firefox
G as in gif
H as in Haskell
I as in Iron Man
J as in Jacob
K as in Kirk
L as in left side of the road
M as in Mac
N as in 9gag
O as in Oxford comma
P as in physics
Q as in QWERTY
R as in red
S as in semicolon
T as in Taiwan
U as in under the toilet paper holder
V as in Valor
W as in Wolverines
X as in Xbox
Y as in Yankees
Z as in 0∈ℕ

A as in ayyy
B as in bee
C as in cede
D as in deed
E as in eeee
F as in fee
G as in gee
H as in he
I as in I
J as in jay
K as in kay
L as in lee
M as in me
N as in need
O as in oh
P as in pee
Q as in queue
R as in reed
S as in see
T as in tee
U as in unit
V as in veal
W as in why
X as in x-ray
Y as in you
Z as in zed

JavaScript Test

For each item except 37 and 38, answer what the JavaScript expression evaluates to. If the expression throws an exception or error upon evaluation, indicate which exception or error is thrown.

Part A. One Divided by Zero

> 1/0
1. ______
> 1/-0
2. ______
> -1/-0
3. ______

Part B. Two Arrays Walk into a Foo

> []+[]
4. ______
> []-[]
5. ______
> []*[]
6. ______
> []/[]
7. ______
> []%[]
8. ______
> []<[]
9. ______
> []==[]
10. ______
> []<=[]
11. ______
> []<<[]
12. ______
> []>>[]
13. ______

Part C. Fifty Shades of Zero

> 0==””
14. ______
> 0==”0″
15. ______
> “”==”0″
16. ______
> 0+”0”
17. ______
> 0-“0”
18. ______
> 0==[]
19. ______
> []==0
20. ______
> 0==[0]
21. ______
> “0”==[0]
22. ______
> “0”==[“0”]
23. ______
> [0]==[“0”]
24. ______
> 0==[“0″]
25. ______
> [0]+[0]
26. ______
> [0]-[0]
27. ______
> [0]*”0”
28. ______
> []+{}
29. ______
> {}+[]
30. ______
> {}-[]
31. ______
> {}=={}
32. ______
> 0=={}
33. ______
> {}==0
34. ______
> 0=={0:0}
35. ______
> [0]+{0:0}
36. ______

37. What type is the result of []+{}+0, that is, adding the empty array, the empty object, and 0?
a. array
b. object
c. integer
d. number
e. this expression SyntaxErrors
f. none of the above

38. If you didn’t select e above, what exactly does []+{}+0 evaluate to? If you selected e above, what is the token that the SyntaxError complains about?

Part D. Array Operations

> var foo = [20, 5, 15, 10]
> var bar = foo.reverse()
> foo
39. ______
> bar
40. ______
> var foo = [20, 5, 15, 10]
> var bar = foo.sort()
> foo
41. ______
> bar
42. ______
> var foo = [20, 5, 15, 10]
> var bar = foo.concat([5])
> foo
43. ______
> bar
44. ______
> var foo = [20, 5, 15, 10]
> var bar = foo.concat(5)
> foo
45. ______
> bar
46. ______

Part E. Parsing to Integer

> parseInt(“10”)
47. ______
> parseInt(“1/0”)
48. ______
> parseInt(“10”,8)
49. ______
> parseInt(1/0,8)
50. ______
> parseInt(1/0,12)
51. ______
> parseInt(1/0,16)
52. ______
> parseInt(1/0,20)
53. ______
> parseInt(1/0,24)
54. ______
> parseInt(1/0,28)
55. ______
> parseInt(1/0,32)
56. ______
> parseInt(1/0,36)
57. ______
> parseInt(1/0,40)
58. ______

To check your answers (since there’s some pretty involved arithmetic here): out of your answers to items 50 through 58, the sum of your answers that are integers should be 43 mod 127 and 41 mod 151.

Part F. Putting it All Together

javascript_function

In case this “reassuring” disclaimer may be necessary: There are no typos in the writing of this function. Every single character (or lack thereof) is intentional for the purposes of the following items.

> quux(2,4,5)
59. ______
> quux(100,[“foo”],”foo”)
60. ______
> quux(0,0,0)
61. ______
> quux(0,0)
62. ______
> quux(0)
63. ______
> quux()
64. ______
> quux(0,0,0,0)
65. ______
> a
66. ______
> b
67. ______
> c
68. ______
> d
69. ______
> e
70. ______
> f
71. ______
> 0+quux
72. ______

As a final check of your work, exactly 7 of these 72 expressions throw an exception or error upon evaluation. You have exactly 7, right?

Continue reading “JavaScript Test”

How I Generate My Passwords, and Why, Fuck You Apple

What is much more problematic than using a weak password is using the same password in multiple places.

There’s a gigantic issue with using a new password for each site that you go to, though: you have to memorize that many passwords. You could use a scheme where you use the same base password and then append the name of the site to the end, but that’s really not more secure than just using the same password in each site.

You could decide to use one of those password managers that exist out there. Personally, I find myself unable to believe that I could just trust some external entity with all my passwords and have an expectation they’re all alright. Oh wait, I’m not even paranoid.

Here’s how I generate my passwords. This scheme is actually memorable, and actually produces significantly different passwords.

Here’s all you memorize to cover all of your websites you care about your password in: a string, a hierarchy, and a function.

(Also, there are definitely places you don’t care about your password. Some of them send you your password in plaintext. Don’t even bother making a secure password in those cases.)

1. The String

Any string of length that’s at least some moderately large number.

-sP~m*KsjO04

, for example, is an excellent string. It doesn’t matter that you don’t understand any particular patterns in the string, because there’s only 12 characters in it, and you can easily memorize just one string of 12 random characters.

Continue reading “How I Generate My Passwords, and Why, Fuck You Apple”

Keyboard

Things easier to type on my keyboard than on QWERTY:

the
that
this
have
they
Chen
Google
United States
Massachusetts
Massachvsetts
alpha
beta
red
orange
green
white
teal
grey
earth
air
fire
lorem ipsum
emacs
one
three
four
six
seven
eight
nine
ten
eleven
twelve
lol
quantum
mens et manus
IHTFP
python
SimpleHTTPServer
cd
JQuery
sudo apt-get install
summon
screen -dr
yunith
raven
[::-1]
yes avocado | espeak

Things easier to type on QWERTY than on my keyboard:

QWERTY
word
yellow
black
pink
water
vim
rofl
two
five
Wu
Gmail
Ethiopia
California
AkshajKadaveru
public
private
keyboard
fuck
qw (the hardest two-letter combination to type on my keyboard)
Xi Jinping
zyxyvy
wordpress
bin
tidorn
buzzword-bingo
SIPB
:(){:|:&};:

For a person who is this fond of vim, it’s quite unfortunate that I designed my keyboard before I started using vim.

16-004

Sometimes a heartstring is broken

Sometimes someone sees a heartstring break

Sometimes a heartstring breaks and resounds
And resounds
Resounds

Sometimes someone sees a broken heartstring

Sometimes someone sees a broken heartstring
But does not say

Sometimes someone sees a broken heartstring
But dares not say

Sometimes someone hears a broken heartstring resound
And resound
But does not say
Resound
And dares not say
Does not make a
Resound
Sound

Sometimes someone sees a broken heartstring
And tells the outside that in here
Is a broken heartstring
And no one hears

Sometimes a broken heartstring
Brings silence
And sometimes
Comes for too much silence

Sometimes someone seeks
The broken heartstring

Sometimes someone seeks
The broken heartstring
Because the heart has been silenced away

Sometimes one returns to the innermost heart
To discover that
A broken heartstring is holding up
A desperate bit of freedom
Dangling
Over the gaping void