## Tuesday, February 7, 2012

### Why I hate programming (part 4 of n)

back to R:

1. Writing some code, seemed a bit slow, looked to stack overflow for help:

reason: R's wiki page is dead

2. Populating a matrix from a vector. (In R, a matrix is different from an array is different from a vector.)

vec <- 1:9
mat <- as.matrix(vec, nrow = 3, ncol = 3)
# mat is 9x1 (silent fail on invalid arguments nrow and ncol)
mat2 <- matrix(vec, nrow = 3, ncol = 3)
# mat2 is 3x3

3. How big is my vector?

vec <- 1:9
mat2 <- as.matrix(vec, nrow = 3, ncol = 3)
nrow(vec) # NULL
nrow(mat2) # 3
NROW(vec) # 3
NROW(mat2) # 3

## Saturday, August 27, 2011

### USPC 2011

Well, it just wouldn't be a USPC without a roundup. (see also USPC 2010, USPC 2009, USPC 2008, USPC 2007)

1. Battleships
Ugh, I spent too much time running around in circles, trying to figure out where to place the cruisers. Somehow I got it into my head that I needed one in the leftmost column, because they couldn't fit in the rightmost two columns. I ended up printing out this page three times, making the same deductions before finally solving it.

2. Sudoku
Ok going at first, but then I got stuck, so I did a little bit of guessing and worked it out. Slower than I like, but not as bad as Battleships.

3. Crossied Countries
No problems here.

4. Barn Storm
For some reason, I thought had one less difference than I had found and wasted a few minutes trying to find an 11th!

5. Easy as ABCD
More information than I was used to (compared to the Mensa Blue Book), but also larger than the ones I had practiced on. After a few initial deductions, I did a little bit of guessing and got it completed.

6. Times Like These
Tried fiddling with the first row for a bit, and then looked at the third row. The 7 there needs to be either the tens digit in the product or the ones digit of one of the multiplicands. Some quick checking yielded 2x6x7=84. Cross-referencing the columns, I got the placements, filled in the first column, and then the rest.

7. Masyu
Did as much logic stuff as I could, most notably the top-left and bottom-left corners, then did some pencilwork for filling in the rest.

8. Square Count
More or less ok, but missed 2 of the A=2 diagonal squares, so only partial credit.

9. Crack It On
Worked on breaking the right side first, since it required at least three words beginning with the same letter. Some trial and error with the remaining words got the left side.

10. Flash Cards 1
Mostly trial and error, working with different digits for the single in the product.

11. Flash Cards 2
Quickly realized that the denominator needed to factor into two single digits for the flip, and only a few possibilities existed among the digits (32, 36, 27, 63, no right side up 8 or 9 for 72 to work).

12. Takeout
Pretty straightforward.

13. Corral
Not bad, but slower than usual, esp. trying to figure out whether the central mass in the 7th row needed to break out right or left.

14. Blocks (solved after time)
Easy deduction of the square and 4-long piece. Then a dead-end in the bottom-right yielded one more. Worked out a Hamiltonian path in the middle-left that seemed likely, and made placements from there.

15. Hex Words
Still working on it.

16. Word Connection (solved after time)
The two "P"s and two "T"s were good for fixing September/April and October/August, respectively, and then just needed to fit the rest in.

17. Hopper (solved after time)
Not as bad as Tom Snyder's practice. The second 1 didn't leave a lot of choices, and I stopped trying to make it too compact, since it needed to be a unique fit for 8x8.

18. Corral Crates
Still working on it. Doesn't seem too bad, if larger than Palmer's.

19. Kaku Rogue
Got everything but the top-left and lower-right corners. Not sure of a good way to go about it except to try different numbers until one works. The first time for me that checking column and row sums worked: in this case, for the singleton connecting squares.

20. Jumping Crossword
Still working on it.

21. Hungarian Tapa
Still working on it.

22. Dynasty Sudoku (solved after time)
A long time making deductions, then guessing, only to get a solution that is only slightly wrong with two transpositions and violating the single-connected-space constraint.

Potential points: 170
Expected points: 160 (partial credit on 5.)

Fingers crossed for a good ranking this year.

EDIT: Hex Words isn't bad, once you realize that intersecting words on a hex grid need to have valid words along all three axes. This forces JUDO into the upper-left, and using an efficient packing heuristic for the rest works pretty well.

Corral Crates also wasn't too bad, though I messed up early and had a contradiction. Much of the strategy is the same as for Corral: since each crate cannot touch empty space diagonally, the really useful anti-checkerboard constraint still holds.

Kaku Rogue worked out with more guessing, but I need to check my answer -- Oops, didn't even see the second constraint on exactly one negative number per row and column. Good thing I didn't do this one, I guess!

EDIT 2: Looks like I did miss a 10th difference on Barn Storm, so my total score this year is 154.

Labels: ,

## Wednesday, March 23, 2011

### On Fuzziness

I have debated (with myself) on whether to blog about my (mis-)adventures in tutoring at the City Heights Farmer's Market/Library as part of SIO GDAWG's outreach efforts. I figure it will be ok to simply remark about both the (1) gaps in knowledge (conceptual or otherwise) of the kids and (2) weirdness of homework that these kids bring.

One girl (who came twice, but whom I haven't seen in a month or two) had trouble in her math class. She was taking Algebra I, and somehow had made it through most of the first semester (I'm guessing they started algebra in the Fall) without anyone noticing that she was having basic trouble with arithmetic. For the most part, she could do basic numerical operations, but had a very flaky grasp of order of operations, distributive properties, and negative numbers. (from what I could tell) Needless to say, it was a bit much to ask her to do operations involving linear equations.

One boy (4th grade?) hadn't yet memorized his multiplication tables. Irregardless of this (which isn't uncommon for his age), he didn't understand that multiplication represented repeated addition. The problem with not knowing this concept is that treating multiplication as a black box operation is going to be very bad news for this kid when he starts algebra (see above).

Last week I also helped a kid with some worksheets dealing with St. Patrick's Day (SPD). The first page was basically a crossword with a single clue running vertically that spelled out "leprechaun". Problem is, there were some really vague (and obscure) clues that depended on both awareness that it was SPD-themed as well as the cultural aspects associated with SPD. (Really, how many people will know of the top of their heads that "Emerald Isle" refers to Ireland?)

In the same packet, there was a word association page where one item would be given and two blanks needed to be filled with items from a word box. Unfortunately, some of the examples were synonyms ("wee" -> "little", "small") and some were same-category-membership ("Japan" -> "Mexico", "Japan"). What this demonstrates and what you were supposed to do if you didn't know some of the words (e.g. the kid didn't know what "wee" meant) is beyond me.

On a later page, there were a series of analogies. Besides the fact that analogies were not explained, a lot of the problems violated the standard guidelines for analogies (as they are used in the SAT and other "important" tests). For example, in A:B::C:D, the relationship between A and B should be the same as that between C and D. The analogy should NOT rely on any association between A and C or B and D. (which is what SAT writers like to do to trip people up)

On another page, there were some weird set exclusion problems (e.g. "What are the numbers that are in the square, but not in the triangle and circle?") in reference to a figure. Problematically, the use of language was imprecise: the questions sometimes used "and" and sometimes used "or", when in both cases, the desired conjunction was "nor"!

The busywork nature of the worksheets also seemed weird to me. I guess the standard purpose of homework these days is to occupy time rather than practice what you learned or apply those skills in reasonable useful example situations. I am reminded of Feynman's remarks on science textbooks:
Finally I come to a book that says, "Mathematics is used in science in many ways. We will give you an example from astronomy, which is the science of stars." I turn the page, and it says, "Red stars have a temperature of four thousand degrees, yellow stars have a temperature of five thousand degrees . . ." -- so far, so good. It continues: "Green stars have a temperature of seven thousand degrees, blue stars have a temperature of ten thousand degrees, and violet stars have a temperature of . . . (some big number)." There are no green or violet stars, but the figures for the others are roughly correct. It's vaguely right -- but already, trouble! That's the way everything was: Everything was written by somebody who didn't know what the hell he was talking about, so it was a little bit wrong, always! And how we are going to teach well by using books written by people who don't quite understand what they're talking about, I cannot understand. I don't know why, but the books are lousy; UNIVERSALLY LOUSY!

Anyway, I'm happy with this book, because it's the first example of applying arithmetic to science. I'm a bit unhappy when I read about the stars' temperatures, but I'm not very unhappy because it's more or less right -- it's just an example of error. Then comes the list of problems. It says, "John and his father go out to look at the stars. John sees two blue stars and a red star. His father sees a green star, a violet star, and two yellow stars. What is the total temperature of the stars seen by John and his father?" -- and I would explode in horror.

My wife would talk about the volcano downstairs. That's only an example: it was perpetually like that. Perpetual absurdity! There's no purpose whatsoever in adding the temperature of two stars. Nobody ever does that except, maybe, to then take the average temperature of the stars, but not to find out the total temperature of all the stars! It was awful! All it was was a game to get you to add, and they didn't understand what they were talking about. It was like reading sentences with a few typographical errors, and then suddenly a whole sentence is written backwards. The mathematics was like that. Just hopeless!

Labels: , ,

## Wednesday, March 2, 2011

### bibtex & capitalization

It seems that most of the default bibtex styles convert all non-first letters in titles to lowercase. This is problematic, since of course many papers have proper nouns (e.g. locations, species, named concepts) in their titles! Rather than go through and attach braces "{}" around all letters that need capitalization preserved, it makes more sense to edit the bibtex style file (*.bst) to preserve the title:
If you prefer to edit the bibtex style (.bst) rather than the bibliography (.bib), you can search for occurences of change.case$in it. This is the function that capitalizes or title-izes fields that are not people names. Typically, for the title field, you should find something like title "t" change.case$. Since you want the title unmodified, replace that by just title.

All I needed to do was copy the bibtex style file into the local folder with my tex document, edit it, and re-compile. Voila!

From here.

Labels: , , ,

## Tuesday, February 22, 2011

### Streamlining the workflow

Yes, TexShop's keyboard-command typesetting is nice, but I couldn't figure out a way to get it to run through the whole 4-step process (latex/bibtex/latex/latex) for making a file with cited references with one keystroke.

Lyx will do the whole compilation in one command, but its interface doesn't allow me to edit just the latex code, instead forcing me to use some weird WYSIWYM viewing mode.

Luckily, I found some scripts that will integrate MacTex and TextWrangler.

I still needed a single keystroke full-compile-and-view command though, so I glued the "Full document compilation" and "Show result" scripts together and assigned it a keyboard shortcut (Window->Palettes->Scripts->Set Key...).

I also needed to edit the shell script to use Preview instead of Skim. Maybe this means I should play around with Skim a bit?

Anyway, this now allows me to select a bunch (or all) of references in Papers, export to bibtex, and cite them easily (assuming that the metadata in Papers is correct).

Labels: , ,

## Sunday, January 30, 2011

### JJ Abrams and his love of nicknames

(or maybe just his writers?)

Examples:
Alias (season 4): "Arvin Clone" (imposter of Arvin Sloane)
Lost (all seasons): anything Sawyer says
Fringe (season 2): "Walternate" (portmanteau of Walter and alternate)
Fringe (season 3): "Faulivia" (portmanteau of Faux and Olivia)

Labels: ,

## Thursday, January 27, 2011

### Why I hate programming (part 3 of n)

1. Matlab's inability to remember the current folder. Sure, you can set it so that the default location is a different location, but would it be so hard to remember the current folder when quitting and to automatically open that location when started again. Seems like a no-brainer to have some sort of checkbox for this in the preferences...

2. Matlab's default renderer's inability to handle transparency. Yes, that's right, I want to plot two histograms on top of each other, but the only way it can do transparency is to enable the OpenGL renderer. This would be fine if the OpenGL renderer could do fonts properly, but it can't, and moreover is unable to save images in vector format. (Don't even get me started on trying to draw patterned bars...)

more to come...