Skip to content
Snippets Groups Projects
Commit 589be86e authored by Dashamir Hoxha's avatar Dashamir Hoxha
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
public
tmp
\ No newline at end of file
image: dockerscripts/bookdown
pages:
script:
- render.sh
artifacts:
paths:
- public
only:
- master
# Introduction {#index}
This is a minimal example of a book based on R Markdown and
**bookdown**, that can be hosted and edited on GitLab.
## R Markdown Examples
You can use anything that Pandoc's Markdown supports, for example a
math equation like this: ` $a^2 + b^2 = c^2$ ` is rendered like this:
$a^2 + b^2 = c^2$.
Remember each Rmd file contains one and only one chapter, and a
chapter is defined by the first-level heading `#`.
You can label chapter and section titles using `{#label}` after them,
e.g., we can reference Chapter \@ref(programing). If you do not manually
label them, there will be automatic labels anyway, e.g., Chapter
\@ref(applications).
Figures and tables with captions will be placed in `figure` and
`table` environments, respectively.
```{r nice-fig, fig.cap='Here is a nice figure!', out.width='80%', fig.asp=.75, fig.align='center'}
par(mar = c(4, 4, .1, .1))
plot(pressure, type = 'b', pch = 19)
```
Reference a figure by its code chunk label with the `fig:` prefix,
e.g., see Figure \@ref(fig:nice-fig). Similarly, you can reference
tables generated from `knitr::kable()`, e.g., see Table
\@ref(tab:nice-tab).
```{r nice-tab, tidy=FALSE}
knitr::kable(
head(iris, 20), caption = 'Here is a nice table!',
booktabs = TRUE
)
```
You can write citations, too. For example, we are using the
**bookdown** package [@R-bookdown] in this sample book, which was
built on top of R Markdown and **knitr** [@xie2015].
## Installing Bookdown
The **bookdown** package can be installed from CRAN or Github:
```{r eval=FALSE}
install.packages("bookdown")
# or the development version
# devtools::install_github("rstudio/bookdown")
```
To compile this example to PDF, you need XeLaTeX. You are recommended
to install TinyTeX (which includes XeLaTeX):
<https://yihui.name/tinytex/>.
```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```
Please see https://bookdown.org/yihui/bookdown/get-started.html for
mode details.
## Version
The latest version of this book is at:
http://dashohoxha.gitlab.io/bookdown-example/
Corrections or improvements can be suggested at:
https://gitlab.com/dashohoxha/bookdown-example
## License
![](assets/images/cc.png)
This work is licensed under a [Creative Commons Attribution-ShareAlike
4.0 Unported License](http://creativecommons.org/licenses/by-sa/4.0/).
# Programing Examples {#programing}
## Problem 1
### Kërkesa
Nqs kemi N monedha dhe i vendosim në formë trekëndëshi, në mënyrë të
tillë që:
- në rreshtin e parë vendosim 1 monedhë
- në rreshtin e dytë vendosim 2 monedha
- në rreshtin e tretë vendosim 3 monedha
- e kështu me radhë (siç tregohet në figurë)
Sa është lartësia e trekëndëshit më të madh që mund të formohet?
![](assets/images/ahTh1foh.png)
Referenca: https://www.codechef.com/problems/TRICOIN
#### Shembull
```
$ cat input.txt
3
3
5
7
$ python3 prog.py < input.txt
2
2
3
```
- Testi 1: Nuk mund të formojmë një trekëndësh me lartësi >2, sepse kjo
kërkon të paktën 6 monedha.
- Testi 2: Nuk mund të formojmë një trekëndësh me lartësi >2, sepse
kjo kërkon të paktën 6 monedha.
- Testi 3: Nuk mund të formojmë një trekëndësh me lartësi >3, sepse
kjo kërkon të paktën 10 monedha.
### Zgjidhja 1
```python
T = int(input())
for t in range(T):
n = int(input())
l = 0 # lartesia
s = 0 # sasia e monedhave
while True:
s += l + 1
if s > n:
break
else:
l += 1
print(l)
```
#### Sqarime
Fillimisht shënojmë me `0` **l**artësinë e trekëndëshit dhe **s**asinë
e monedhave që duhet për ta ndërtuar. Pastaj fillojmë ta rrisim
lartësinë me nga 1, duke llogaritur edhe sasinë e monedhave që na
duhen për ta ndërtuar. Këtë punë e bëjmë deri sa sasia e monedhave mos
ta kalojë numrin `n` që na është dhënë.
### Zgjidhja 2
```python
for _ in range(int(input())):
n = int(input())
l = s = 0
while s <= n:
l += 1
s += l
print(l - 1)
```
Fillojmë ta rrisim lartësinë me nga 1, duke llogaritur edhe sasinë e
monedhave që na duhen. Këtë punë e bëjmë deri sa sasia e duhur e
monedhave ta kalojë numrin `n` që na është dhënë. Atere lartësia e
mundshme e trekëndëshit është vlera e `l`-së që sapo kaluam (ku sasia
e dhënë e monedhave ishte e mjaftueshme për ta ndërtuar).
### Detyra
Shkruani një program që llogarit shumën e shifrave të një numri të
dhënë.
Referenca: https://www.codechef.com/problems/FLOW006
#### Shembull
```
$ cat input.txt
3
12345
31203
2123
$ python3 prog.py < input.txt
15
9
8
```
## Problem 2
### Kërkesa
Në një varg me numra natyrorë $`a_1, a_2, ... , a_n`$ gjeni diferencën
më të vogël të mundshme midis 2 prej tyre. Dmth gjeni vlerën minimale
të $`|a_i - a_j|`$ për çdo $`1 \leq i < j \leq n`$ .
Referenca: https://www.codechef.com/problems/HORSES
#### Shembull
```
$ cat input.txt
1
5
4 9 1 32 13
$ python3 prog.py < input.txt
3
```
### Zgjidhja 1
```python
T = int(input())
for t in range(T):
n = int(input())
l = list(map(int, input().split()))
dmin = abs(l[0] - l[1])
i = 0
while i <= n-2:
j = i + 1
while j <= n-1:
d = abs(l[i] - l[j])
if d < dmin:
dmin = d
j += 1
i += 1
print(dmin)
```
#### Sqarime
Marrim të gjitha kombinimet e mundshme të `i` dhe `j`, gjejmë
diferencat midis tyre, dhe ndërkohë gjejmë edhe më të voglën e
diferencave.
P.sh. për numrin $`a_1`$ bëjmë diferencën me $`a_2, a_3, ... , a_n`$,
për numrin $`a_2`$ bëjmë diferencën me $`a_3, ... , a_n`$, e kështu me
radhë.
Kjo zgjidhje nuk është dhe aq efiçente sepse për $n$ numra duhet të
bëjmë përafërsisht $`n^2`$ veprime (zbritje, krahasime, etj.)
Zgjidhja më poshtë është më e shpejtë.
### Zgjidhja 2
```python
T = int(input())
for t in range(T):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
dmin = l[0] - l[1]
i = 0
while i <= n-2:
d = l[i] - l[i+1]
if d < dmin:
dmin = d
i += 1
print(dmin)
```
#### Sqarime
Fillimisht i rendisim numrat në rendin zbritës. Pastaj, në vend që të
bëjmë diferencën e numrit $`a_i`$ me të gjithë numrat pasardhës,
mjafton që të bëjmë diferencën e tij vetëm me numrin $`a_{i+1}`$, dhe
dihet që diferenca me numrat e tjerë pasardhës nuk është më e vogël se
kjo (sepse janë më të vegjël se $`a_{i+1}`$).
### Detyra
Kemi një varg me numra ku të gjithë numrat përsëriten një numër çift
herësh, me përjashtim të njërit i cili përsëritet një numër tek
herësh. Të gjendet ky numër.
Referenca: https://www.codechef.com/problems/MISSP
#### Shembull
```
$ cat input.txt
2
3
1
2
1
5
1
1
2
2
3
$ python3 prog.py < input.txt
2
3
```
Janë 2 raste testimi, i pari ka 3 numra (njëri nën tjetrin), dhe i dyti ka 5 numra.
# Applications
Some _significant_ applications are demonstrated in this chapter.
## Example one
## Example two
# Final Words
We have finished a nice book.
`r if (knitr:::is_html_output()) '
# References {-}
'`
This is a minimal example of a book based on R Markdown and
**bookdown**, that can be hosted and edited on GitLab.
book_filename: "bookdown-example"
language:
ui:
chapter_name: "Chapter"
delete_merged_file: true
rmd_files: [
"index.Rmd",
"01-intro.md",
"02-problem1.md",
"02-problem2.md",
"03-application.md",
"04-summary.md",
"05-references.md",
]
File added
@Book{xie2015,
title = {Dynamic Documents with {R} and knitr},
author = {Yihui Xie},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2015},
edition = {2nd},
note = {ISBN 978-1498716963},
url = {http://yihui.name/knitr/},
}
assets/images/ahTh1foh.png

14.9 KiB

assets/images/cc.png

1.66 KiB

assets/images/favicon.ico

14.7 KiB

@Manual{R-base,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2018},
url = {https://www.R-project.org/},
}
@Manual{R-bookdown,
title = {bookdown: Authoring Books and Technical Documents with R Markdown},
author = {Yihui Xie},
year = {2019},
note = {R package version 0.14},
url = {https://CRAN.R-project.org/package=bookdown},
}
@Manual{R-knitr,
title = {knitr: A General-Purpose Package for Dynamic Report Generation in R},
author = {Yihui Xie},
year = {2019},
note = {R package version 1.25},
url = {https://CRAN.R-project.org/package=knitr},
}
@Manual{R-rmarkdown,
title = {rmarkdown: Dynamic Documents for R},
author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang and Richard Iannone},
year = {2019},
note = {R package version 1.16},
url = {https://CRAN.R-project.org/package=rmarkdown},
}
\usepackage{booktabs}
\usepackage{amsthm}
\makeatletter
\def\thm@space@setup{%
\thm@preskip=8pt plus 2pt minus 4pt
\thm@postskip=\thm@preskip
}
\makeatother
@font-face {
font-family: 'Monaco';
font-style: normal;
font-weight: normal;
src: local('Monaco'), url('Monaco.woff') format('woff');
}
p.caption {
color: #777;
margin-top: 10px;
}
p code {
white-space: inherit;
font-family: Monaco !important;
}
pre {
word-break: normal;
word-wrap: normal;
font-family: Monaco !important;
}
pre code {
white-space: inherit;
font-family: Monaco !important;
}
build.sh 0 → 100755
#!/bin/bash
cd $(dirname $0)
### copy everything to a tmp dir
rm -rf tmp/
rsync -a . tmp/
cd tmp/
### preprocess markdown files to fix them for pandoc
for file in $(find . -name '*.md'); do
# fix latex delimiters for pandoc
sed -i $file \
-e 's/$`/$/g' \
-e 's/`\$/$/g'
# leave an empty line before starting a list, otherwise pandoc does not interpret it as a list
sed -i $file \
-e '/./{H;$!d} ; x ; s/:\n-/:\n\n-/'
# open links on a new tab
sed -i $file \
-e 's#\([^(]\)\(https\?://.*\)#\1[\2](\2){target="_blank"}#'
done
### render all the formats
rm -rf ../public/
Rscript -e "bookdown::render_book('index.Rmd', 'all', output_dir = '../public')"
### copy font Monaco
cd ..
cp assets/Monaco.woff public/
### clean up
rm -rf tmp/
---
title: "Bookdown Example"
author: "Dashamir Hoxha"
date: "`r Sys.Date()`"
url: http\://dashohoxha.gitlab.io/bookdown-example
description: "This is a minimal example of using bookdown to write a book."
bibliography: [assets/book.bib, assets/packages.bib]
biblio-style: apalike
link-citations: yes
site: bookdown::bookdown_site
documentclass: scrbook
output:
bookdown::gitbook:
css: assets/style.css
split_by: chapter # chapter | chapter+number | section | section+number | rmd
#number_sections: FALSE
highlight: tango
config:
edit: https://gitlab.com/dashohoxha/bookdown-example/edit/master/%s
download: ["pdf", "epub", "tex"]
toc:
collapse: section # section | subsection | none
before: |
<li><a href="./">Bookdown Example</a></li>
toolbar:
position: fixed # fixed | static
fontsettings:
theme: white # white | sepia | night
family: serif # serif | sans
size: 2
sharing:
facebook: no
twitter: no
all: ['facebook', 'twitter', 'linkedin', 'google']
bookdown::pdf_book:
#number_sections: FALSE
#includes:
# in_header: assets/preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
#fig_caption: FALSE
highlight: tango
bookdown::epub_book:
#number_sections: FALSE
#fig_caption: FALSE
---
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment