Please don’t rely on this Gitea instance being around forever. If any of your build scripts use my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking for there, tell me to migrate it.

Day23 Part 1

master
Karl Spickermann 2 years ago
parent 5dd123ea97
commit e572ed1862

@ -11,9 +11,7 @@
</component>
<component name="ChangeListManager">
<list default="true" id="400bdf61-8921-41d3-8f98-a0a1b0877f46" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/day22/day22.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/day22/day22Test.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/day22/day22Test2.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/day23/day23.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/helper/helper.go" beforeDir="false" afterPath="$PROJECT_DIR$/helper/helper.go" afterDir="false" />
</list>
@ -56,7 +54,7 @@
<recent name="C:\Users\karls\go\src\AoC2020" />
</key>
</component>
<component name="RunManager" selected="Go Build.go build day22.go">
<component name="RunManager" selected="Go Build.go build day23.go">
<configuration name="go build day10.go" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
<module name="AoC2020" />
<working_directory value="$PROJECT_DIR$/day10" />
@ -197,6 +195,16 @@
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="go build day23.go" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
<module name="AoC2020" />
<working_directory value="$PROJECT_DIR$/day23" />
<parameters value="318946572" />
<kind value="FILE" />
<filePath value="$PROJECT_DIR$/day23/day23.go" />
<package value="AoC2020" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="go build day2.go" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
<module name="AoC2020" />
<working_directory value="$PROJECT_DIR$/day2" />
@ -301,6 +309,7 @@
<item itemvalue="Go Build.go build day17.go" />
<item itemvalue="Go Build.go build day20.go" />
<item itemvalue="Go Build.go build day22.go" />
<item itemvalue="Go Build.go build day23.go" />
</list>
<recent_temporary>
<list>
@ -325,59 +334,59 @@
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="WindowStateProjectService">
<state x="351" y="0" width="1092" height="1040" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1608658619075">
<state x="351" y="0" width="1092" height="1040" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1608757578032">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="-1472" y="103" key="#com.intellij.execution.impl.EditConfigurationsDialog/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607019292652" />
<state x="351" y="0" width="1092" height="1040" key="#com.intellij.execution.impl.EditConfigurationsDialog/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658619075" />
<state x="351" y="0" width="1092" height="1040" key="#com.intellij.execution.impl.EditConfigurationsDialog/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757578032" />
<state x="661" y="322" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1606836882379">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="661" y="322" key="#com.intellij.fileTypes.FileTypeChooser/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1606836882379" />
<state width="546" height="466" key="DebuggerActiveHint" timestamp="1608656816732">
<state width="552" height="466" key="DebuggerActiveHint" timestamp="1608757330340">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="546" height="466" key="DebuggerActiveHint/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608656816732" />
<state width="552" height="466" key="DebuggerActiveHint/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757330340" />
<state x="739" y="287" key="FileChooserDialogImpl" timestamp="1607278759015">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="739" y="287" key="FileChooserDialogImpl/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1607278759015" />
<state width="1164" height="235" key="GridCell.Tab.0.bottom" timestamp="1608658595696">
<state width="1161" height="235" key="GridCell.Tab.0.bottom" timestamp="1608757569304">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.bottom/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629475" />
<state width="1164" height="235" key="GridCell.Tab.0.bottom/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658595696" />
<state width="1164" height="235" key="GridCell.Tab.0.center" timestamp="1608658595696">
<state width="1161" height="235" key="GridCell.Tab.0.bottom/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757569304" />
<state width="1161" height="235" key="GridCell.Tab.0.center" timestamp="1608757569304">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.center/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629474" />
<state width="1164" height="235" key="GridCell.Tab.0.center/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658595696" />
<state width="1164" height="235" key="GridCell.Tab.0.left" timestamp="1608658595696">
<state width="1161" height="235" key="GridCell.Tab.0.center/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757569304" />
<state width="1161" height="235" key="GridCell.Tab.0.left" timestamp="1608757569304">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.left/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629474" />
<state width="1164" height="235" key="GridCell.Tab.0.left/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658595696" />
<state width="1164" height="235" key="GridCell.Tab.0.right" timestamp="1608658595696">
<state width="1161" height="235" key="GridCell.Tab.0.left/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757569304" />
<state width="1161" height="235" key="GridCell.Tab.0.right" timestamp="1608757569304">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="386" key="GridCell.Tab.0.right/-1920.0.1920.1040/0.0.1920.1040@-1920.0.1920.1040" timestamp="1607708629475" />
<state width="1164" height="235" key="GridCell.Tab.0.right/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658595696" />
<state width="938" height="425" key="GridCell.Tab.1.bottom" timestamp="1608658103907">
<state width="1161" height="235" key="GridCell.Tab.0.right/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757569304" />
<state width="938" height="425" key="GridCell.Tab.1.bottom" timestamp="1608757429346">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="938" height="425" key="GridCell.Tab.1.bottom/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658103907" />
<state width="938" height="425" key="GridCell.Tab.1.center" timestamp="1608658103906">
<state width="938" height="425" key="GridCell.Tab.1.bottom/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757429346" />
<state width="938" height="425" key="GridCell.Tab.1.center" timestamp="1608757429346">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="938" height="425" key="GridCell.Tab.1.center/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658103906" />
<state width="938" height="425" key="GridCell.Tab.1.left" timestamp="1608658103906">
<state width="938" height="425" key="GridCell.Tab.1.center/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757429346" />
<state width="938" height="425" key="GridCell.Tab.1.left" timestamp="1608757429346">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="938" height="425" key="GridCell.Tab.1.left/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658103906" />
<state width="938" height="425" key="GridCell.Tab.1.right" timestamp="1608658103906">
<state width="938" height="425" key="GridCell.Tab.1.left/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757429346" />
<state width="938" height="425" key="GridCell.Tab.1.right" timestamp="1608757429346">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state width="938" height="425" key="GridCell.Tab.1.right/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608658103906" />
<state width="938" height="425" key="GridCell.Tab.1.right/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608757429346" />
<state x="782" y="240" key="RollbackChangesDialog" timestamp="1608474837005">
<screen x="0" y="0" width="1920" height="1040" />
</state>
@ -394,24 +403,13 @@
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="92" y="92" width="1736" height="856" key="com.intellij.history.integration.ui.views.SelectionHistoryDialog/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608488889272" />
<state x="593" y="141" width="585" height="801" key="find.popup" timestamp="1608483030515">
<state x="593" y="141" width="585" height="801" key="find.popup" timestamp="1608756195388">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="593" y="141" width="585" height="801" key="find.popup/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608483030515" />
<state x="593" y="141" width="585" height="801" key="find.popup/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608756195388" />
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup" timestamp="1608654442412">
<screen x="0" y="0" width="1920" height="1040" />
</state>
<state x="623" y="225" width="672" height="678" key="search.everywhere.popup/-1920.0.1920.1040/0.0.1920.1040@0.0.1920.1040" timestamp="1608654442412" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/day22/day22.go</url>
<line>115</line>
<option name="timeStamp" value="20" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>

@ -0,0 +1,107 @@
package main
import (
"fmt"
"os"
"strconv"
)
type Cup struct {
Number int
Next *Cup
}
func main() {
args := os.Args[1:]
input := args[0]
var cups = make(map[int]*Cup)
fmt.Println(input)
for _, val := range input{
number,_ := strconv.Atoi(string(val))
cups[number] = &Cup{Number: number}
}
for id, val := range input {
number,_ := strconv.Atoi(string(val))
nextNumber, _ := strconv.Atoi(string(input[(id+1)%len(input)]))
cups[number].Next = cups[nextNumber]
}
var inputNumbers []int
for _, val := range input{
number,_ := strconv.Atoi(string(val))
inputNumbers = append(inputNumbers,number)
}
min, max := minMax(inputNumbers)
iteration := 0
currentCup := cups[inputNumbers[0]]
for iteration < 100 {
fmt.Println(currentCup.Number)
threeCupStart := currentCup.Next
threeCupEnd := threeCupStart.Next.Next
currentCup.Next = threeCupEnd.Next
destination := currentCup.Number-1
for {
if destination < min {
destination = max
}
if destination != threeCupStart.Number &&
destination != threeCupStart.Next.Number &&
destination != threeCupEnd.Number {
break
}
destination--
}
destinationCup := cups[destination]
destinationNext := destinationCup.Next
destinationCup.Next = threeCupStart
threeCupEnd.Next = destinationNext
currentCup = currentCup.Next
iteration++
}
s := ""
cup := cups[1].Next
for cup != cups[1] {
s += fmt.Sprint(cup.Number)
cup = cup.Next
}
fmt.Println(s)
}
func runRound(cups *[]int){
}
func moveElement(cups *[]int, from int, to int) {
indexToRemove := from
indexWhereToInsert := to
val := (*cups) [indexToRemove]
(*cups) = append((*cups)[:indexToRemove], (*cups)[indexToRemove+1:]...)
fmt.Println("cups:", (*cups))
newSlice := make([]int, indexWhereToInsert+1)
copy(newSlice,(*cups)[:indexWhereToInsert])
newSlice[indexWhereToInsert]=val
fmt.Println("newSlice:", newSlice)
fmt.Println("cups:", (*cups))
(*cups) = append(newSlice, (*cups)[indexWhereToInsert:]...)
fmt.Println("cups:", (*cups))
}
func minMax(input[]int) (int, int){
var max int
var min int
for i, val := range input {
if i==0 || val < min {
min = val
}
if i==0 || val > max {
max = val
}
}
return min,max
}

@ -81,3 +81,12 @@ func Equal(a, b []int) bool {
}
return true
}
func Contains(elem int, array []int) bool{
for _, val := range array{
if val == elem{
return true
}
}
return false
}

Loading…
Cancel
Save