Rename folders
This commit is contained in:
1 parent
fa11582a25
commit
89ca6f60df
31 files changed
No files matched your search
Executable
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
||||
9883356733752069656661181949779760668336947879672334631498492012279248564815678743918257448799319394268097164282313431712170232427711341278448916123555398963258649192254954428653124048627490363654445098463746705264577434331872739013223257852686325396697166785638826129755245235190709399598738659344508060635161185663324868573885182433469142265019784585737647295954667470632356552310324986978582442373946683324324964975714411442032304368571210978040452375554437723241626980594046753116656563509033582217499974991050134612298676291437298830232670458958219114171954451027352367739620478811495628756386541454713737366356111396226531647796778156447213557264103125841191713843757879301825505533453412476928891777791351737361271824619255577975586534476383753744919060501896538114501577965998706141772971209530162029611212394330506366554760555985142486615059863665687038214179699497301518671235225039492252152831716676249276459715873878384073464072107130115017397861339839974612262240665898961586771878531734607833716543388957148829186678512928177033946090629333529733506188186491613897795746195676809483647332656452184268453163657020142050372765496336683247811884935692201117801592269834244542309222751840604155598822227798309394498363764883786862121857736540788261474227727573412175921075911613378269583723493564169193703048107587824874507062172662316199464348924079568980207043197747731699644026757735542726813181286644228218672046427990847221832377789165397153394375317488763889333787123219407819215168529579908731886226239268502975706487441416997356682064305998636328307113664355564840868361978472573841164836852638262380254558998276331311259321936449351314839691926943221768453235649270701181576626894059389974499339646710732716693944726670597014216317455536154850912570211723421084726837163066678451494298835856395177169799446984621942806126353719503476824664397994141971252455842399737184857680309555968583267395151918467779142081885016329640358734318651614815274714217361819541411245482744942727223724341036719762295093691593943642695981904245811763931437506664169019253386477962205615978146656122809239164153984041695920788386152526156651567161529613461075949987112434688430577931309566169938658238131388748673502393192966732727669176892230919335512042768019752490429924614995548790485236919892572581165918181889945981625991679388139740392886185070704069391458729396629064967719294157985428512749485068703151629444515826641465363794311668907458547074287419227448154297192011603664309292416178131683644752872050258037223667895571881735267731619682303693113966616892347897586716546532647515254969203958682032224086613534856095312173392176821627487358438155926690388994175855839248259592583158115924176581194228135144321212144612404814173818165971197080324010425577891463533490228555831854329959177368166973665428489143193498369966397039974022459115212827302769786335383711753289878858888347477763603116959748371911358872941047169133943230873983851190696084753533987563447044225998578548836074893487135550728570221787647980451277456271891871624638884052965468227916727087869861795555886885968159474793392795528716972474306285699940177438694265557321776690614226501349518145887036414862424271735173151666215396509958697963466163651799397415229168111121912551489570394885715344189110112361282433604124163632175357526337118452132159963182341630539680977021753880579239457089551634994026538289663528325339236328152566952086836038905324227172132834124329594591191923629950743453145992306064672222762235807963593817695660515172482489453688919570595591433751273030183683714995478755667593325936204584941326969197226471128682728999845978288190492744518431783416339478743290182163593658604157792595274347414386866048553430198923828336873693295851831465287047112486725349632081905333758331119996211127566234502295418282558161312537781738584112391614856516295872955898538881702494502275922438131954803275957973305149586967106220974672724018361192186118906128163176626674873244874518431436966840218178724296142054642332557418129132414956123214407158419679596279181341745495813039235143194037441769115217676181107224378686288044659623815988405093577141274491494270284546184583747873214053423324458846314462282862392472318084336060531738151829485076295782113040501365477364524166505660316865952326609661798143592651341054228799358817759077687559318451287829184584385093763848924720114437615427904852166522586453549189178513691669963062202377767713866084969138581221644642388399515572532717438159263432583293559754549669296578758984347086627546465729605425905342101995416573335592158918466882541643249199901697467353472250175852479938791414295165433144796691478486471251301526439296744457536479351413254751913262292810401851177040286959929252685979462173928453424181742375153072621370196987618980939081678477621248512397161496561374797886371885134691398185204413863348846133589520134176681445787399786095818933664384183427582728461416372811364896875186814192397537182244209297699374782329548370982283244568347180377Line truncated
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// file, _ := os.Open("test")
|
||||
file, _ := os.Open("input")
|
||||
defer file.Close()
|
||||
scanner := bufio.NewScanner(file)
|
||||
diskMap := []string{}
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
diskMap = append(diskMap, strings.Split(line, "")...)
|
||||
}
|
||||
fileID := 0
|
||||
blockSize := 0
|
||||
blockSizes := []int{}
|
||||
freeSpace := 0
|
||||
freeSpaces := []int{}
|
||||
blocks := []string{}
|
||||
for i := range diskMap {
|
||||
if i % 2 == 0 {
|
||||
blockSize, _ = strconv.Atoi(diskMap[i])
|
||||
blockSizes = append(blockSizes, blockSize)
|
||||
for j:=0;j<blockSize;j++ {
|
||||
blocks = append(blocks, strconv.Itoa(fileID))
|
||||
}
|
||||
fileID++
|
||||
} else {
|
||||
freeSpace, _ = strconv.Atoi(diskMap[i])
|
||||
freeSpaces = append(freeSpaces, freeSpace)
|
||||
for j:=0;j<freeSpace;j++ {
|
||||
blocks = append(blocks, ".")
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(freeSpaces) < len(blockSizes) {
|
||||
freeSpaces = append(freeSpaces, 0)
|
||||
}
|
||||
//TRY3
|
||||
for id:=fileID-1;id>=0;id-- {
|
||||
idPositions := findIDpositions(blocks,id)
|
||||
for moveTo:=0;moveTo<=id;moveTo++ {
|
||||
if moveTo==id {
|
||||
continue
|
||||
}
|
||||
if len(idPositions) <= freeSpaces[moveTo] {
|
||||
//find the spaces after the moveTo
|
||||
idSpacePositions := findSpacesAfterID(blocks,moveTo,freeSpaces[moveTo])
|
||||
//assign id to spaces for each len(idPositions)
|
||||
for i:=0;i<blockSizes[id];i++ {
|
||||
blocks[idSpacePositions[i]]=strconv.Itoa(id)
|
||||
blocks[idPositions[i]] = "."
|
||||
freeSpaces[moveTo]--
|
||||
}
|
||||
break
|
||||
//assign new id positions to idPositions
|
||||
//assign space to each idPositions
|
||||
}
|
||||
}
|
||||
fmt.Println(blocks)
|
||||
}
|
||||
checksum := 0
|
||||
for i := range blocks {
|
||||
blockID, _ := strconv.Atoi(blocks[i])
|
||||
checksum = checksum + i * blockID
|
||||
}
|
||||
fmt.Println(checksum)
|
||||
}
|
||||
|
||||
|
||||
func findIDpositions(blocks []string, id int) []int {
|
||||
positions := []int{}
|
||||
for i := range blocks {
|
||||
if blocks[i] == strconv.Itoa(id) {
|
||||
positions = append(positions, i)
|
||||
}
|
||||
}
|
||||
return positions
|
||||
}
|
||||
|
||||
func findSpacesAfterID(blocks []string, id, idSpaces int) []int {
|
||||
spaces := []int{}
|
||||
idPositions := findIDpositions(blocks,id)
|
||||
for i:=idPositions[len(idPositions)-1];i<len(blocks);i++ {
|
||||
if blocks[i] == "." {
|
||||
spaces = append(spaces, i)
|
||||
}
|
||||
if len(spaces) == idSpaces {
|
||||
break
|
||||
}
|
||||
}
|
||||
return spaces
|
||||
}
|
||||
Reference in new issue
Block a user