Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions 01-Introduction/Alarms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ public class Alarms
{
public int countAlarms(int[] volume, int S)
{
return default(int);
int count=0;
int j=0;
while (S>0)
{
S = S - volume[0];
var tmp = volume[0];
for(var i = 1; i < volume.Length; i++)
{
volume[i - 1] = volume[i];
}
volume[volume.Length - 1] = tmp;
count++;
}

return count;
}

#region Testing code
Expand Down Expand Up @@ -56,7 +70,7 @@ private static Boolean KawigiEdit_RunTest(int testNum, int[] p0, int p1, Boolean
Console.WriteLine("");
return res;
}
public static void Run() {
public static void Main() {
Boolean all_right;
all_right = true;

Expand Down
16 changes: 14 additions & 2 deletions 01-Introduction/Ameba.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ public class Ameba
{
public int simulate(int[] X, int A)
{
return default(int);
int i=0;
int len = X.Length;
while (i<len)
{
if (A == X[i])
{
A = 2*A;
}
i++;
}

return A;
}

#region Testing code
Expand Down Expand Up @@ -56,7 +67,7 @@ private static Boolean KawigiEdit_RunTest(int testNum, int[] p0, int p1, Boolean
Console.WriteLine("");
return res;
}
public static void Run() {
public static void Main() {
Boolean all_right;
all_right = true;

Expand Down Expand Up @@ -100,3 +111,4 @@ public static void Run() {
}
#endregion
}

53 changes: 49 additions & 4 deletions 01-Introduction/RobotOnMoon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,53 @@ public class RobotOnMoon
{
public string isSafeCommand(string[] board, string S)
{
return default(string);
}
int robotRow = 0, robotCol = 0;

// Find the robot's initial position
for (int i = 0; i < board.Length; i++) {
for (int j = 0; j < board[i].Length; j++) {
if (board[i][j] == 'S') {
robotRow = i;
robotCol = j;
break;
}
}
}

foreach (char command in S) {
// Predict next position based on the command
int nextRow = robotRow, nextCol = robotCol;

switch (command) {
case 'U':
nextRow--;
break;
case 'D':
nextRow++;
break;
case 'L':
nextCol--;
break;
case 'R':
nextCol++;
break;
}

// Check if the next position is out of bounds
if (nextRow < 0 || nextRow >= board.Length || nextCol < 0 || nextCol >= board[0].Length) {
return "Dead";
}

// If not out of bounds, check if the next position is not an obstacle to move the robot
if (board[nextRow][nextCol] != '#') {
robotRow = nextRow;
robotCol = nextCol;
}
}

return "Alive";

}

#region Testing code

Expand Down Expand Up @@ -71,7 +116,7 @@ private static Boolean KawigiEdit_RunTest(int testNum, string[] p0, string p1, B
return res;
}

public static void Run()
public static void Main()
{
Boolean all_right;
all_right = true;
Expand Down Expand Up @@ -133,4 +178,4 @@ public static void Run()
}

#endregion
}
}
2 changes: 1 addition & 1 deletion 03-LINQ/GoldSavings.App/GoldSavings.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>GoldSavings.App</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
198 changes: 198 additions & 0 deletions 03-LINQ/GoldSavings.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GoldSavings.App.Model;
using GoldSavings.App.Client;
namespace GoldSavings.App;
using System.Xml.Serialization;

class Program
{
Expand All @@ -19,5 +20,202 @@ static void Main(string[] args)
Console.WriteLine($"The price for {goldPrice.Date} is {goldPrice.Price}");
}


//Zadanie 1.3
// Pobierz ceny złota za ostatni rok
DateTime lastYear = DateTime.Today.AddYears(-1);
DateTime today = DateTime.Today;
List<GoldPrice> lastYearPrices = goldClient.GetGoldPrices(lastYear, today).GetAwaiter().GetResult();

// Znajdź TOP 3 najwyższe i najniższe ceny
var top3HighestPrices = lastYearPrices.OrderByDescending(p => p.Price).Take(3).ToList();
var top3LowestPrices = lastYearPrices.OrderBy(p => p.Price).Take(3).ToList();

var top3HighestPricesQuery = (from p in lastYearPrices orderby p.Price descending select p).Take(3).ToList();
var top3LowestPricesQuery = (from p in lastYearPrices orderby p.Price ascending select p).Take(3).ToList();

Console.WriteLine("TOP 3 highest gold prices in the last year:");
foreach (var price in top3HighestPrices)
{
Console.WriteLine($"Date: {price.Date}, Price: {price.Price}");
}
foreach (var price in top3HighestPricesQuery)
{
Console.WriteLine($"Date: {price.Date}, Price: {price.Price}");
}

Console.WriteLine("TOP 3 lowest gold prices in the last year:");
foreach (var price in top3LowestPrices)
{
Console.WriteLine($"Date: {price.Date}, Price: {price.Price}");
}
foreach (var price in top3LowestPricesQuery)
{
Console.WriteLine($"Date: {price.Date}, Price: {price.Price}");
}


//zadanie 1.4
// Pobierz ceny złota w styczniu 2020
DateTime startJanuary2020 = new DateTime(2020, 01, 01);
DateTime endJanuary2020 = new DateTime(2020, 01, 31);
List<GoldPrice> january2020Prices = goldClient.GetGoldPrices(startJanuary2020, endJanuary2020).GetAwaiter().GetResult();

// Oblicz średnią cenę zakupu w styczniu 2020
double averageBuyPrice = january2020Prices.Average(p => p.Price);

List<GoldPrice> allPricesAfterJanuary2020 = new List<GoldPrice>();

DateTime startPeriod = new DateTime(2020, 02, 01); // Start od lutego 2020
DateTime endPeriod = DateTime.Today; // Do dzisiaj
DateTime tempEnd;

while (startPeriod < endPeriod)
{
tempEnd = startPeriod.AddYears(1) > endPeriod ? endPeriod : startPeriod.AddYears(1).AddDays(-1);
List<GoldPrice> yearlyPrices = goldClient.GetGoldPrices(startPeriod, tempEnd).GetAwaiter().GetResult();
allPricesAfterJanuary2020.AddRange(yearlyPrices);
startPeriod = tempEnd.AddDays(1);
}

var profitableDaysQuery = (from p in allPricesAfterJanuary2020 where ((p.Price - averageBuyPrice) / averageBuyPrice * 100) > 5 select p.Date).ToList();


// Sprawdź, kiedy zysk przekroczył 5%
List<DateTime> profitableDays = new List<DateTime>();
foreach (var price in allPricesAfterJanuary2020)
{
double profit = (price.Price - averageBuyPrice) / averageBuyPrice * 100; // Zysk w procentach
//Console.WriteLine($"Date: {price.Date.ToShortDateString()}, Profit: {profit}%"); // Dodane do debugowania
if (profit > 5) // 5% zysku
{
profitableDays.Add(price.Date);
}

}

// Wyświetl dni, w których zysk przekroczył 5%
Console.WriteLine("Days when the profit exceeded 5%:");
//foreach (var day in profitableDays)
//{
//Console.WriteLine(day.ToShortDateString());
//}


//zadanie 1.5

List<GoldPrice> combinedPrices = new List<GoldPrice>();
// Pobieranie danych za każdy rok oddzielnie i łączenie ich w jedną listę
for (int year = 2019; year <= 2022; year++)
{
DateTime startOfYear = new DateTime(year, 01, 01);
DateTime endOfYear = new DateTime(year, 12, 31);
List<GoldPrice> yearlyPrices = goldClient.GetGoldPrices(startOfYear, endOfYear).GetAwaiter().GetResult();
combinedPrices.AddRange(yearlyPrices);
}

// Sortowanie połączonych danych cenowych od najniższej do najwyższej ceny
var sortedPrices = combinedPrices.OrderBy(p => p.Price).ToList();

// Wybieranie dat dla cen na pozycjach 11-13 w rankingu
if (sortedPrices.Count >= 13) // Upewnienie się, że mamy wystarczającą ilość danych
{
var secondTenDates = sortedPrices.Skip(10).Take(3).Select(p => p.Date).ToList();
var secondTenDatesQuery = (from p in combinedPrices
orderby p.Price
select p.Date)
.Skip(10)
.Take(3)
.ToList();

Console.WriteLine("Dates that open the second ten of the gold price ranking from 2019 to 2022:");
foreach (var date in secondTenDates)
{
Console.WriteLine(date.ToShortDateString());
}
foreach (var date in secondTenDatesQuery)
{
Console.WriteLine(date.ToShortDateString());
}
}
else
{
Console.WriteLine("Not enough data to determine the second ten of the gold price ranking.");
}


//Zadanie 1.6
// Lista lat, dla których chcemy obliczyć średnie ceny
int[] years = new int[] { 2021, 2022, 2023 };
foreach (int year in years)
{
DateTime startOfYear = new DateTime(year, 01, 01);
DateTime endOfYear = new DateTime(year, 12, 31);

// Pobieranie danych cenowych za dany rok
List<GoldPrice> yearlyPrices = goldClient.GetGoldPrices(startOfYear, endOfYear).GetAwaiter().GetResult();

// Obliczanie średniej ceny złota za dany rok, jeśli są dostępne jakiekolwiek dane
if (yearlyPrices.Count > 0)
{
double averagePrice = yearlyPrices.Average(p => p.Price);
Console.WriteLine($"The average gold price in {year} was: {averagePrice}");
double averagePriceQuery = (from p in yearlyPrices select p.Price).Average();
Console.WriteLine($"[Query] The average gold price in {year} was: {averagePriceQuery}");
}
else
{
Console.WriteLine($"No data available for the year {year}.");
}
}


//Zadanie 1.7
// Znajdowanie najlepszego dnia na zakup
var bestBuy = combinedPrices.OrderBy(p => p.Price).FirstOrDefault();

// Znajdowanie najlepszego dnia na sprzedaż po dacie zakupu
var bestSell = combinedPrices.Where(p => p.Date > bestBuy.Date).OrderByDescending(p => p.Price).FirstOrDefault();

// Obliczanie zwrotu z inwestycji (ROI), tylko jeśli znaleziono obie daty
if (bestBuy != null && bestSell != null)
{
double roi = (bestSell.Price - bestBuy.Price) / bestBuy.Price * 100;

// Wyświetlanie wyników
Console.WriteLine($"Najlepszy moment na zakup: {bestBuy.Date.ToShortDateString()}, cena: {bestBuy.Price}");
Console.WriteLine($"Najlepszy moment na sprzedaż: {bestSell.Date.ToShortDateString()}, cena: {bestSell.Price}");
Console.WriteLine($"Zwrot z inwestycji: {roi}%");
}
else
{
Console.WriteLine("Nie można znaleźć optymalnych dat zakupu i sprzedaży w dostępnych danych.");
}

//Zadanie 1.8
string filePath = @"prices.xml";
SavePricesToXml(combinedPrices, filePath);

//Zadanie 1.9
List<GoldPrice> prices = LoadPricesFromXml(filePath);

}

//Zadanie 1.8
public static void SavePricesToXml(List<GoldPrice> prices, string filePath)
{
// Tworzenie XmlSerializer do serializacji obiektów GoldPrice
XmlSerializer serializer = new XmlSerializer(typeof(List<GoldPrice>));

// Utworzenie strumienia plikowego z użyciem ścieżki filePath
using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
{
// Serializacja listy prices do pliku XML
serializer.Serialize(fileStream, prices);
}
}

//Zadanie 1.9
public static List<GoldPrice> LoadPricesFromXml(string filePath) =>
(List<GoldPrice>)new XmlSerializer(typeof(List<GoldPrice>)).Deserialize(new FileStream(filePath, FileMode.Open, FileAccess.Read));
}
Loading