Skip to content

Commit ed45475

Browse files
committed
chore: migrate to scala 3, the higher the number the better you know
1 parent 2d60580 commit ed45475

7 files changed

Lines changed: 200 additions & 158 deletions

File tree

2023/.gitignore

Lines changed: 100 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,104 @@
1-
#
2-
# Are you tempted to edit this file?
3-
#
4-
# First consider if the changes make sense for all,
5-
# or if they are specific to your workflow/system.
6-
# If it is the latter, you can augment this list with
7-
# entries in .git/info/excludes
8-
#
9-
# see also test/files/.gitignore
10-
#
11-
12-
#
13-
# JARs aren't checked in, they are fetched by sbt
14-
#
15-
/lib/*.jar
16-
/test/files/codelib/*.jar
17-
/test/files/lib/*.jar
18-
/test/files/speclib/instrumented.jar
19-
/tools/*.jar
20-
21-
# Developer specific properties
22-
/build.properties
23-
/buildcharacter.properties
24-
25-
# might get generated when testing Jenkins scripts locally
26-
/jenkins.properties
27-
28-
# target directory for build
29-
/build/
30-
31-
# other
32-
/out/
33-
/bin/
34-
/sandbox/
35-
36-
# intellij
37-
/src/intellij*/*.iml
38-
/src/intellij*/*.ipr
39-
/src/intellij*/*.iws
40-
**/.cache
41-
/.idea
42-
/.settings
43-
44-
# vscode
45-
/.vscode
46-
47-
# Standard symbolic link to build/quick/bin
48-
/qbin
49-
50-
# sbt's target directories
51-
/target/
52-
/project/**/target/
53-
/test/macro-annot/target/
54-
/test/files/target/
55-
/test/target/
56-
/build-sbt/
1+
*.DS_Store
2+
*.class
3+
*.tasty
4+
*.log
5+
*.swp
6+
*~
7+
tags
8+
9+
# sbt specific
10+
dist/*
11+
target/
12+
lib_managed/
13+
src_managed/
14+
project/boot/
15+
project/plugins/project/
16+
project/local-plugins.sbt
17+
.history
18+
.ensime
19+
.ensime_cache/
20+
.sbt-scripted/
5721
local.sbt
58-
jitwatch.out
5922

60-
# Used by the restarr/restarrFull commands as target directories
61-
/build-restarr/
62-
/target-restarr/
23+
# npm
24+
node_modules
25+
26+
# VS Code
27+
.vscode/
28+
# Metals
29+
.bloop/
30+
.metals/
31+
metals.sbt
32+
33+
# idea
34+
.idea
35+
.idea_modules
36+
/.worksheet/
37+
38+
# scala-cli
39+
.scala-build
40+
sbt-launch.jar
41+
42+
# Partest
43+
dotty.jar
44+
dotty-lib.jar
45+
tests/partest-generated/
46+
tests/locks/
47+
/test-classes/
48+
49+
# Benchmarks
50+
bench/tests-generated
51+
52+
# Ignore output files but keep the directory
53+
out/
54+
build/
55+
!out/.keep
56+
testlogs/
57+
58+
# Ignore build-file
59+
.packages
60+
/.cache-main
61+
/.cache-tests
62+
63+
# Put local stuff here
64+
local/
65+
compiler/test/debug/Gen.jar
66+
67+
before-pickling.txt
68+
after-pickling.txt
69+
bench/compile.txt
70+
71+
community-build/scala3-bootstrapped.version
72+
community-build/sbt-injected-plugins
73+
community-build/sbt-dotty-sbt
74+
community-build/sbt-scalajs-sbt
75+
community-build/dotty-community-build-deps
76+
77+
# Vulpix output files
78+
*.check.out
79+
!/dist/bin/
80+
81+
# semanticdb test output files
82+
*.expect.scala.out
83+
*.expect.out
84+
85+
# Bloop
86+
.bsp
87+
88+
# Coursier
89+
cs
90+
91+
# Coursier test product
92+
compiler/test-coursier/run/*.jar
93+
94+
# docs related
95+
contributors.js
96+
content-contributors.css
97+
docs/_spec/_site/
98+
docs/_spec/.jekyll-metadata
6399

64-
# metals
65-
.metals
66-
.bloop
67-
project/**/metals.sbt
100+
# scaladoc related
101+
scaladoc/output/
68102

69-
.bsp
103+
#coverage
104+
coverage/

2023/.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "3.7.15"
2-
runner.dialect = scala213
2+
runner.dialect = scala3

2023/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Run the days with
2+
3+
```bash
4+
scala-cli run src/main/scala/day01.scala --main-class com.markkovari.adventofcode.part1
5+
```
6+
7+
- Soon will add a justfile with params to run the days, but realistocly not going to happen

2023/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The simplest possible sbt build file is just one line:
22

3-
ThisBuild / scalaVersion := "2.13.12"
3+
ThisBuild / scalaVersion := "3.3.1"
44
// That is, to create a valid sbt build, all you've got to do is define the
55
// version of Scala you'd like your project to use.
66

2023/src/main/scala/Main.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.markkovari.adventofcode
1+
// package com.markkovari.adventofcode
22

3-
import scala.io.Source
4-
import scala.collection.IndexedSeqView
5-
import scala.collection.mutable.HashMap
3+
// import scala.io.Source
4+
// import scala.collection.IndexedSeqView
5+
// import scala.collection.mutable.HashMap
66

7-
object Main extends App {
8-
val day = new Day01
9-
println(day.firstResult)
10-
println(day.secondResult)
11-
}
7+
// object Main extends App {
8+
// val day = new Day01
9+
// println(day.firstResult)
10+
// println(day.secondResult)
11+
// }

2023/src/main/scala/day01.scala

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.markkovari.adventofcode
2+
3+
import scala.collection.immutable.HashMap
4+
import scala.io.Source
5+
6+
@main def part1: Unit = println(s"The solution is ${firstResult}")
7+
@main def part2: Unit = println(s"The solution is ${secondResult}")
8+
9+
val numbersAsStringsAndValues =
10+
HashMap[String, Int](
11+
"one" -> 1,
12+
"two" -> 2,
13+
"three" -> 3,
14+
"four" -> 4,
15+
"five" -> 5,
16+
"six" -> 6,
17+
"seven" -> 7,
18+
"eight" -> 8,
19+
"nine" -> 9
20+
)
21+
22+
private def stringStartsStringifiedDigit(text: String): Option[Int] = {
23+
numbersAsStringsAndValues
24+
.find { case (key, _) => text.startsWith(key) }
25+
.map { case (_, value) => value }
26+
}
27+
28+
private val exampleFilename = "example_1"
29+
private val exampleFilename2 = "example_2"
30+
private val valuesFilename = "values"
31+
32+
private val lines =
33+
Source.fromFile(s"./src/main/resources/1/${valuesFilename}").getLines
34+
private val linesForSecond =
35+
Source.fromFile(s"./src/main/resources/1/${valuesFilename}").getLines
36+
37+
val firstResult =
38+
lines
39+
.map(line => getFirstAndLastMultipliedTen(getDigits(line)))
40+
.sum
41+
42+
val secondResult =
43+
linesForSecond
44+
.map(line => getFirstAndLastMultipliedTen(getMixedUpDigits(line)))
45+
.sum
46+
47+
private def getFirstAndLastMultipliedTen(list: List[Int]): Int = {
48+
list match {
49+
case a :: Nil => a * 10 + a
50+
case a :: b :: Nil => a * 10 + b
51+
case a :: b :: tail => a * 10 + tail.last
52+
case _ => 0
53+
}
54+
}
55+
56+
def getMixedUpDigits(of: String): List[Int] = of match {
57+
case "" => List()
58+
case other => {
59+
stringStartsStringifiedDigit(other) match {
60+
case Some(value) => value :: getMixedUpDigits(other.splitAt(1)._2)
61+
case None => {
62+
val (head, tail) = other.splitAt(1)
63+
head.toIntOption match {
64+
case None => getMixedUpDigits(tail)
65+
case Some(_) => head.toInt :: getMixedUpDigits(tail)
66+
}
67+
}
68+
}
69+
}
70+
71+
}
72+
73+
def getDigits(of: String): List[Int] = of match {
74+
case "" => List()
75+
case a => {
76+
val (head, tail) = a.splitAt(1)
77+
head.toIntOption match {
78+
case None => getDigits(tail)
79+
case Some(_) => head.toInt :: getDigits(tail)
80+
}
81+
}
82+
}

2023/src/main/scala/days/01/Day01.scala

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)