From 08685aea03c3ed2076f6f26644d9487fa0eb4493 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Mon, 21 Jun 2021 13:44:05 +0200 Subject: [PATCH] [linux-intro] Complete example files Add an example script file which computes prime numbers, and complete with a C version for execution efficiency comparison. --- linux-intro/files/files.sh | 8 ++++++++ linux-intro/files/linux-intro.tar | Bin 40960 -> 40960 bytes linux-intro/files/prime-again.sh | 16 ++++++++++++++++ linux-intro/files/prime.c | 20 ++++++++++++++++++++ linux-intro/files/prime.sh | 19 +++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 linux-intro/files/prime-again.sh create mode 100644 linux-intro/files/prime.c create mode 100644 linux-intro/files/prime.sh diff --git a/linux-intro/files/files.sh b/linux-intro/files/files.sh index 35cf42b..69c6c95 100644 --- a/linux-intro/files/files.sh +++ b/linux-intro/files/files.sh @@ -11,6 +11,8 @@ folders="\ 05.avsl \ " +# Include example text file to each lesson + text=text.txt for f in $folders; do @@ -21,5 +23,11 @@ for f in $folders; do done done +# Include script examples to lesson 4 + +cp prime.sh prime.c $file/04.stil + +# Compress and cleanup + tar -cvf $file.tar $file rm -fr $file diff --git a/linux-intro/files/linux-intro.tar b/linux-intro/files/linux-intro.tar index d89e45579d7a85c90bc51c874ced4f60bc896191..527562bbf95a090cbf7143a85a5de229b50abe22 100644 GIT binary patch delta 1771 zcmbu9&2G~`5Xa+|3RsCl`8XhiG;I?UH*Mn2wW`)g9FRbW2o4-j=^?2%%38?=nlz}Y zs+I!>f{`sokDO=7miaMwM z9*mae{rNPYsm@2bP7F`^d#u|;rfjZc7`0Rkr5sbSn;GT@UaE6b*Xh|lvT3eeT_?4$ z9JBa*-6k>>!`8jUTOSX2msR`i^W_)g=mtFWs8_JDrmCzyb!QUChH-tmwo+?yQDb5V z%|^dX$Qryk;9}5+#1@FdZj&AKHz49e9yOXB25iVg=LmZ8r+EZ?&}W?%G(?13jF5V` zwM7UIZGslWparWXKU#$%C!gCKukY^SGweXI4tsm2+Yt2#;NoGiT$ZE)Hkf9z7l%&r zuP#oGl%N>n8CVIyLL;dSX(yi8iRbM^Qdr`omAH=~l%DV=g+ZH%gh`%NEcaTRB==|R zgIFc_b^p3>?%zyuRNX&cemO}umNAoV&z*fqNxEz6|Ce4^uVIO}*zX)h40ig1i1(`P zr??lf78eZakYryBpxfZ0JnZqvB*z#amIC*44xQOcdZUEL_nP8IOm+tLDEw0-Vf?!4#vA6Egnu~wGbExa|Y)|Pt)^$?L eQ#wy{n>fx?>|b(B>HL~wO6RvM^OVjX*W@n}hMm;_ delta 1072 zcmZvay-Gwe5Joq9*+O9p|0)r73lR$;xtW<@uZ4w`SXfvHT8V{)h=s5q7G4pQ#TW1u ze1Uy4&9X6*$q2VQ%$GCY+{vsznf2daR{^X=i_o*K4M4pSPMx{@Hl{NrgO+S&%^!0X z;~cp-KC+9sLDwwiGK-msE!B)%X2Y6c$ZSP1pV>w?C_Rw~v*)Jt3|PFkB{L)A%&}s; z!?t3)`>tZKv$Xr3^aKa-z0|dro@71mjxv)haA*5#&2;_XUi58&eGb)Zn|+RI=6T2C z$`$6lCD)V6)nn{C?RZ*c`r?LXH6wO8SB!hRs9Eu^T}e+2j{o0l=^4oJdp9yOGVbhF zF}}r}V!Zo + +#define N 99 + +int main(void) +{ + int i, j; + i = 1; + printf ("%5d", i); + while (i < N) + { + i++; + j = 2; + while (i % j != 0) j++; + if (j == i) printf ("%5d", i); + } + printf ("\n"); +} diff --git a/linux-intro/files/prime.sh b/linux-intro/files/prime.sh new file mode 100644 index 0000000..2d91899 --- /dev/null +++ b/linux-intro/files/prime.sh @@ -0,0 +1,19 @@ +#!/bin/env bash + +# Prints prime numbers, dividable evenly only by itself and one + +N=99 + +i=1 +printf "%5d" $i +while [[ $i < $N ]]; do + i=$(( $i + 1 )) + j=2 + while [[ $(( $i % $j )) != 0 ]]; do + j=$(( $j + 1 )) + done + if [[ $j = $i ]]; then + printf "%5d" $i + fi +done +printf "\n" -- 2.39.2