-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC# Stuffs
More file actions
121 lines (118 loc) · 4.11 KB
/
C# Stuffs
File metadata and controls
121 lines (118 loc) · 4.11 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace leetcode_NumberOfSteps
{
class Program
{
static void Main(string[] args)
{
//change number of steps to see how many steps it will take to divide a number until 0.
NumberOfSteps(100);
Console.WriteLine();
}
//This code could be much cleaner without comments
static void NumberOfSteps(int num)
{
Console.WriteLine("Number is {0}", num);
int steps = 0;
int half = num;
while (num > 0)
{
if (num % 2 == 0)
{
Console.WriteLine("Divinding {0} by two", num);
num = num / 2;
++steps;
}
else if (num % 2 != 0)
{
Console.WriteLine("Subtracting 1 from {0}", num);
num = num - 1;
++steps;
}
Console.WriteLine("Number is {0}", num);
Console.WriteLine("Number of Steps: {0}", steps);
}
}
//Cleaned code, submitted to LeetCode. Doesn't work as typed in VS19.
/*
public class Solution
{
public int NumberOfSteps(int num)
{
int steps = 0;
while (num != 0)
{
if (num % 2 == 0)
{
num = num / 2;
++steps;
}
else
{
--num;
++steps;
}
}
return;
}
}
*/
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EB5CBDE2-F8B9-44E2-B910-C5D0A9E0EFE1}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>leetcode_NumberOfSteps</RootNamespace>
<AssemblyName>leetcode NumberOfSteps</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>