Golfcoder FAQ LOGIN
Error

Advent of Code Leaderboard 2023 / Day 1

View puzzle on adventofcode.com

Submit solution



Rules
  • You're welcome to participate alone or in a team.
  • You may submit multiple solutions and explore different programming languages.
  • Stick to the standard library of your language, no further dependencies/libraries, except the ones which OneCompiler provides (e.g. NumPy for Python).
  • Ensure your code aligns to the template (Python, Rust, Go, Kotlin, JavaScript, C#, TypeScript, C++, Java, C, Swift, Scala, Ruby), reading the puzzle input from stdin (terminated with end-of-file), and printing the solution to stdout.
  • Please refrain from making network requests, reading data from files, or storing data in variable/function/class names for reflection.

Leaderboard

Name Language Tokens Sum Tokens Part 1 Tokens Part 2 Last change
1 Profile imageSharparam Ruby 148 36 112 10 months ago
2 Profile imageVisible-Bag4062 Python 208 45 163 10 months ago
3 Profile imageMustafa Furkan Kaptan Python 209 43 166 10 months ago
4 Profile imageValentin Slawicek Kotlin 212 52 160 10 months ago
5 Profile imageLiquidFun Python 217 56 161 10 months ago
6 GXgaetjen Kotlin 232 78 154 11 months ago
7 Profile imageanonymous Kotlin 261 60 201 11 months ago
8 Profile imageVisible-Bag4062 C++ 290 74 216 10 months ago
9 Profile imageMathias Parger Python 348 129 219 10 months ago
10 Profile imageabnew123 Java 527 189 338 10 months ago
11 Profile imageKevin Brasier Python 10043 43 - 10 months ago
12 Profile imageNolan Locke Kotlin 10048 48 - 10 months ago
13 Profile image0bArcane Python 10067 67 - 10 months ago
14 Profile imageVisible-Bag4062 Java 10115 115 - 10 months ago

338 tokens in Java for part 2 by abnew123

Download solution

importjava.util.*;

publicclassMain{

publicstaticvoidmain(String[]args){
Scannerin=newScanner(System.in);
intanswer=0;
List<String>lines=newArrayList<>();
while(in.hasNext()){
lines.add(in.nextLine());
}
for(Stringline:lines){
answer+=10*helper(line,true);
answer+=helper(line,false);
}
System.out.println(answer);
}

privatestaticinthelper(Stringline,booleanforwards){
String[]digits=newString[]{"one","two","three","four","five","six","seven","eight","nine"};

char[]chars=line.toCharArray();
for(inti=0;i<chars.length;i++){
intindex=forwards?i:(chars.length-i-1);
for(intj=0;j<digits.length;j++){
if(index+digits[j].length()>line.length()){
continue;
}
Stringsubstring=line.substring(index,index+digits[j].length());
if(substring.contains(digits[j])){
returnj+1;
}
}
charch=chars[index];
if(Character.isDigit(ch)){
returnCharacter.digit(ch,10);
}
}
return-1;
}
}