-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.xml
2494 lines (2428 loc) · 483 KB
/
index.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Everyone Has a Story</title>
<link>https://BhaveshSGupta.me/</link>
<description>Recent content on Everyone Has a Story</description>
<generator>Hugo -- gohugo.io</generator>
<language>en</language>
<managingEditor>[email protected] (Bhavesh S. Gupta)</managingEditor>
<webMaster>[email protected] (Bhavesh S. Gupta)</webMaster>
<lastBuildDate>Wed, 05 Apr 2023 01:45:46 +0000</lastBuildDate>
<atom:link href="https://BhaveshSGupta.me/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>About</title>
<link>https://BhaveshSGupta.me/about/</link>
<pubDate>Sat, 20 Jun 2015 14:02:37 +0200</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/about/</guid>
<description><p>My name is Bhavesh S. Gupta, and I am currently working as a Sr. Software Engineer at <a href="https://Investisdigital.com">InvestisDigital</a>. I am passionate about using technology to make people&rsquo;s lives better, and I believe that OpenSource technology is the key to achieving this goal.</p>
<p>Programming has always been a hobby of mine, and I have always loved the challenge of solving complex problems with code. As a Full Stack Engineer, I have had the opportunity to work with a wide range of technologies, including NodeJS, ReactJS, MonogoDB, Redis, DocumentDB, DRUPAL CMS, StencilJS (Web components), Python, HTML5, CSS3, JavaScript, and JQuery.</p>
<p>Despite my experience, I am always learning and trying to improve my skills as a developer. I believe that staying up-to-date with the latest languages and technologies is essential in this field. Whenever I get the chance, I try my hand at learning new languages and technologies, as I believe this helps me become a better engineer.</p>
<p>Through this website, I hope to share my experiences and insights with others who share my passion for technology. Whether you are a beginner or an experienced programmer, I hope you will find something of value here. Thank you for visiting, and I look forward to sharing more with you!</p>
</description>
</item>
<item>
<title>Samsung Galaxy Watch4 Classic LTE & Galaxy S20 FE 5G: The Ultimate Combo for Tech Enthusiasts</title>
<link>https://BhaveshSGupta.me/blog/samsung-galaxy-s20/</link>
<pubDate>Wed, 05 Apr 2023 01:45:46 +0000</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/samsung-galaxy-s20/</guid>
<description><p>If you&rsquo;re a tech enthusiast looking for the perfect combination of a smartphone and a wearable, look no further than the Samsung Galaxy Watch4 Classic LTE and Galaxy S20 FE 5G combo. This dynamic duo provides all the features you need to stay connected, fit, and up-to-date with the latest technology trends.</p>
<p>Let&rsquo;s start with the Galaxy S20 FE 5G. This smartphone is 5G ready, powered by a Qualcomm Snapdragon 865 Octa-Core processor, and comes with 8GB RAM and 128GB internal memory, expandable up to 1TB. It runs on the Android 11.0 operating system and has dual SIM capabilities, making it perfect for the frequent traveler or someone who needs to stay connected on multiple networks.</p>
<p>The Galaxy S20 FE 5G also boasts a triple rear camera setup, including a 12MP (Dual Pixel) OIS F1.8 wide rear camera, an 8MP OIS tele camera, and a 12MP ultra-wide camera. It has a 30X space zoom, single take, and night mode features, as well as a 32MP F2.2 front punch-hole camera. The 6.5-inch Infinity-O Super AMOLED display with a 120Hz refresh rate and 1080 x 2400 (FHD+) resolution is perfect for streaming movies or browsing the web.</p>
<p>The Galaxy S20 FE 5G is also equipped with a 4500 mAh battery with super-fast charging and fast wireless charging, as well as a fingerprint sensor for added security. It&rsquo;s IP68 rated, has a microSD card slot (expandable up to 1 TB), a dual nano-SIM, hybrid SIM slot, and is 5G+5G dual stand-by capable.</p>
<p>Now, let&rsquo;s move on to the Galaxy Watch4 Classic LTE. This wearable is only compatible with Android smartphones and runs on Wear OS powered by Samsung. It features a bioelectrical impedance analysis sensor for body composition analysis, as well as an optical heart rate sensor. With advanced sleep analysis and women&rsquo;s health monitoring features, the Galaxy Watch4 is perfect for fitness enthusiasts or anyone looking to monitor their health.</p>
<p>The enhanced fitness tracking lets you track 90+ workouts, and the enriched app availability and connectivity with Wear OS powered by Samsung make it easy to stay on top of your fitness goals. The Galaxy Watch4 has a typical usage time of up to 40 hours, and it comes with a watch strap and wireless charger for added convenience.</p>
<p>The Samsung Galaxy Watch4 Classic LTE &amp; Galaxy S20 FE 5G combo is the perfect choice for tech enthusiasts who want the latest in smartphone and wearable technology. With no-cost EMI and additional exchange offers available on Amazon, it&rsquo;s never been easier to upgrade your tech game.</p>
<p>As an Amazon Associate, I earn from qualifying purchases made through the affiliate link: <a href="https://amzn.to/3U8YFrs">https://amzn.to/3U8YFrs</a></p></description>
</item>
<item>
<title>Resignation Etiquette</title>
<link>https://BhaveshSGupta.me/blog/resignation-etiqutte/</link>
<pubDate>Mon, 08 Feb 2021 20:50:32 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/resignation-etiqutte/</guid>
<description><p>One follow etiquette about several things in life but rarely people talk about resignation etiquette.</p>
<p>Internet is one of those tool in the world which is boon and curse to people depending upon how you use it. It is great tool to get different perspectives over any problems by reading, listening and watching. Recently I have been reading about Resignation etiquette, after reading I decided to write down my thoughts on it, such that it could be helpful to someone.</p>
<div class="shortcode-notice note">
<div class="shortcode-notice-title note">
note</div>
<div class="notice-content">PS: I am still a very novice writer so there are can be profound mistake here. I am still learning sill growing. You may or may not agree with what I say here please don&rsquo;t take me wrong.</div>
</div>
<h2 id="standard-time">Standard time</h2>
<p>I feel in corporate world two weeks is the standard time for any course of action. In this time frame, management can meet and talk about all general affairs, people&rsquo;s management, decision about promotion/demotion. So for any action you should give at-least two weeks of time, rest depends upon your situation.</p>
<h2 id="discussing-problem-with-yourmanagerlinemanagermdceo">Discussing problem with your manager/line manager/MD/CEO</h2>
<p>There are times people resign due to some small problems like designation, salary, type of work or such small things which are easily solvable from management. In this case it is always better to discuss these before giving resignation, after talking if the solution can not be achieve in standard time then you can go ahead with your resignation. But you should not give resignation without dicussing this smaller issue. Sometime it is right time to move to another company for your own goals and everything if thats the case it is okay to go ahead.</p>
<h2 id="your-manager-should-not-be-surprise-with-your-official-resignation-mail">Your manager should not be surprise with your official resignation mail</h2>
<p>Your immediate manager should not be surprise with your resignation mail. It is good practice to inform them informally once before sending it. What ever your relation would be they are still your manager and they should be informed informally.</p>
<h2 id="once-you-have-send-resignation-you-should-not-take-it-back">Once you have send resignation you should not take it back</h2>
<p>As it is said you should be a person of your word. You should not take back your resignation. If you are in an environment where the things you deserve or desire or problems you are solved after putting resignation then you should leave that place asap if someone can&rsquo;t recognized your efforts while discussing it, they would continue to do so in future as well.</p>
<h2 id="do-not-let-your-friendscolleague-know-that-you-have-resigned-un-till-it-is-officially-declared">Do not let your friends/colleague know that you have resigned un-till it is officially declared</h2>
<p>I am still skeptical about this but it feels after official when you have given resignation you should not talk with friends. Usually this is open topic and eventually everyone knows. When people start knowing about the it then you can inform your close colleague.</p>
<div class="shortcode-notice note">
<div class="shortcode-notice-title note">
note</div>
<div class="notice-content">PS: Usually your friends from office are someone who would know about this but your close colleague wont.</div>
</div>
<h2 id="do-give-notice-when-possible">Do Give Notice When Possible</h2>
<p>Normally every company has their own notice period policy. It ranges from 1 to 3 months in India. Ideally you should serve atleast 2 weeks of notice period or it depends upon your company policy. There is always or in most cases a point in your job description about early release by paying some financial loss to your company this is usually related to your salary.</p>
<p>If you feel leaving early is something that cannot be avoided then you should go with that option.</p>
<h2 id="do-not-leave-with-hate">Do not leave with hate</h2>
<p>People tend to live company with hate, fights and bad words which is last thing you want to do where you have worked for so long. It is always good to leave on happy face, you should not complain about a person, manager or company itself find a polite words for the words you want to say.</p>
<h2 id="delete-all-personal-filesemails-from-your-office-pclaptop">Delete all personal files/emails from your office pc/laptop</h2>
<p>Ideally in your office pc there should not be anything personal but over time when you have been a place for long term some things make space in your office pc. You should clear/delete all these before giving notice. Sometime this happens where a company would ask you to leave on same day when you give your resignation. You should be ready for that, In such situation what ever you are feeling you should leave with happy face.</p>
<blockquote>
<p>Last but not the least, do not burn bridges. You may never know with whom you may work again in life so it is better to always end on positive note</p>
</blockquote></description>
</item>
<item>
<title>The Coin Weight Problem</title>
<link>https://BhaveshSGupta.me/blog/the-coin-weight-problem/</link>
<pubDate>Wed, 03 Feb 2021 11:06:14 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/the-coin-weight-problem/</guid>
<description><p>The problem resolves around find which of the coin is uneven in weight of all other coins. Suppose there are around 8 coin out of them one is heavy/light then others and we have one scale where we can compare two things</p>
<p>This is an interesting another problem which I had found while dicussing with <a href="https://www.linkedin.com/in/vatsalsura/">Vatsal</a> a friend of mine, which was asked in his interview for some company.</p>
<p>Suppose out of eight we know that one of them is of higher weight then others. The simplest way to achieve the solution for this problem would be doing a binary search like approach where you would divide in two equal half check which side is higher then again divde in two equal half and then look for higher side where you can reach finally to a conclusion on which coin is higher</p>
<p>Same approach can be taken when one of coin is lighter then others. For eight coin it would take atleast 3 round for above solution.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-7">7</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#40a070">88889888</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">8888</span> <span style="color:#40a070">9888</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span> <span style="color:#40a070">98</span> <span style="color:#40a070">88</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span> <span style="color:#40a070">9</span> <span style="color:#40a070">8</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-7">7</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#40a070">88887888</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">8888</span> <span style="color:#40a070">7888</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span> <span style="color:#40a070">78</span> <span style="color:#40a070">88</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span> <span style="color:#40a070">7</span> <span style="color:#40a070">8</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p>Now to optimize the solution we can look into another approach. Here as in above we are sure that one of the coin is higher in weight then others. In this case we can do something like this. We can take two coin aside and equally divide rest 6 coins. Then we can compare three with other three. If weight of one of side is higher then we can discard all other coin then this three as we are aware that only one coin is of higher weight then other. Now we have three coins left. We can weight two of them, if one of side is higher then we have found then coin. If both are equal then the one which we didnt weigh is coin with higher weight.</p>
<p>Other secenario could be where when we had compare 3 - 3 coins on each side they would have been of equal weigh. In that case we can weigh left two coins and get which one is higher.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-5">5</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#40a070">898888</span> <span style="color:#40a070">88</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">898</span> <span style="color:#40a070">888</span>
</span></span><span style="display:flex;"><span>/<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">8</span> <span style="color:#40a070">9</span> <span style="color:#40a070">8</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5">5</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#40a070">889888</span> <span style="color:#40a070">88</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">889</span> <span style="color:#40a070">888</span>
</span></span><span style="display:flex;"><span>/<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">8</span> <span style="color:#40a070">8</span> <span style="color:#40a070">9</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-5">5</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#40a070">888888</span> <span style="color:#40a070">98</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span><span style="color:#40a070">888</span> <span style="color:#40a070">888</span> <span style="color:#40a070">98</span>
</span></span><span style="display:flex;"><span> /<span style="color:#4070a0;font-weight:bold">\
</span></span></span><span style="display:flex;"><span><span style="color:#4070a0;font-weight:bold"></span> <span style="color:#40a070">9</span> <span style="color:#40a070">8</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p>In above solution we have optimized it further such that instead of three operation we are doing just two opertation.</p>
<p>The intresting problem here would be when we would not be aware whether a coin is lighter or heavier. In that case how we can optimize it. Whose solution we can try to find may in another blog post.</p></description>
</item>
<item>
<title>The Fizzbuzz Problem 2</title>
<link>https://BhaveshSGupta.me/blog/the-fizzbuzz-problem-2/</link>
<pubDate>Tue, 02 Feb 2021 08:56:01 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/the-fizzbuzz-problem-2/</guid>
<description><p>Last time I had stopped optimizing this the problem more because we were having a discussion where string concatination is a costly opperation. So yesterday I was talking with Nishchay how can about the previous blog and other things at that point we started on optimizing this further avoiding string contactination as well.</p>
<p>In Competetive programming, this is optimize even further, where % modulo operation is replaced by addtion and subtraction. This approach is also dicussed in same video which was shared in previous post.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-11">11</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">let</span> c3<span style="color:#666">=</span><span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">let</span> c5<span style="color:#666">=</span><span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> (number <span style="color:#666">=</span> <span style="color:#40a070">1</span>; number <span style="color:#666">&lt;=</span> <span style="color:#40a070">100</span>; number<span style="color:#666">++</span>) {
</span></span><span style="display:flex;"><span> c3<span style="color:#666">++</span>;
</span></span><span style="display:flex;"><span> c5<span style="color:#666">++</span>;
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">var</span> outcome <span style="color:#666">=</span> <span style="color:#4070a0">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(c3<span style="color:#666">==</span><span style="color:#40a070">3</span>) {outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#34;fizz&#34;</span>;c3<span style="color:#666">=</span><span style="color:#40a070">0</span>}
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(c5<span style="color:#666">==</span><span style="color:#40a070">5</span>) {outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#34;buzz&#34;</span>;c5<span style="color:#666">=</span><span style="color:#40a070">0</span>}
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(outcome) console.log(outcome)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> console.log(number)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-14">14</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span>c3 <span style="color:#666">=</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span>c5 <span style="color:#666">=</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> number <span style="color:#007020;font-weight:bold">in</span> <span style="color:#007020">range</span>(<span style="color:#40a070">1</span>, <span style="color:#40a070">101</span>):
</span></span><span style="display:flex;"><span> c3<span style="color:#666">+=</span><span style="color:#40a070">1</span>
</span></span><span style="display:flex;"><span> c5<span style="color:#666">+=</span><span style="color:#40a070">1</span>
</span></span><span style="display:flex;"><span> outcome <span style="color:#666">=</span> <span style="color:#4070a0">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(c3 <span style="color:#666">==</span> <span style="color:#40a070">3</span>) :
</span></span><span style="display:flex;"><span> outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#39;fizz&#39;</span>
</span></span><span style="display:flex;"><span> c3<span style="color:#666">=</span><span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(c5 <span style="color:#666">==</span> <span style="color:#40a070">5</span>) :
</span></span><span style="display:flex;"><span> outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#39;buzz&#39;</span>
</span></span><span style="display:flex;"><span> c5<span style="color:#666">=</span><span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(outcome <span style="color:#666">!=</span> <span style="color:#4070a0">&#34;&#34;</span>) : <span style="color:#007020">print</span>(outcome)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>: <span style="color:#007020">print</span>(number)
</span></span></code></pre></td></tr></table>
</div>
</div><p>While discussion this approach, with Vijay and Anup there was discussion that string contactination is costly operation compared to modulo. And instead of going above approach last approach to the problem was much better.</p>
<p>So yesterday I and Nishchay were dicussing this problem and working on a solution where we could avoid string contactination as well. While doing I tried to combine all of the example from previous post and come up with something as below</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-11">11</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">let</span> c3<span style="color:#666">=</span><span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">let</span> c5<span style="color:#666">=</span><span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> (number <span style="color:#666">=</span> <span style="color:#40a070">1</span>; number <span style="color:#666">&lt;=</span> <span style="color:#40a070">100</span>; number<span style="color:#666">++</span>) {
</span></span><span style="display:flex;"><span> c3<span style="color:#666">++</span>;
</span></span><span style="display:flex;"><span> c5<span style="color:#666">++</span>;
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">var</span> outcome <span style="color:#666">=</span> <span style="color:#4070a0">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(c3<span style="color:#666">==</span><span style="color:#40a070">3</span> <span style="color:#666">&amp;&amp;</span> c5<span style="color:#666">==</span><span style="color:#40a070">5</span>) {console.log(<span style="color:#4070a0">&#34;fizzbuzz&#34;</span>);c3<span style="color:#666">=</span><span style="color:#40a070">0</span>;c5<span style="color:#666">=</span><span style="color:#40a070">0</span>}
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(c3<span style="color:#666">==</span><span style="color:#40a070">3</span>){ console.log(<span style="color:#4070a0">&#34;fizz&#34;</span>); c3<span style="color:#666">=</span><span style="color:#40a070">0</span>}
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(c5<span style="color:#666">==</span><span style="color:#40a070">5</span>){ console.log(<span style="color:#4070a0">&#34;buzz&#34;</span>); c5<span style="color:#666">=</span><span style="color:#40a070">0</span>}
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> console.log(number)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-7">7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-8">8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-9">9</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span>c3 <span style="color:#666">=</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span>c5 <span style="color:#666">=</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> number <span style="color:#007020;font-weight:bold">in</span> <span style="color:#007020">range</span>(<span style="color:#40a070">1</span>, <span style="color:#40a070">101</span>):
</span></span><span style="display:flex;"><span> c3<span style="color:#666">+=</span><span style="color:#40a070">1</span>
</span></span><span style="display:flex;"><span> c5<span style="color:#666">+=</span><span style="color:#40a070">1</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(c3 <span style="color:#666">==</span> <span style="color:#40a070">3</span> <span style="color:#007020;font-weight:bold">and</span> c5 <span style="color:#666">==</span> <span style="color:#40a070">3</span>): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizzbuzz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(c3 <span style="color:#666">==</span> <span style="color:#40a070">3</span>): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(c5 <span style="color:#666">==</span> <span style="color:#40a070">5</span>): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;buzz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>: <span style="color:#007020">print</span>(number)
</span></span></code></pre></td></tr></table>
</div>
</div><p>While dicussing Nishchay pointed out that in this solution also we incrementing three times why not try to lower number of increments and addition and make it further optimize. Then we come up the below solution.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-14">14</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-15"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-15">15</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">var</span> c3 <span style="color:#666">=</span> <span style="color:#40a070">3</span>;
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">var</span> c5 <span style="color:#666">=</span> <span style="color:#40a070">5</span>;
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span>(number <span style="color:#666">=</span> <span style="color:#40a070">1</span>; number <span style="color:#666">&lt;=</span><span style="color:#40a070">100</span>; number<span style="color:#666">++</span>){
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">==</span> c5 <span style="color:#666">&amp;&amp;</span> number <span style="color:#666">==</span> c3){
</span></span><span style="display:flex;"><span> console.log(<span style="color:#4070a0">&#34;fizzbuzz&#34;</span>);
</span></span><span style="display:flex;"><span> c3 <span style="color:#666">+=</span> <span style="color:#40a070">3</span>;
</span></span><span style="display:flex;"><span> c5 <span style="color:#666">+=</span> <span style="color:#40a070">5</span>;
</span></span><span style="display:flex;"><span> } <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">==</span> c3){
</span></span><span style="display:flex;"><span> console.log(<span style="color:#4070a0">&#34;fizz&#34;</span>);
</span></span><span style="display:flex;"><span> c3 <span style="color:#666">+=</span> <span style="color:#40a070">3</span>;
</span></span><span style="display:flex;"><span> } <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">==</span> c5){
</span></span><span style="display:flex;"><span> console.log(<span style="color:#4070a0">&#34;buzz&#34;</span>);
</span></span><span style="display:flex;"><span> c5 <span style="color:#666">+=</span> <span style="color:#40a070">5</span>;
</span></span><span style="display:flex;"><span> } <span style="color:#007020;font-weight:bold">else</span> console.log(number);
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-14">14</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span>c3 <span style="color:#666">=</span> <span style="color:#40a070">3</span>
</span></span><span style="display:flex;"><span>c5 <span style="color:#666">=</span> <span style="color:#40a070">5</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> number <span style="color:#007020;font-weight:bold">in</span> <span style="color:#007020">range</span>(<span style="color:#40a070">1</span>, <span style="color:#40a070">101</span>) :
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> (number <span style="color:#666">==</span> c3 <span style="color:#007020;font-weight:bold">and</span> number <span style="color:#666">==</span> c5) :
</span></span><span style="display:flex;"><span> <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizzbuzz&#39;</span>)
</span></span><span style="display:flex;"><span> c3 <span style="color:#666">+=</span> <span style="color:#40a070">3</span>
</span></span><span style="display:flex;"><span> c5 <span style="color:#666">+=</span> <span style="color:#40a070">5</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span> (number <span style="color:#666">==</span> c3) :
</span></span><span style="display:flex;"><span> <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizz&#39;</span>)
</span></span><span style="display:flex;"><span> c3 <span style="color:#666">+=</span> <span style="color:#40a070">3</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(number <span style="color:#666">==</span> c5):
</span></span><span style="display:flex;"><span> <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;buzz&#39;</span>)
</span></span><span style="display:flex;"><span> c5 <span style="color:#666">+=</span> <span style="color:#40a070">5</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>: <span style="color:#007020">print</span>(number)
</span></span></code></pre></td></tr></table>
</div>
</div><p>A small problem with task to optimize it help me to write two blog post :D. If we find more better approach then there might be a third post to cover that :D.</p></description>
</item>
<item>
<title>The Fizzbuzz Problem</title>
<link>https://BhaveshSGupta.me/blog/the-fizzbuzz-problem/</link>
<pubDate>Sun, 31 Jan 2021 16:42:25 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/the-fizzbuzz-problem/</guid>
<description><p>Recently I have been giving few interviews and I have faced this problem twice or thrice I guess where an interviewer asks me this problem.</p>
<p>The essence of problem goes like this, the task is to print 1 to N (In most cases N is 100), where if number is divisible by 3 you would print fizz, if its divisible by 5 you would print buzz, if its divisible by both then print fizzbuzz.</p>
<p>Lets see output when N is let say 15:</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-14">14</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-15"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-15">15</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#40a070">1</span>
</span></span><span style="display:flex;"><span><span style="color:#40a070">2</span>
</span></span><span style="display:flex;"><span>fizz
</span></span><span style="display:flex;"><span><span style="color:#40a070">4</span>
</span></span><span style="display:flex;"><span>buzz
</span></span><span style="display:flex;"><span>fizz
</span></span><span style="display:flex;"><span><span style="color:#40a070">7</span>
</span></span><span style="display:flex;"><span><span style="color:#40a070">8</span>
</span></span><span style="display:flex;"><span>fizz
</span></span><span style="display:flex;"><span>buzz
</span></span><span style="display:flex;"><span><span style="color:#40a070">11</span>
</span></span><span style="display:flex;"><span>fizz
</span></span><span style="display:flex;"><span><span style="color:#40a070">13</span>
</span></span><span style="display:flex;"><span><span style="color:#40a070">14</span>
</span></span><span style="display:flex;"><span>fizzbuzz
</span></span></code></pre></td></tr></table>
</div>
</div><p>The problem seems very simple in nature but it is an interesting problem to try when you are learning a new language. As I have been giving interviews in Javascript and python I would try to put of solution in both language.</p>
<p>PS: Here I am considering N to be 100 ;)</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6">6</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> (number <span style="color:#666">=</span> <span style="color:#40a070">1</span>; number <span style="color:#666">&lt;=</span> <span style="color:#40a070">100</span>; number<span style="color:#666">++</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span> <span style="color:#666">&amp;&amp;</span> number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) console.log(<span style="color:#4070a0">&#34;fizzbuzz&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) console.log(<span style="color:#4070a0">&#34;fizz&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) console.log(<span style="color:#4070a0">&#34;buzz&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> console.log(number)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-5">5</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> number <span style="color:#007020;font-weight:bold">in</span> <span style="color:#007020">range</span>(<span style="color:#40a070">1</span>, <span style="color:#40a070">101</span>):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span> <span style="color:#007020;font-weight:bold">and</span> number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizzbuzz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;buzz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>: <span style="color:#007020">print</span>(number)
</span></span></code></pre></td></tr></table>
</div>
</div><p>Above solution are correct, but if we see it from optimizing prospective then it is not optimize. We are doing same operation multiple times i.e. we are taking modulo of 3 and 5 twice, first in common case then again in else if cases.</p>
<p>First step towards optimizing it could be as follows</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-7">7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-8">8</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> (number <span style="color:#666">=</span> <span style="color:#40a070">1</span>; number <span style="color:#666">&lt;=</span> <span style="color:#40a070">100</span>; number<span style="color:#666">++</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">let</span> modulo3 <span style="color:#666">=</span> number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">let</span> modulo5 <span style="color:#666">=</span> number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(modulo3 <span style="color:#666">&amp;&amp;</span> modulo5) console.log(<span style="color:#4070a0">&#34;fizzbuzz&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(modulo3) console.log(<span style="color:#4070a0">&#34;fizz&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> <span style="color:#007020;font-weight:bold">if</span>(modulo5) console.log(<span style="color:#4070a0">&#34;buzz&#34;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> console.log(number)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-7">7</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> number <span style="color:#007020;font-weight:bold">in</span> <span style="color:#007020">range</span>(<span style="color:#40a070">1</span>, <span style="color:#40a070">101</span>):
</span></span><span style="display:flex;"><span> modulo3 <span style="color:#666">=</span> number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span> modulo5 <span style="color:#666">=</span> number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(modulo3 <span style="color:#007020;font-weight:bold">and</span> modulo5): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizzbuzz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(modulo3): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;fizz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">elif</span>(modulo5): <span style="color:#007020">print</span>(<span style="color:#4070a0">&#39;buzz&#39;</span>)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>: <span style="color:#007020">print</span>(number)
</span></span></code></pre></td></tr></table>
</div>
</div><p>How above approach is more optimize then previous one can be said by,
In previous approach lets say number is 5, then there would 3 modulo operation would be runnning while in the newer approach for any case there would just two modulo operation and we are storing two number.</p>
<p>I recently learned this from Arnav also known as <a href="https://twitter.com/championswimmer">championswimmer</a>. He was talking about same at this <a href="https://www.youtube.com/watch?v=UYMP-cMy_zg">video</a> on the youtube channel of <a href="https://www.youtube.com/channel/UCICWIYEx2mo4wYZzLwJ7wVw">Coding Blocks</a> where he optimize it even more then this.</p>
<p>In above video he showed on of the way to optimize it even better with two modulo and single storage the example he had shown was in kotlin and it goes as follows.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-12">12</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-kotlin" data-lang="kotlin"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">fun</span> <span style="color:#06287e">main</span> (){
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">for</span> (i <span style="color:#007020;font-weight:bold">in</span> <span style="color:#40a070">1.</span>.<span style="color:#40a070">100</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">var</span> d = <span style="color:#4070a0">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(i % <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) { d<span style="color:#666">+=</span> <span style="color:#4070a0">&#34;fizz&#34;</span> }
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(i % <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) { d<span style="color:#666">+=</span> <span style="color:#4070a0">&#34;buzz&#34;</span> }
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(d <span style="color:#666">==</span> <span style="color:#4070a0">&#34;&#34;</span> ) {
</span></span><span style="display:flex;"><span> println(i)
</span></span><span style="display:flex;"><span> } <span style="color:#007020;font-weight:bold">else</span> {
</span></span><span style="display:flex;"><span> println(d)
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><p>We can optimize our solution even better with above approach lets try that as well.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-6-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-6-7">7</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> (number <span style="color:#666">=</span> <span style="color:#40a070">1</span>; number <span style="color:#666">&lt;=</span> <span style="color:#40a070">100</span>; number<span style="color:#666">++</span>) {
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">let</span> outcome <span style="color:#666">=</span> <span style="color:#4070a0">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#34;fizz&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#34;buzz&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(outcome) console.log(outcome)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span> console.log(number)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-7-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-7-6">6</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">for</span> number <span style="color:#007020;font-weight:bold">in</span> <span style="color:#007020">range</span>(<span style="color:#40a070">1</span>, <span style="color:#40a070">101</span>):
</span></span><span style="display:flex;"><span> outcome <span style="color:#666">=</span> <span style="color:#4070a0">&#34;&#34;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">3</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) : outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#39;fizz&#39;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(number <span style="color:#666">%</span> <span style="color:#40a070">5</span> <span style="color:#666">==</span> <span style="color:#40a070">0</span>) : outcome <span style="color:#666">+=</span> <span style="color:#4070a0">&#39;buzz&#39;</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(outcome <span style="color:#666">!=</span> <span style="color:#4070a0">&#34;&#34;</span>) : <span style="color:#007020">print</span>(outcome)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>: <span style="color:#007020">print</span>(number)
</span></span></code></pre></td></tr></table>
</div>
</div><p>PS: There has been some newer development on optimizing code and the newer approach we took. I had a brief discussion with Vijay aka Punnysher and Anop aka manchurian/potato :D.
There would be another update to this.</p></description>
</item>
<item>
<title>First and Last post of 2020</title>
<link>https://BhaveshSGupta.me/blog/first-and-last-2020/</link>
<pubDate>Thu, 31 Dec 2020 23:11:46 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/first-and-last-2020/</guid>
<description><h2 id="2020">2020</h2>
<p>2020, has been amazing year by far. Have experience so much this year which is unbelievable. Although I have not written anything then these two lines. But this would a memorable year in lot of sense.</p>
<p>Cheers,
Happy New Year everyone,
Happy 2021</p>
</description>
</item>
<item>
<title>Convert Excel to Json</title>
<link>https://BhaveshSGupta.me/blog/convert-excel-to-json/</link>
<pubDate>Sat, 14 Sep 2019 19:54:55 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/convert-excel-to-json/</guid>
<description><p>Some time in our projects we need data in json files(mostly web projects). But collecting and managing data in json files is harder(At least this is what I feel) compared to excel. I had recently ran into a similar situation where I need some data. Data is going to be provided by a non-technical person/client. And there going to be several rounds of it.</p>
<p>So I was looking for options what can be done here, where I found several online tools which could be used for same. But I don&rsquo;t want to use that because of course privacy. I don&rsquo;t want to upload an excel file to a unknown application which would process it server side give me results.</p>
<p>My search ended upon <a href="https://www.npmjs.com/package/simple-excel-to-json">this</a>. I found this nodejs module which was supper easy to use which would read your excel file and return a json object. So I created a small nodejs project which help me achieving solution to the problem.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-7">7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-8">8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-9">9</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-js" data-lang="js"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">var</span> parser <span style="color:#666">=</span> require(<span style="color:#4070a0">&#39;simple-excel-to-json&#39;</span>)
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">var</span> doc <span style="color:#666">=</span> parser.parseXls2Json(<span style="color:#4070a0">&#39;sample.xlsx&#39;</span>, { isNested<span style="color:#666">:</span> <span style="color:#007020;font-weight:bold">true</span> });
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">const</span> fs <span style="color:#666">=</span> require(<span style="color:#4070a0">&#39;fs&#39;</span>);
</span></span><span style="display:flex;"><span>fs.writeFileSync(<span style="color:#4070a0">&#34;sample.json&#34;</span>,JSON.stringify(doc[<span style="color:#40a070">0</span>], <span style="color:#007020;font-weight:bold">null</span>, <span style="color:#40a070">2</span>), <span style="color:#007020;font-weight:bold">function</span>(err) {
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span>(err) {
</span></span><span style="display:flex;"><span> console.log(<span style="color:#4070a0">&#34;There was an error!&#34;</span>);
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> console.log(err);
</span></span><span style="display:flex;"><span> }
</span></span><span style="display:flex;"><span>});
</span></span></code></pre></td></tr></table>
</div>
</div><p>So <a href="https://github.com/BhaveshSGupta/excel-to-json-demo">here</a> is a repository link to source code. To run this you would need nodejs in your system.</p>
<p>You would need to a <code>npm install</code> and <code>node index.js</code> to this working.</p>
</description>
</item>
<item>
<title>Another Attempt at Wag3</title>
<link>https://BhaveshSGupta.me/blog/another-attempt-at-wag3/</link>
<pubDate>Sun, 25 Aug 2019 16:57:46 +0530</pubDate>
<author>[email protected] (Bhavesh S. Gupta)</author>
<guid>https://BhaveshSGupta.me/blog/another-attempt-at-wag3/</guid>
<description><p>Until now we had done as of following code. We would create couples of more functions which would help us in managing our application. As discussed earlier we would now we creating different directories and files present inside .git directory along with directory itself. More or less we would something like following directory structure after doing <code>wag init</code></p>
<ul>
<li>.git is the git directory itself, which contains:
<ul>
<li>.git/objects/ : the object store, which we’ll introduce in the next section.</li>
<li>.git/refs/ the reference store, which we’ll discuss . It contains two subdirectories, heads and tags.</li>
<li>.git/HEAD, a reference to the current HEAD (more on that later!)</li>
<li>.git/config, the repository’s configuration file.</li>
<li>.git/description, the repository’s description file.</li>
</ul>
</li>
</ul>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-14">14</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-15"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-15">15</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-16"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-16">16</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-17"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-17">17</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-18"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-18">18</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-19"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-19">19</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-20"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-20">20</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-21"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-21">21</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-22"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-22">22</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-23"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-23">23</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-24"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-24">24</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-25"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-25">25</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-26"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-26">26</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-27"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-27">27</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-28"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-28">28</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-29"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-29">29</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-30"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-30">30</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-31"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-31">31</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-32"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-32">32</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-33"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-33">33</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-34"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-34">34</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-35"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-35">35</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-36"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-36">36</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-37"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-37">37</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-38"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-38">38</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-39"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-39">39</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-40"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-40">40</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-41"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-41">41</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-42"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-42">42</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-43"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-43">43</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-44"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-44">44</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-45"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-45">45</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-46"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-46">46</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-0-47"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-0-47">47</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">import</span> <span style="color:#0e84b5;font-weight:bold">sys</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">import</span> <span style="color:#0e84b5;font-weight:bold">argparse</span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">import</span> <span style="color:#0e84b5;font-weight:bold">os</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>argparser <span style="color:#666">=</span> argparse<span style="color:#666">.</span>ArgumentParser(description<span style="color:#666">=</span><span style="color:#4070a0">&#34;Another Content Tracker&#34;</span>)
</span></span><span style="display:flex;"><span>argsubparsers <span style="color:#666">=</span> argparser<span style="color:#666">.</span>add_subparsers(title<span style="color:#666">=</span><span style="color:#4070a0">&#34;Commands&#34;</span>, dest<span style="color:#666">=</span><span style="color:#4070a0">&#34;command&#34;</span>)
</span></span><span style="display:flex;"><span>argsubparsers<span style="color:#666">.</span>required <span style="color:#666">=</span> <span style="color:#007020;font-weight:bold">True</span>
</span></span><span style="display:flex;"><span>argsp <span style="color:#666">=</span> argsubparsers<span style="color:#666">.</span>add_parser(
</span></span><span style="display:flex;"><span> <span style="color:#4070a0">&#34;init&#34;</span>, help<span style="color:#666">=</span><span style="color:#4070a0">&#34;Initialize a new, empty repository.&#34;</span>)
</span></span><span style="display:flex;"><span>argsp<span style="color:#666">.</span>add_argument(<span style="color:#4070a0">&#34;path&#34;</span>, metavar<span style="color:#666">=</span><span style="color:#4070a0">&#34;directory&#34;</span>, nargs<span style="color:#666">=</span><span style="color:#4070a0">&#34;?&#34;</span>,
</span></span><span style="display:flex;"><span> default<span style="color:#666">=</span><span style="color:#4070a0">&#34;.&#34;</span>, help<span style="color:#666">=</span><span style="color:#4070a0">&#34;Where to create the repository.&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">main</span>(argv<span style="color:#666">=</span>sys<span style="color:#666">.</span>argv[<span style="color:#40a070">1</span>:]):
</span></span><span style="display:flex;"><span> args <span style="color:#666">=</span> argparser<span style="color:#666">.</span>parse_args(argv)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> args<span style="color:#666">.</span>command <span style="color:#666">==</span> <span style="color:#4070a0">&#34;init&#34;</span>:
</span></span><span style="display:flex;"><span> cmd_init(args)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">cmd_init</span>(args):
</span></span><span style="display:flex;"><span> repo_create(args<span style="color:#666">.</span>path)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">class</span> <span style="color:#0e84b5;font-weight:bold">GitRepository</span>(<span style="color:#007020">object</span>):
</span></span><span style="display:flex;"><span> <span style="color:#4070a0">&#34;&#34;&#34;A git repository&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span> worktree <span style="color:#666">=</span> <span style="color:#007020;font-weight:bold">None</span>
</span></span><span style="display:flex;"><span> gitdir <span style="color:#666">=</span> <span style="color:#007020;font-weight:bold">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">def</span> __init__(self, path, force<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">False</span>):
</span></span><span style="display:flex;"><span> self<span style="color:#666">.</span>worktree <span style="color:#666">=</span> path
</span></span><span style="display:flex;"><span> self<span style="color:#666">.</span>gitdir <span style="color:#666">=</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>join(path, <span style="color:#4070a0">&#34;.git&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_create</span>(path):
</span></span><span style="display:flex;"><span> <span style="color:#4070a0">&#34;&#34;&#34;Create a new repository at path.&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span> repo <span style="color:#666">=</span> GitRepository(path)
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># We check whether there exsits a path of worktree</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>exists(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># if path exsits its a directory or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> <span style="color:#007020;font-weight:bold">not</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>isdir(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;</span><span style="color:#70a0d0">%s</span><span style="color:#4070a0"> is not a directory!&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># if path exsits its empty or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>listdir(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;</span><span style="color:#70a0d0">%s</span><span style="color:#4070a0"> is not empty!&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>:
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># Create directory as nothing exist with same path</span>
</span></span><span style="display:flex;"><span> os<span style="color:#666">.</span>makedirs(repo<span style="color:#666">.</span>worktree)
</span></span></code></pre></td></tr></table>
</div>
</div><p>Now let&rsquo;s create function which would gives us path of directory after verifying that the directory exist and if it doesn&rsquo;t it should gives us an error. We would also require mechanism to check whether we need to create the directory or not if it doesn&rsquo;t exists.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-14">14</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-15"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-15">15</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-16"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-16">16</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-17"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-17">17</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-18"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-18">18</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-19"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-19">19</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-20"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-20">20</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-21"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-21">21</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-22"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-22">22</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-23"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-23">23</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-24"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-24">24</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-25"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-25">25</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-1-26"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-1-26">26</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_dir</span>(repo, <span style="color:#666">*</span>path, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">False</span>):
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># repo is for our GitRepository object as we want to work with repository.</span>
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># *path is the path we want to check</span>
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># mkdir to specify whether we want to create directory or not.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># this function would give us path we want to check if it exist or not</span>
</span></span><span style="display:flex;"><span> path <span style="color:#666">=</span> repo_path(repo, <span style="color:#666">*</span>path)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># This would check whether path exists and if it does then it would check if it is a directory or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>exists(path):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> (os<span style="color:#666">.</span>path<span style="color:#666">.</span>isdir(path)):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> path
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>:
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;Not a directory </span><span style="color:#70a0d0">%s</span><span style="color:#4070a0">&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># This would check if we need to create directory as it doesn&#39;t exists</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> mkdir:
</span></span><span style="display:flex;"><span> os<span style="color:#666">.</span>makedirs(path)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> path
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>:
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> <span style="color:#007020;font-weight:bold">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_path</span>(repo, <span style="color:#666">*</span>path):
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># This would return us path under repository git directory</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>join(repo<span style="color:#666">.</span>gitdir, <span style="color:#666">*</span>path)
</span></span></code></pre></td></tr></table>
</div>
</div><p>We have created another <code>repo_path</code> function which is gives us path based on our git directory. Now we would add for these in our <code>repo_create()</code></p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-14">14</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-15"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-15">15</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-16"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-16">16</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-17"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-17">17</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-18"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-18">18</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-19"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-19">19</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-2-20"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-2-20">20</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_create</span>(path):
</span></span><span style="display:flex;"><span> <span style="color:#4070a0">&#34;&#34;&#34;Create a new repository at path.&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span> repo <span style="color:#666">=</span> GitRepository(path)
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># We check whether there exists a path of worktree</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>exists(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># if path exists its a directory or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> <span style="color:#007020;font-weight:bold">not</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>isdir(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;</span><span style="color:#70a0d0">%s</span><span style="color:#4070a0"> is not a directory!&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># if path exists its empty or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>listdir(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;</span><span style="color:#70a0d0">%s</span><span style="color:#4070a0"> is not empty!&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>:
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># Create directory as nothing exist with same path</span>
</span></span><span style="display:flex;"><span> os<span style="color:#666">.</span>makedirs(repo<span style="color:#666">.</span>worktree)
</span></span><span style="display:flex;"><span> repo_path(repo, <span style="color:#4070a0">&#34;branches&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;branches&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;objects&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;refs&#34;</span>, <span style="color:#4070a0">&#34;tags&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;refs&#34;</span>, <span style="color:#4070a0">&#34;heads&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span></code></pre></td></tr></table>
</div>
</div><p>Above would create <code>.git</code> directory with <code>braches</code>, <code>objects</code> and <code>refs</code> directory with <code>tags</code> and <code>heads</code> under it. It would look as follows:</p>
<ul>
<li>.git
<ul>
<li>objects</li>
<li>branches</li>
<li>refs
<ul>
<li>tags</li>
<li>heads</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><code>Assert()</code> helps us to identify that all these directories are created. If there is some issue and we return None from function it would show assertation error.</p>
<p>Besides directories there are few files which are also created when you do a git init, so those also needs to be created when we <code>wag init</code>. Those files are config, HEAD and description others too but for now we would concentrate on these three.</p>
<p>Now these files could be created anywhere and that directory may or may not exist so we would so let&rsquo;s create a function which would create these directories if require. Also lets open description file and write &ldquo;Unnamed repository; edit this file &lsquo;description&rsquo; to name the repository.&rdquo; into that. We need to change this in our <code>repo_create</code> function</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-6"> 6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-7"> 7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-8"> 8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-9"> 9</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-10"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-10">10</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-11"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-11">11</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-12"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-12">12</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-13"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-13">13</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-14"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-14">14</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-15"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-15">15</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-16"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-16">16</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-17"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-17">17</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-18"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-18">18</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-19"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-19">19</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-20"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-20">20</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-21"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-21">21</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-22"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-22">22</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-23"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-23">23</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-24"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-24">24</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-25"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-25">25</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-26"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-26">26</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-3-27"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-3-27">27</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_create</span>(path):
</span></span><span style="display:flex;"><span> <span style="color:#4070a0">&#34;&#34;&#34;Create a new repository at path.&#34;&#34;&#34;</span>
</span></span><span style="display:flex;"><span> repo <span style="color:#666">=</span> GitRepository(path)
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># We check whether there exists a path of worktree</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>exists(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># if path exists its a directory or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> <span style="color:#007020;font-weight:bold">not</span> os<span style="color:#666">.</span>path<span style="color:#666">.</span>isdir(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;</span><span style="color:#70a0d0">%s</span><span style="color:#4070a0"> is not a directory!&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># if path exists its empty or not</span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> os<span style="color:#666">.</span>listdir(repo<span style="color:#666">.</span>worktree):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">raise</span> <span style="color:#007020">Exception</span>(<span style="color:#4070a0">&#34;</span><span style="color:#70a0d0">%s</span><span style="color:#4070a0"> is not empty!&#34;</span> <span style="color:#666">%</span> path)
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">else</span>:
</span></span><span style="display:flex;"><span> <span style="color:#60a0b0;font-style:italic"># Create directory as nothing exist with same path</span>
</span></span><span style="display:flex;"><span> os<span style="color:#666">.</span>makedirs(repo<span style="color:#666">.</span>worktree)
</span></span><span style="display:flex;"><span> repo_path(repo, <span style="color:#4070a0">&#34;branches&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;branches&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;objects&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;refs&#34;</span>, <span style="color:#4070a0">&#34;tags&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">assert</span>(repo_dir(repo, <span style="color:#4070a0">&#34;refs&#34;</span>, <span style="color:#4070a0">&#34;heads&#34;</span>, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">True</span>))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">with</span> <span style="color:#007020">open</span>(repo_file(repo, <span style="color:#4070a0">&#34;description&#34;</span>), <span style="color:#4070a0">&#34;w&#34;</span>) <span style="color:#007020;font-weight:bold">as</span> f:
</span></span><span style="display:flex;"><span> f<span style="color:#666">.</span>write(<span style="color:#4070a0">&#34;Unnamed repository; edit this file &#39;description&#39; to name the repository.</span><span style="color:#4070a0;font-weight:bold">\n</span><span style="color:#4070a0">&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_file</span>(repo, <span style="color:#666">*</span>path, mkdir<span style="color:#666">=</span><span style="color:#007020;font-weight:bold">False</span>):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">if</span> repo_dir(repo, <span style="color:#666">*</span>path[:<span style="color:#666">-</span><span style="color:#40a070">1</span>], mkdir<span style="color:#666">=</span>mkdir):
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> repo_path(repo, <span style="color:#666">*</span>path)
</span></span></code></pre></td></tr></table>
</div>
</div><p>For config file we would need to use config parser module which would create a config file in Microsoft’s INI format. So first let&rsquo;s create a function which would create default config. We would need to import this module with below modules.
In default config there are thing fields,</p>
<ul>
<li>repositoryformatversion whose value we would set to 0, for more info visit <a href="https://github.com/git/git/blob/00a09d57eb8a041e6a6b0470c53533719c049bab/Documentation/technical/repository-version.txt">here</a>. Our program would be compatible with only 0 format version only</li>
<li>filemode whose value would be set to false, it disables tacking of file mode changes</li>
<li>bare whose value would be false. It indicates that this repository has a work. Git supports an optional worktree key which indicates location of the worktree, if not <code>..</code>(parent repository)</li>
</ul>
<p>All these keys are under core section so first we would add section and then set this config.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-1">1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-2">2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-3">3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-4">4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-5">5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-6">6</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-7"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-7">7</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-8"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-8">8</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-4-9"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-4-9">9</a>
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-py" data-lang="py"><span style="display:flex;"><span><span style="color:#007020;font-weight:bold">def</span> <span style="color:#06287e">repo_default_config</span>():
</span></span><span style="display:flex;"><span> ret <span style="color:#666">=</span> configparser<span style="color:#666">.</span>ConfigParser()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> ret<span style="color:#666">.</span>add_section(<span style="color:#4070a0">&#34;core&#34;</span>)
</span></span><span style="display:flex;"><span> ret<span style="color:#666">.</span>set(<span style="color:#4070a0">&#34;core&#34;</span>, <span style="color:#4070a0">&#34;repositoryformatversion&#34;</span>, <span style="color:#4070a0">&#34;0&#34;</span>)
</span></span><span style="display:flex;"><span> ret<span style="color:#666">.</span>set(<span style="color:#4070a0">&#34;core&#34;</span>, <span style="color:#4070a0">&#34;filemode&#34;</span>, <span style="color:#4070a0">&#34;false&#34;</span>)
</span></span><span style="display:flex;"><span> ret<span style="color:#666">.</span>set(<span style="color:#4070a0">&#34;core&#34;</span>, <span style="color:#4070a0">&#34;bare&#34;</span>, <span style="color:#4070a0">&#34;false&#34;</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span> <span style="color:#007020;font-weight:bold">return</span> ret
</span></span></code></pre></td></tr></table>
</div>
</div><p>Now let&rsquo;s update our <code>repo_create</code> function to create config and Head file.</p>
<div class="highlight"><div style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">
<table style="border-spacing:0;padding:0;margin:0;border:0;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-1"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-1"> 1</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-2"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-2"> 2</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-3"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-3"> 3</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-4"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-4"> 4</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-5"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-5"> 5</a>
</span><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f" id="hl-5-6"><a style="outline:none;text-decoration:none;color:inherit" href="#hl-5-6"> 6</a>