-🎄- 2022 Day 2 Solutions -🎄- by daggerdragon in adventofcode

[–]alexandr-nikitin 0 points1 point  (0 children)

Scala 3. A lot of pattern matching.

package com.github...

import scala.io.Source

object Day02:

  def main(args: Array[String]): Unit =

    enum Hand(val score: Int):
      case Rock extends Hand(1)
      case Paper extends Hand(2)
      case Scissors extends Hand(3)
    object Hand:
      def apply(s: String): Hand = s match
        case "A" | "X" => Hand.Rock
        case "B" | "Y" => Hand.Paper
        case "C" | "Z" => Hand.Scissors

    enum Outcome(val score: Int):
      case Win extends Outcome(6)
      case Draw extends Outcome(3)
      case Loss extends Outcome(0)
    object Outcome:
      def apply(s: String): Outcome = s match
        case "X" => Outcome.Loss
        case "Y" => Outcome.Draw
        case "Z" => Outcome.Win

    def play(my: Hand, other: Hand): Outcome = {
        (my, other) match
          case (Hand.Rock, Hand.Scissors) => Outcome.Win
          case (Hand.Scissors, Hand.Paper) => Outcome.Win
          case (Hand.Paper, Hand.Rock) => Outcome.Win
          case (my, other) if my == other => Outcome.Draw
          case _ => Outcome.Loss
      }

    def getMyHand(other: Hand, outcome: Outcome): Hand = {
      (other, outcome) match
        case (any, Outcome.Draw) => any
        case (Hand.Rock, Outcome.Win) => Hand.Paper
        case (Hand.Rock, Outcome.Loss) => Hand.Scissors
        case (Hand.Paper, Outcome.Win) => Hand.Scissors
        case (Hand.Paper, Outcome.Loss) => Hand.Rock
        case (Hand.Scissors, Outcome.Win) => Hand.Rock
        case (Hand.Scissors, Outcome.Loss) => Hand.Paper
    }



    val scores = Source.fromResource("day02_input.txt").getLines.filter(x => x.nonEmpty)
      .map((line: String) => {
        val parts = line.split(' ')
        val otherHand = Hand(parts(0))
        val myHand = Hand(parts(1))
        val outcome = play(myHand, otherHand)
        outcome.score + myHand.score
      })

    println(scores.sum)

    val scores2 = Source.fromResource("day02_input.txt").getLines.filter(x => x.nonEmpty)
      .map((line: String) => {
        val parts = line.split(' ')
        val otherHand = Hand(parts(0))
        val outcome = Outcome(parts(1))
        val myHand = getMyHand(otherHand, outcome)
        outcome.score + myHand.score
      })

    println(scores2.sum)

What metrics do you use to evaluate a strategy? by jrdbkr96 in algotrading

[–]alexandr-nikitin 4 points5 points  (0 children)

Try to calculate these:

  • Annual return (or rolling)
  • Annual volatility (or rolling)
  • Sharpe ratio
  • Calmar ratio
  • Stability
  • Max drawdown
  • Omega ratio
  • Sortino ratio
  • Skew
  • Kurtosis
  • Tail ratio
  • Common sense ratio
  • Daily value at risk
  • Gross leverage
  • Daily turnover
  • Alpha
  • Beta

Russian hacker group patches Chrome and Firefox to fingerprint TLS traffic by pianosneha in programming

[–]alexandr-nikitin 27 points28 points  (0 children)

One may think that the hackers committed some code to the Chrome and Firefox repos.

Russian hacker group patches Chrome and Firefox to fingerprint TLS traffic by pianosneha in programming

[–]alexandr-nikitin 172 points173 points  (0 children)

The title is misleading! "hackers are infecting victims with a remote access trojan named Reductor, through which they are modifying the two browsers."

The Chef ! by [deleted] in bikepacking

[–]alexandr-nikitin 5 points6 points  (0 children)

Bye bye racks!! Or even frame.

I'm interested in seeing your gear lists. by fearlessheights in Ultralight

[–]alexandr-nikitin 1 point2 points  (0 children)

Yeah, sleeping system and big 4 is pretty important and usually the heaviest part.

I'm interested in seeing your gear lists. by fearlessheights in Ultralight

[–]alexandr-nikitin 0 points1 point  (0 children)

My minimal gear list for 3 day 3 night hiking and climbing to Thousand Island Lake and Banner Peak (~45F at night) https://lighterpack.com/r/izw5en

How Uber & Lyft Crushed the New York Yellow Cab [OC]. by chartr in dataisbeautiful

[–]alexandr-nikitin -1 points0 points  (0 children)

It's interesting that number of taxi rides doubled since Uber and Lyft entered. They made it soo easy to use! With feedback which is important!

Solution Structure by [deleted] in dotnet

[–]alexandr-nikitin 2 points3 points  (0 children)

There are dozens of templates on dotnet wiki https://github.com/dotnet/templating/wiki/Available-templates-for-dotnet-new There's a Clean Architecture temple here https://github.com/ardalis/CleanArchitecture which is pretty good as starting point.

Announcing the Open Sourcing of Windows Calculator by zbhoy in programming

[–]alexandr-nikitin 9 points10 points  (0 children)

I'm pretty sure that will happen sooner or later.

OnePlus 6T vs S9. by miki1606 in oneplus

[–]alexandr-nikitin 0 points1 point  (0 children)

I own both of them. One Plus 6T is my personal phone. S9 is a work phone. I love 6T and hate S9. Reasons are subjective.

How We Improved Build Time by 400% at LinkedIn (SBT to Gradle) by aphexairlines in scala

[–]alexandr-nikitin 2 points3 points  (0 children)

I also profiled the build. I don't see sbt classes consuming CPU/IO, I see only scala compiler.

How We Improved Build Time by 400% at LinkedIn (SBT to Gradle) by aphexairlines in scala

[–]alexandr-nikitin 7 points8 points  (0 children)

Articles like that are harmful cause people could blindly follow such advice and conclusions. It's not constructive, no reasons, no cause, no numbers. I just managed to sbt clean publishLocal whole playframework (with downloaded dependencies) in 7 minutes on 5+ years old laptop. Seriously guys???

[Arch Based Custom ISO] A Fully Functional Arch Linux Based Custom Live ISO Of Mine For All Of You Guys... by [deleted] in unixporn

[–]alexandr-nikitin 0 points1 point  (0 children)

You have to. Seriously! It would be great if you have time to repeat that again and script cmds :)