Skip to content

Commit 053f92e

Browse files
committedMar 2, 2018
Haiku Genrator
1 parent e9e283d commit 053f92e

File tree

7 files changed

+94
-18
lines changed

7 files changed

+94
-18
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ obj/ProgramingChallenges.csproj.nuget.cache
33
obj/ProgramingChallenges.csproj.nuget.g.props
44
obj/ProgramingChallenges.csproj.nuget.g.targets
55
obj/project.assets.json
6+
Polygon/*
7+
.vscode

‎.vscode/settings.json

-11
This file was deleted.

‎README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ If you have any questions, you can contact me by email morasiu2@gmail.com
1818
1. [10 Random Sentence Generator](#10)
1919
1. [11 Password Generator](#11)
2020
1. [12 Internet Time](#12)
21-
-----
21+
1. [13 Haiku Generator](#13)
2222
## Bonus
2323
1. [Loading animation](#bonus1)
24-
24+
-----
2525
## Progress
2626
All - **100** <br>
27-
Done - **13** <br>
28-
Remain - **89** <br>
27+
Done - **14** <br>
28+
Remain - **88** <br>
2929

3030
* <a name="00">00</a> Name Generator - 29.01.2018 *Done* (`Python 3`) <br>
3131
![00](docs/images/00.png)
@@ -60,5 +60,7 @@ Definitions are form [FreeDictionary](https://www.thefreedictionary.com/) </br>
6060
* <a name="12">12</a> ~~Internet Time~~ Clock - 01.03.2018 *Done* (`C#`)
6161
Why Clock? I found Internet Time quite boring challenge so I've made clock with ASCII art. <br>
6262
![12](docs/images/12.png)
63+
* <a name="13">13</a> Haiku Generator - 02.03.2018 *Done* (`C#`) <br>
64+
![13](docs/images/13.png)
6365
## Bonus
6466
* <a name="bonus1">Bonus 1</a> Loading animation in console 24.02.2018 *Done* (`C#`)![Bonus 1](docs/images/bonus1.gif)

‎challenges/12_Clock/Clock.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading;
33
using System.Collections.Generic;
4+
45
class Clock{
56
static void Main(string[] args){
67
Console.ForegroundColor = ConsoleColor.Green;
@@ -12,12 +13,14 @@ static void Main(string[] args){
1213
}
1314

1415
static string GetTime(){
15-
DateTime time = DateTime.Now;
16-
string sTime = time.ToString("HH:mm:ss");
17-
return sTime;
16+
// Get time from system
17+
DateTime time = DateTime.Now;
18+
string sTime = time.ToString("HH:mm:ss");
19+
return sTime;
1820
}
1921

2022
static void StartClock(){
23+
//Infite loop with our clock :)
2124
List<string> arts = new List<string>();
2225
string time;
2326
string clock = "";
@@ -40,6 +43,7 @@ static void StartClock(){
4043
}
4144

4245
static string GetACIIArt(char c){
46+
// Get ASCII art
4347
string art = "";
4448
switch (c){
4549
case '0':
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Net;
5+
6+
class Haiku{
7+
static void Main(string[] args){
8+
Console.ForegroundColor = ConsoleColor.Green;
9+
Console.WriteLine("<-----------Haiku Genrator------------>");
10+
Console.WriteLine("Created by Morasiu (morasiu2@gmail.com)");
11+
Console.WriteLine("It may take a while. Don't worry, be happy.");
12+
Generate();
13+
Console.ReadKey();
14+
}
15+
16+
static void Generate(){
17+
//Template for Haiku
18+
//From 4-syllabes
19+
//To 6-syllabes
20+
//5-syllabes
21+
string haiku = "";
22+
string[] words = GetWords();
23+
haiku += "From " + words[0] + "\n";
24+
haiku += "to " + words[1] + " " + words[2] + "\n";
25+
haiku += words[3] + " " + words[4] + ".";
26+
Console.WriteLine(haiku);
27+
}
28+
29+
static string[] GetWords(){
30+
List<string> words = new List<string>() {"", "", "", "", ""};
31+
while(words.Contains("")){
32+
string word = GetWord();
33+
int syllabes = CountSyllabes(word);
34+
if(words[0] == "" && syllabes == 4) words[0] = word;
35+
else if(words[1] == "" && syllabes == 2) words[1] = word;
36+
else if(syllabes == 4) words[2] = word;
37+
else if(syllabes == 2) words[3] = word;
38+
else if(syllabes == 3) words[4] = word;
39+
}
40+
41+
return words.ToArray();
42+
}
43+
44+
static int CountSyllabes(string word){
45+
//Count syllabes, simple as that. It works, but have a few exception like "pure" or "Language". Damn you English.
46+
string wordLow = word.ToLower();
47+
int syllabes = 0;
48+
// string consonants = "bcdfghjklmnqprstvwxz";
49+
string vovels = "aeiouy";
50+
51+
for (int i = 0; i < wordLow.Length; i++){
52+
if (i < wordLow.Length - 1){
53+
if (vovels.Contains(wordLow[i].ToString()) && !vovels.Contains(wordLow[i+1].ToString()))
54+
syllabes++;
55+
} else if (i == wordLow.Length - 1){
56+
if (vovels.Contains(wordLow[i].ToString()))
57+
syllabes++;
58+
}
59+
}
60+
return syllabes;
61+
}
62+
63+
static string GetWord(){
64+
//Copied from 08_Hangman
65+
//Get a word from https://fakena.me/random-english-words/one/
66+
WebClient client = new WebClient();
67+
string url = "https://fakena.me/random-english-words/one/";
68+
string line = "";
69+
//Check internet connection
70+
try{
71+
line = client.DownloadString(url).Split('\n')[27];
72+
} catch (System.Net.WebException) {
73+
Console.WriteLine("Network connection problem :(");
74+
System.Environment.Exit(1);
75+
}
76+
string word = line.Substring(39).Split('<')[0];
77+
return word;
78+
}
79+
}
5 KB
Binary file not shown.

‎docs/images/13.png

6.63 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.