javascript - I successfully compiled my program. Now how do I run it? -


i want solve project euler problem 1:

if list natural numbers below 10 multiples of 3 or 5, 3, 5, 6 , 9. sum of these multiples 23.

find sum of multiples of 3 or 5 below 1000.

here's code:

\documentclass[10pt,a4paper]{article} \usepackage{hyperref} \newcommand*\rfrac[2]{{}^{#1}\!/_{#2}} \title{solution project euler problem 1} \author{aadit m shah} \begin{document} \maketitle want find sum of multiples of 3 or 5 below 1000. can use formula of $n^{th}$ triangular number\footnote{\url{http://en.wikipedia.org/wiki/triangular_number}} calculate sum of multiples of number $m$ below 1000. formula of $n^{th}$ triangular number is:  \begin{equation} t_n = \sum_{k = 1}^n k = 1 + 2 + 3 + \ldots + n = \frac{n (n + 1)}{2} \end{equation}  if last multiple of $m$ below 1000 $x$ $n = \rfrac{x}{m}$. sum of multiples of $m$ below 1000 therefore:  \begin{equation} m \times t_{\frac{x}{m}} = m \times \sum_{k = 1}^{\frac{x}{m}} k = \frac{x (\frac{x}{m} + 1)}{2} \end{equation}  sum of multiples of 3 or 5 below 1000 equal to:  \begin{equation} 3 \times t_{\frac{999}{3}} + 5 \times t_{\frac{995}{5}} - 15 \times t_{\frac{990}{15}} = \frac{999 \times 334 + 995 \times 200 - 990 \times 67}{2} \end{equation} \end{document} 

i compiled using pdflatex:

$ pdflatex problem1.tex pdftex, version 3.14159265-2.6-1.40.15 (tex live 2014/arch linux) (preloaded format=pdflatex) . . . output written on problem1.pdf (1 page, 106212 bytes). transcript written on problem1.log. 

it generated following output pdf file along bunch of other files scary extensions:

solution project euler problem 1

how run pdf file computes solution? know solution problem want know how execute pdf file compute solution.

the reason why prefer latex on other programming languages because supports literate programming, approach programming introduced donald knuth, creator of tex , 1 of greatest computer scientists of time.

edit: nice able print computed solution either on screen or on paper. computing solution without printing useful heating room hot onset of summer , global warming. in addition, printing solution teach me how write hello world program in latex.

so, today seems safe day tackle problem...


the op not seem quite pdf-savvy. however, quite literate latex guy. means, must knowing tex well, given of donald knuth admirer...

so preliminaries. real meat.

first, quote the official pdf-1.7 specification document:

pdf not programming language, , pdf file not program.
                                                                                                            (p. 92, section 7.10.1)

however, pre-decessor of pdf format, postscript, is turing-complete programming language... turing-complete, tex is, creation of donald knuth, 1 of greatest computer scientists of time.

postscript files, on other hand, are programs, , can executed postscript printers (though execution time cannot reliably determined in advance).

hence, , second, op should able find way convert hi-level latex code low-level tex code. code needs emit postscript program, in turn can executed postscript printer. writing tex code should trivial op, once given postscript code should result of tex code.

i myself not well-versed tex aspect of problem solving procedure. however, can postscript.

the postscript op's tex code should produce goes (there sure more optimized versions possible -- first, quick'n'dirty shot @ it):

%!ps  % define variables /n1 999 def /t1 334 def /n2 995 def /t2 200 def /n3 990 def /s1  67 def /t3   2 def  % run computational code n1 t1 mul n2 t2 mul n3 s1 mul sub add t3    div  % print result on printer, not on <stdout> /helvetica findfont 24 scalefont setfont 30 500 moveto (result 'project euler problem no. 1' :) show  /helvetica-bold findfont 48 scalefont setfont 80 400 moveto (                   ) cvs show  showpage 

send postscript code postscript printer, , compute , print solution.


update

to answer 1 of comments: if replace last section of postscript code starting /helvetica findfont simple print statement, not might imagine.

print not cause printer output paper. instead asks postscript interpreter write topmost item on stack (which must (string)!) standard output channel. (if topmost item on stack not of type (string), trigger typecheck postscript error.)

so sending modified postscript file (where print has replaced last section of ps code) printer not work (unless printer supports interactive executive postscript mode -- not standard part of postscript language). work if feed file ghostscript in terminal or cmd.exe window.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -