7

On Project Euler Problem 11 (link: https://projecteuler.net/problem=11), there is a 20x20 grid of numbers. However, when I pasted it into Mathematica, I got this strange result where the times symbol 'x' is interlaced between the numbers.

Here is an image that shows this (again, this grid is directly copy/pasted from the website): http://i.gyazo.com/6336b0c44a1cb6afef7ee3f962c06522.png

Are there any in-line commands/functions you can use on that mass of numbers so that you can enter everything once and it will return a nicely formatted list/matrix? The only way I could think of, which did not make use of in-line commands, was very tedious: Ctrl+F --> Replace all "x" with "," and then manually entering curly brackets to turn the grid into a list/matrix.

Ideally, I want to turn it into something like {{1,2,3},{4,5,6},{7,8,9}}, but of course with the appropriate elements.

Edit: From this StackExchange post (Cut and paste data from a spreadsheet), I found that

data = ImportString["(copy/paste grid here)", "TSV"] 

works exactly as desired :)

Edit 2: Just kidding, the above doesn't work. It doesn't add commas.

user155812
  • 505
  • 3
  • 8

3 Answers3

9

Here is one way to import the grid into Mathematica

Partition[
 StringCases[
  Import["http://projecteuler.net/problem=11", "Plaintext"], 
  DigitCharacter ..][[10 ;; -8]], 
 20] // ToExpression
Karsten7
  • 27,448
  • 5
  • 73
  • 134
5

Szabolcs's Past Tabular Data palette still works just like it should. This palette is so useful it is one of only two I always open on start-up.

If for some reason you are looking for a one-off solution here is mine:

Block[{Times = List}, (*paste here*) ] ~Partition~ 20

Reference: Convert head Times to List

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
1

Highlight the list and paste into a text file and then

t=Import["put path of text file in here","Table"]
t//MatrixForm

works for me. Does it work for anyone else?

bobbym
  • 2,628
  • 2
  • 15
  • 20