Day 1 done

master
attila 4 years ago
commit e1dfce35e0

1
.gitignore vendored

@ -0,0 +1 @@
target

@ -0,0 +1,29 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/benches" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CargoProjects">
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component>
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/day1.iml" filepath="$PROJECT_DIR$/.idea/day1.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

@ -0,0 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeRunConfigurationManager" shouldGenerate="true" shouldDeleteObsolete="true" buildAllGenerated="false">
<generated />
</component>
<component name="CMakeSettings">
<configurations>
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="4fa19ef7-5edf-4cf5-80c5-1dace056e2f6" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FUSProjectUsageTrigger">
<session id="770093350">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.open.time.0" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="rs" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Rust" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="rs" value="694" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Rust" value="694" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="492">
<caret line="72" column="1" lean-forward="true" selection-start-line="72" selection-start-column="1" selection-end-line="72" selection-end-column="1" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/main.rs" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="-1" />
<option name="y" value="-22" />
<option name="width" value="1922" />
<option name="height" value="1068" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="day1" type="b2602c69:ProjectViewProjectNode" />
<item name="day1" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="day1" type="b2602c69:ProjectViewProjectNode" />
<item name="day1" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="org.rust.cargo.project.model.PROJECT_DISCOVERY" value="true" />
<property name="settings.editor.selected.configurable" value="reference.settingsdialog.IDE.editor.colors" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Cargo Command.Release">
<configuration name="Release" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --release" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<method v="2" />
</configuration>
<configuration name="Unnamed" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="channel" value="DEFAULT" />
<option name="command" value="run" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<method v="2" />
</configuration>
<list>
<item itemvalue="Cargo Command.Unnamed" />
<item itemvalue="Cargo Command.Release" />
</list>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="4fa19ef7-5edf-4cf5-80c5-1dace056e2f6" name="Default Changelist" comment="" />
<created>1543681202606</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1543681202606</updated>
<workItem from="1543681203734" duration="2785000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="2785000" />
</component>
<component name="ToolWindowManager">
<frame x="-1" y="-22" width="1922" height="1068" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2497332" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32910052" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Cargo" />
<window_info anchor="right" id="Database" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/main.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="492">
<caret line="72" column="1" lean-forward="true" selection-start-line="72" selection-start-column="1" selection-end-line="72" selection-end-column="1" />
</state>
</provider>
</entry>
</component>
</project>

4
day1/Cargo.lock generated

@ -0,0 +1,4 @@
[[package]]
name = "day1"
version = "0.1.0"

@ -0,0 +1,6 @@
[package]
name = "day1"
version = "0.1.0"
authors = ["attila <daf276@gmx.de>"]
[dependencies]

@ -0,0 +1,73 @@
use std::collections::HashSet;
fn main() {
let change_in_frequencies: Vec<i32> = "-19,+8,-10,+9,+2,+19,+5,+8,+13,+16,+4,-8,+16,-10,+11,+13,-12,-5,\
-15,-12,+9,-6,-18,+5,+3,+18,-3,+5,-19,+21,-9,-9,+20,-18,+11,+11,+17,+17,-20,-7,+5,+7,+7,+7,+7,\
+16,-12,+18,+10,+3,+15,-10,+8,+5,+7,-16,-16,-2,-15,+3,-6,+9,-15,+19,-12,-20,-1,-12,+11,-22,+10,\
+15,+2,-10,-19,+1,-18,-21,-4,+16,-15,+13,+20,+7,+23,+13,-3,+10,+8,-7,+4,-19,-7,-4,+19,+20,-18,\
-5,+11,+22,-14,+15,-3,+16,+20,-16,-11,-12,+7,-13,+7,+12,+20,+9,-15,+1,-14,+11,+16,+13,+9,-16,\
+18,-8,-6,+17,+7,+15,+7,-15,-15,-14,-16,+15,+17,+19,+6,-16,+13,-12,+20,-18,-11,-8,-14,+18,-11,\
+6,-16,+14,-10,-6,+1,+16,+4,-6,-8,+27,+18,+10,-3,-2,+11,-10,+11,+7,+19,-1,+11,+14,-16,-10,+15,\
-9,+2,-1,+13,-4,+6,-9,+10,-2,-10,+17,-14,-10,+15,+17,-12,-15,+18,+8,+13,+3,+17,+14,+1,+15,+18,\
+7,+15,-2,+9,+3,-1,-18,-15,-11,-10,-1,-14,+13,-18,-2,+5,+5,-7,-5,-12,+4,+19,+15,+9,-17,-10,-5,\
+13,+15,+7,-10,+12,+1,+9,-18,+14,+20,+2,+5,+7,+6,+13,+4,+12,-9,+17,+10,-5,-9,+18,+4,+5,-16,+1,\
+16,+1,-5,+19,-5,+14,-15,-3,+7,-15,+14,-7,+16,+13,+1,+17,-4,-9,+12,+15,+10,+5,+8,+31,+22,+12,\
+16,-17,+9,-21,-13,+22,-1,-2,+17,+14,+34,+18,-15,+10,+14,+11,+4,-9,+13,-12,+7,+3,-15,+6,+5,+21,\
-18,-20,+7,+18,-11,+8,-9,+11,-19,-2,-2,-20,-13,+16,-14,-1,+4,+20,-10,+6,-18,+15,+41,-1,+25,+21,\
+15,+1,-14,-1,-11,+17,-9,-5,-1,+21,-2,+9,+3,-13,-16,+1,+13,-4,-18,-8,-20,-1,+2,+1,+4,-8,-46,-29,\
-16,-5,-36,+35,-144,+3,+2,-7,-1,-11,-20,-22,-12,-18,-2,-18,+8,-18,+3,-1,+7,-18,+7,+19,-12,-19,\
-19,-14,+15,+15,+6,-17,+12,+11,+24,+16,+4,+12,+4,-18,+3,+19,-10,+12,-4,+19,+3,+2,+5,+19,+5,+22,\
-21,+1,-21,-19,+13,-12,+10,-12,-13,-2,-11,-16,-7,+10,-21,-3,+4,+22,+18,+11,+1,-10,+15,+5,-9,+2,\
+1,-24,-1,-2,+6,-26,-15,-16,+9,+25,+14,-7,-27,-24,+16,-30,-30,+26,+12,+3,-32,+3,-10,-4,+8,-19,\
-7,+15,+13,-3,+16,+7,-21,-23,-12,+14,-149,-77,+19,+6,-80,+11,-16,-19,-65,+6,-67327,-14,+16,-15,\
-10,+4,+16,-12,-3,-10,+7,+14,-2,+17,+8,-7,+15,-17,-13,-11,-18,+19,-22,-11,-1,-16,-2,+10,-12,-6,\
+11,+9,+1,+13,+9,-6,+19,-10,-4,-12,+14,+1,+19,+15,+8,-16,+1,+8,+18,-12,-5,+10,+15,-9,-15,+12,+8,\
-9,+3,+16,+5,+14,+18,-1,-5,+4,+17,+12,-9,-12,-15,+11,-19,+1,-13,+17,-11,-11,-14,+8,+10,-15,+18,\
-12,+4,-1,+10,+16,+11,+3,-11,-14,-4,+17,+13,+4,+12,-18,-16,-20,+14,-22,-20,-20,+6,+16,-15,-35,\
-7,-17,-20,+19,-17,-11,-9,-16,-3,+7,-10,-2,+7,+2,+2,+16,+14,+17,-8,-18,+2,-6,+3,-10,-8,+7,+5,\
+18,-20,-13,-17,-17,-7,+9,+13,-17,+16,+4,+12,-3,+1,-12,-7,+16,+13,+1,+14,-3,-4,+16,-21,-20,-17,\
+1,-14,-10,-5,-14,-1,-5,+19,+3,+16,-9,-13,+2,+3,-7,-15,+4,+6,+8,-10,+5,+12,+8,+18,-7,+8,-15,+5,\
-11,-15,+16,+16,+7,-2,+14,+18,+24,+9,+19,+17,+13,-16,-13,-14,-20,-5,+18,-3,+20,+13,+15,+7,+11,\
-15,-22,-15,-6,+18,-8,+18,-6,-24,-12,+21,+17,+18,+40,+22,+27,-4,-16,+17,-10,-18,+49,+15,-12,+7,\
+13,-16,+10,+15,-1,-3,+16,+6,-7,+4,-18,+13,-4,-16,+18,-5,+1,+9,-4,-2,+19,+17,-4,-14,-24,-21,+1,\
+6,-18,+8,+15,-18,-2,-31,-30,+4,+2,-28,-53,-33,+10,-11,-18,-19,-4,-6,-24,-6,-4,+11,-24,-16,+3,\
-1,-1,+13,-15,-10,-7,-3,+8,-11,+2,+5,+8,-3,-7,+15,+1,-11,-11,-2,-4,+16,+5,+14,-24,-14,-22,-11,\
-15,-6,+8,+15,+19,-14,-12,+1,+9,+5,+18,+6,-18,+16,-8,-10,-8,-9,+1,+11,-16,+8,+18,+12,+8,+2,+10,\
+11,-2,+14,+1,+11,-9,-18,-24,+2,-8,+15,-14,-18,+11,+2,-10,-11,-5,-13,-3,-12,-5,-13,+16,+5,-19,\
-16,-12,-4,+10,-15,+14,-6,+3,-18,+17,+12,-2,+6,+13,+16,-11,+3,+3,-20,-6,+8,-9,-19,-3,+16,-14,\
-14,+1,-12,-10,+19,-12,-18,+5,-3,+7,-20,-16,-18,+17,-23,+25,+65,+11,+11,+16,-1,+16,-9,+19,+13,\
-8,-10,+9,-18,-16,-16,-19,+1,-28,+4,+35,+13,+12,+15,-5,-3,+4,+16,+2,+10,+15,+17,+18,+27,+19,+15,\
+13,+6,-17,+12,+15,+9,+23,+78,-221,-28,+19,+18,-13,-22,-11,-5,-5,-9,-16,-2,+11,+30,+10,+28,-4,\
-72,-36,+10,-5,+77,+35,+102,+153,-29,-676,-67225,-5,+13,+19,+3,+15,+7,-11,-1,-7,+13,+17,+17,+6,\
-15,-9,+11,-8,-7,+10,+1,+13,+19,-11,-11,+2,+4,-11,-7,+10,+19,+17,+7,+12,+20,-2,+135638".split(",").map(|s| s.parse().unwrap()).collect();
println!("Frequency after changes: {}", get_frequency_after_changes(&change_in_frequencies));
println!("First repeated frequency: {}", get_first_repeated_frequency(&change_in_frequencies));
}
fn get_frequency_after_changes(change_in_frequencies: &Vec<i32>) -> i32 {
change_in_frequencies.iter().sum()
}
fn get_first_repeated_frequency(change_in_frequencies: &Vec<i32>) -> i32 {
let mut frequency = 0;
let repeated_frequency;
let mut visited_frequencies = HashSet::new();
'outer: loop {
'inner: for change in change_in_frequencies {
frequency += change;
if !visited_frequencies.contains(&frequency) {
visited_frequencies.insert(frequency);
} else {
repeated_frequency = frequency;
break 'outer;
}
}
}
repeated_frequency
}
Loading…
Cancel
Save