From 15010f37b01811f7ac4b384159aae91039077e4c Mon Sep 17 00:00:00 2001 From: zhihanz Date: Sun, 3 May 2020 20:09:46 -0700 Subject: [PATCH] variables if function test1 --- exercises/functions/functions1.rs | 4 +++- exercises/functions/functions2.rs | 3 +-- exercises/functions/functions3.rs | 3 +-- exercises/functions/functions4.rs | 9 ++++----- exercises/functions/functions5.rs | 3 +-- exercises/if/if1.rs | 2 +- exercises/test1.rs | 4 +++- exercises/variables/variables1.rs | 3 +-- exercises/variables/variables2.rs | 3 +-- exercises/variables/variables3.rs | 3 +-- exercises/variables/variables4.rs | 3 +-- exercises/variables/variables5.rs | 6 ++---- temp_11118 | 0 temp_11118.2sdmqtm61l4rd3r2.rcgu.o | Bin 0 -> 1952 bytes temp_11118.variables4.7rcbfp3g-cgu.0.rcgu.o | Bin 0 -> 1528 bytes temp_11118.variables4.7rcbfp3g-cgu.1.rcgu.o | Bin 0 -> 2648 bytes temp_11118.variables4.7rcbfp3g-cgu.2.rcgu.o | Bin 0 -> 1232 bytes temp_11118.variables4.7rcbfp3g-cgu.3.rcgu.o | Bin 0 -> 2128 bytes temp_11118.variables4.7rcbfp3g-cgu.4.rcgu.o | Bin 0 -> 920 bytes temp_11118.variables4.7rcbfp3g-cgu.5.rcgu.o | Bin 0 -> 2400 bytes 20 files changed, 20 insertions(+), 26 deletions(-) create mode 100644 temp_11118 create mode 100644 temp_11118.2sdmqtm61l4rd3r2.rcgu.o create mode 100644 temp_11118.variables4.7rcbfp3g-cgu.0.rcgu.o create mode 100644 temp_11118.variables4.7rcbfp3g-cgu.1.rcgu.o create mode 100644 temp_11118.variables4.7rcbfp3g-cgu.2.rcgu.o create mode 100644 temp_11118.variables4.7rcbfp3g-cgu.3.rcgu.o create mode 100644 temp_11118.variables4.7rcbfp3g-cgu.4.rcgu.o create mode 100644 temp_11118.variables4.7rcbfp3g-cgu.5.rcgu.o diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 31125278..1f9d4bb9 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,8 +1,10 @@ // functions1.rs // Make me compile! Execute `rustlings hint functions1` for hints :) -// I AM NOT DONE fn main() { call_me(); } +fn call_me(){ + println!("do that is what you want?"); +} diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 108ba38b..9a1eec53 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,13 +1,12 @@ // functions2.rs // Make me compile! Execute `rustlings hint functions2` for hints :) -// I AM NOT DONE fn main() { call_me(3); } -fn call_me(num) { +fn call_me(num : i32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index e3c1bf73..4196a4f9 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -1,10 +1,9 @@ // functions3.rs // Make me compile! Execute `rustlings hint functions3` for hints :) -// I AM NOT DONE fn main() { - call_me(); + call_me(3); } fn call_me(num: i32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 58637e4c..b55a76c9 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -4,18 +4,17 @@ // This store is having a sale where if the price is an even number, you get // 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. -// I AM NOT DONE fn main() { - let original_price = 51; + let original_price = 1; println!("Your sale price is {}", sale_price(original_price)); } -fn sale_price(price: i32) -> { +fn sale_price(price: i32) -> i32{ if is_even(price) { - price - 10 + price - 10 // no semicolon means a return value } else { - price - 3 + return price - 3; // java style is fine } } diff --git a/exercises/functions/functions5.rs b/exercises/functions/functions5.rs index d22aa6c8..6869e863 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -1,7 +1,6 @@ // functions5.rs // Make me compile! Execute `rustlings hint functions5` for hints :) -// I AM NOT DONE fn main() { let answer = square(3); @@ -9,5 +8,5 @@ fn main() { } fn square(num: i32) -> i32 { - num * num; + num * num // again semicolon should not be used in return } diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545..59c6f983 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,6 +1,5 @@ // if1.rs -// I AM NOT DONE pub fn bigger(a: i32, b: i32) -> i32 { // Complete this function to return the bigger number! @@ -8,6 +7,7 @@ pub fn bigger(a: i32, b: i32) -> i32 { // - another function call // - additional variables // Execute `rustlings hint if1` for hints + return if a > b {a} else {b} } // Don't mind this for now :) diff --git a/exercises/test1.rs b/exercises/test1.rs index 8b5b8fdd..08531739 100644 --- a/exercises/test1.rs +++ b/exercises/test1.rs @@ -7,7 +7,6 @@ // more than 40 at once, each apple only costs 1! Write a function that calculates // the price of an order of apples given the order amount. No hints this time! -// I AM NOT DONE // Put your function here! // fn ..... { @@ -21,3 +20,6 @@ fn verify_test() { assert_eq!(70, price1); assert_eq!(65, price2); } +fn calculate_apple_price(number : i32) -> i32{ + if number > 40 {number * 1} else {number * 2} +} diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index 4a3af73c..149d5ce8 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -6,9 +6,8 @@ // even after you already figured it out. If you got everything working and // feel ready for the next exercise, remove the `I AM NOT DONE` comment below. -// I AM NOT DONE fn main() { - x = 5; + let x = 5; println!("x has the value {}", x); } diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb..be2ca14e 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,10 +1,9 @@ // variables2.rs // Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) -// I AM NOT DONE fn main() { - let x; + let x = 10; if x == 10 { println!("Ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 07b1a521..6b0f483c 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,11 +1,10 @@ // variables3.rs // Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) -// I AM NOT DONE fn main() { let x = 3; println!("Number {}", x); - x = 5; + let x = 5; // shadowing println!("Number {}", x); } diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab..64b261a4 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,8 @@ // variables4.rs // Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) -// I AM NOT DONE fn main() { - let x: i32; + let x: i32 = 0;// initilization is mandatory for compiler println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 47a68a55..3b645fc6 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -1,11 +1,9 @@ // variables5.rs // Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) -// I AM NOT DONE - fn main() { - let number = "3"; + let number = "3"; // shadowing can init val with diff type println!("Number {}", number); - number = 3; + let number = 3; println!("Number {}", number); } diff --git a/temp_11118 b/temp_11118 new file mode 100644 index 00000000..e69de29b diff --git a/temp_11118.2sdmqtm61l4rd3r2.rcgu.o b/temp_11118.2sdmqtm61l4rd3r2.rcgu.o new file mode 100644 index 0000000000000000000000000000000000000000..5009bbf5da05cd6cd36776d7cdd33a70c458e40d GIT binary patch literal 1952 zcmbuAy-wUf5XZ+D0!WCQqDVo4f+`Kd;!7#f6(LZd2t`7o2=bY;BP4trSsUp>lQgN) zQ0EC~sCWS$fRZu=Ek&fHM}nF4%z3@ugGiZ^Z)bixv;SFp&-Zn0^WBi=ftUxYP)0%l zZv4`3YPSi`G4r;>+WXh|CD(Z;AHeH1yy=P2u~QUoAfMs65gv&xIM`bU+p!pjwc!_% zVfcGrn?T^>$7Mc9N7Y#$Myr4$AI59^5=mpIhGA_0|2crG0sI2_3!{JOcv17RAK^bV zmk9bhY-?WbOETna4CDMWyzcG`Gx^v6PU^0FQV~9jJ{jF2^ERz$S}^nJY#5w+68p#w zts%W@6y!-Shv2ZAC&Bvr?fEQ^+6NG*B#nY(Km4S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^?h6m3!h)YX6o=5zWX9%tpfvI<%*zvy2eglhiZ@JU;Mgwj?)tmK`>m z5e>!+omybqJ96G3PdQFTPe!`l_Wfxb)AU2%Ci_Sjv#3>w)}E5fWUIr{8%faVj;(`h z!NF8FkMGF;5FCnKy;`e8Pb7E+7cxV*&slarnFTyH+7o-f9uaEC`QT;tRKSRbM4zGQ_{?Ak# z^>brpf6BP*+W`o^S^Dmb_`ju7-aoH@BjfXT;E9Z{W{Z)m_OIZtDZZ%xdj9n2rU7b;%ic<*H?RYLG;5m?}he^TT+&Yz!(-#d|Y jRbRoclTb9jp9aJ|uM?K9jof3o|DNPvMf3j`d-Xi* literal 0 HcmV?d00001 diff --git a/temp_11118.variables4.7rcbfp3g-cgu.2.rcgu.o b/temp_11118.variables4.7rcbfp3g-cgu.2.rcgu.o new file mode 100644 index 0000000000000000000000000000000000000000..647dcc0fc41de0cabcf684749456b9aeefdea3e0 GIT binary patch literal 1232 zcmbu8O=}ZD7{_PRU{@$%k%9p|IH;X(ZRis@) z7PYG1E4w{%6DryH_lQa1Zm@YD9`c>*Fxhu)49lL!=0n$Ga?NG)x{J9cIyRF-w}n*@ zK8N1dSWmuPFVhUcXxld~CS=myUo$rMvX1(ZHmFp9w;zGr{Th&Wp`L#K{4nIX{dk z-yfxUoN+=6k&Ac?`X(zCAv$`s(@thN57JEd-lKeSobjo6=?7DO>WBNCu$}Iukr#P^ z7X;nzU^&+ntgES_1JLNi2QK1%;)h{38E*x9QRn`EoW%L-cznoH>Su@0*fTRI((fARXfHSg$-((Et%Lgn?n z(3r`uDqiQcUg(aY=KAql0q^MYT|?xn;+Rq`<`;7t66T&@?FTiHr$FRzk2T*^J_R-B P#+0LYy$=}TJSP7eUw(Sx literal 0 HcmV?d00001 diff --git a/temp_11118.variables4.7rcbfp3g-cgu.3.rcgu.o b/temp_11118.variables4.7rcbfp3g-cgu.3.rcgu.o new file mode 100644 index 0000000000000000000000000000000000000000..473f7b0917585b451224d7bdbbe1195d4c85860e GIT binary patch literal 2128 zcmbVNy>HV%6nBzB11eQifm#WM4i@Utlasi%BOz2!KRiUGs)7V8=5oHY5vgt2PE`;R zL#L>!R53BKAR+Nz0Ahs+v9d8Rz`%x7-gEA1*G)U{qPzFr?|t6+?($-}xl$|?6iEf; zwvuWRRg}twR9;NPMdb>3+Iv6e?1RK;51y;D_CXV-!Do9At26fClfA!$yrov`!FzkZ zsaB4zVYoe5Qp;#8+j}49J|r1&T0ffpfgH?ZU>$pynh;jX$((Ybo?=%8Qh2tZ6m~0x z>l5SULs%H%H-v2!`O>6TygOM&To?Eh@;j52^+{Px7&7cDzJ9fZYQB$}sfA{2jDP@dT780s4=?jWhgZ zhZr&jVTvfzJv#kI!ZB>{pWh*k^Wm zmheX`-BnOX%y(mjcz(>u>e~JJD5mU*LPFl7gl{>WkZyB@L~$6?Ht?t0$el-P3%a8= zTdLYzSJe#|{hFrIC}C0T5)y=?kpR zculk1Wla?R9dcC8!HLhpc3F5F?cSAn_e<$cs#=*aCSL!7fE7^SNv~X}r{bow5Ev)PF1-u|B?c`TB_A`t$TH4+uT)i~mi4$#Tb0GTuH$ ohJvgw;b{;??cbLX-w)qq887#h047{z%7o8~M$3XD8@2!c0LaAqa{vGU literal 0 HcmV?d00001 diff --git a/temp_11118.variables4.7rcbfp3g-cgu.4.rcgu.o b/temp_11118.variables4.7rcbfp3g-cgu.4.rcgu.o new file mode 100644 index 0000000000000000000000000000000000000000..7072cd3a9ecf92a8daa06b97fb5a70a4a4f9a0b9 GIT binary patch literal 920 zcmbu7u};G<5QZ-;&<;pc2ni$@nAmEyNoYDCR0#?Ur~?uUOGr|;jcA%Gc2Ua0%*M#h zJMaR$1djnv0Ow#g#h@-&vj4m9?vE`y_wDnOf?4HC>}N2X~>V_E^TK<`r@m>{9J>v-UJ`o#kTRP%N#OU! zR=*nbC&Zqe^k2aqy7ODfKlLud=Nx6x-1E+I!B(`smX@nj-Mh*g7%cMZ{S{@DT9SSZ z!?6xzuAg80bI8U&-X7VR?5{~xQdWV~O;r7iqVy)~TT;b2mvJh;;slw#x3HvQ!Ev3f L-*+V5N%wyNY$-=7 literal 0 HcmV?d00001 diff --git a/temp_11118.variables4.7rcbfp3g-cgu.5.rcgu.o b/temp_11118.variables4.7rcbfp3g-cgu.5.rcgu.o new file mode 100644 index 0000000000000000000000000000000000000000..aa7133ce71994dd7de922f6f3bfde11927d3bc25 GIT binary patch literal 2400 zcmbVN&2JM|5FgtqF%V239E_-{RI*frnw1@IV*3CD;eZba5FY~dvOMpu9gEHGYIh9@ ziUblIh$2+(Tzc%S962JdSc3uroprYGO*LT6{IQkI*C4|Xt2dHY6Xe)lcL*xSn$_a9hEd&2fbj3t-f`mX()^855o-o870!LKUGBlvOESvz3$i%DvF1^!5Q20X zpD7aBrK(jbo-0*J0Xee+$PY^G^UEKYbPE36(=Gmz#Z2ok{EA2((&1BnrUDdL9OH$I zeRiV&pT?*C0u-}mQl7!}$2@g3BDQFwN;A~yZvAK;h{kpke9*JQv(=g@O?^_%!pi17>-DU(Y}RB&xnR`V!3Np=tgni3vZBYf|0lz2^jq- z7=~c@LE;)0FW+2<6Jg&4>!yEy;5*heHy*CLFp7u)dXXTtZ`+o;VY^{sC8Fyg5+@N# z$T!y|mnBdJ!}{g2X$O&855lj&>{uSSLTek2#D?q8%SX*4Gc59;Mh$Yt* zRo7kxbgjpUvlu0{swe!ug~dh5V$-S&8{LXrY%hq1k&CiJfK$OhqHEf&DTLE$Kf34mlLhzcF38dTJMjOOJE&WITr&)%35&rL43RiRfECq}-y|Nk4O{#XD2 literal 0 HcmV?d00001