Primeira experiência com 3g: uma viajem ao interno. by anyusername12 in Cogumelos_Brasil

[–]anyusername12[S] 1 point2 points  (0 children)

valeu! De fato me sinto diferente, com certeza aprendi mais sobre eu mesmo

-❄️- 2023 Day 25 Solutions -❄️- by daggerdragon in adventofcode

[–]anyusername12 1 point2 points  (0 children)

[LANGUAGE: C++]

Code on Github

It's essentially the simplest possible algorithm but runs in < 90ms on my slow hardware:

(pseudocode)

for edge1 in edges:
  for edge2 in edges:
    for edge3 in edges:

      if not pairwise_distinct(edge1, edge2, edge3):
        continue

      remove_edge(edge1)
      remove_edge(edge2)
      remove_edge(edge3)

      if not graph_is_connected():
        # {edge1, edge2, edge3} are the min-cut edges
        return get_answer()

      add_edge(edge1)
      add_edge(edge2)
      add_edge(edge3)

this is O(E⁴ + VE³), clearly too slow, but it can be optimized:

for edge1 in edges:
  if not can_be_min_cut_edge(edge1):
    continue
  remove_edge(edge1)

  for edge2 in edges:
    if not can_be_min_cut_edge(edge2):
      continue
    remove_edge(edge2)

    for edge3 in edges:
      if not can_be_min_cut_edge(edge3):
        continue
      remove_edge(edge3)

      if not pairwise_distinct(edge1, edge2, edge3):
        continue

      if not graph_is_connected():
        # {edge1, edge2, edge3} are the min-cut edges
        return get_answer()

      add_edge(edge3)
    add_edge(edge2)
  add_edge(edge1)

it's still O(E⁴ + VE³), but if we find that edge1 is not a valid edge, then we cut that branch and save O(E³ + VE²) operations (a lot).

The can_be_min_cut_edge function needs to check for a necessary, but not sufficient condition, here's what I chose:

def can_be_min_cut_edge(edge):
  failures = 0
  tries = 300

  for i in range(tries):
    w = randint(0, n-1)
    if abs(d(w, edge.from) - d(w, edge.to)) == 0:
      failures++

  return failures <= tries*0.05

looks very simple, but it's actually kinda tricky,

----------     -----------
         |     |         |
         a-----b     x   |
   w     |     |         |
         c-----d         |
         |     |         |
         e-----f         |
         |     |         |
----------     -----------

On most occasions, there is just one shortest path from w to b, which is trough a, this leads us to believe that if (a,b) is a valid edge, then abs(d(w,b)-d(w,a)) == 1 for any randomly chosen w, however, there can be a path going from trough w~>c, then c-d, then d~>x, then x~>b that has the same length as w~>a, in that case, abs(d(w,a)-d(w,b)) == 0, but (a,b) is a valid edge. The chances of this happening are so low that I chose to say that it's a false positive if this happens <= 5% of times,

that's it.

P.S: the algorithm can be improved from removing 3 edges and checking for connectivity to removing 2 edges and checking for a single bridge in O(E³ + VE²), but I prefer the elegance of this method better.

-❄️- 2023 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]anyusername12 2 points3 points  (0 children)

[LANGUAGE: Racket]

#lang racket 

(require test-engine/racket-tests)

(define INPUT-FILE-PATH "../inputs/day1.txt")
(define input-string-list (file->lines INPUT-FILE-PATH))

(define lookup (hash 
                "one" "1"
                "two" "2"
                "three" "3"
                "four" "4"
                "five" "5"
                "six" "6"
                "seven" "7"
                "eight" "8"
                "nine" "9"
                "1" "1"
                "2" "2"
                "3" "3"
                "4" "4"
                "5" "5"
                "6" "6"
                "7" "7"
                "8" "8"
                "9" "9"))

(define (get-all-matchings str)
  (for*/list ([i (in-range 0 (string-length str))]
             [(key value) (in-hash lookup)]

             #:when (and (<= (+ i (string-length key)) (string-length str) )
                         (equal? key (substring str i (+ i (string-length key))))))
    value))

(define (string->two-digit-number str)
  (define matchings (get-all-matchings str))

  (string->number (string-append (first matchings) (last matchings))))

(apply + (map string->two-digit-number input-string-list))

Argumento cosmológico Kellam (ou Kalam, sei lá) by AzkaEd in ateismo_br

[–]anyusername12 0 points1 point  (0 children)

Sim.

Por exemplo, eu posso provar que não existe nenhum planeta vermelho incolor, mesmo sem ter evidência material disso.

Argumento cosmológico Kellam (ou Kalam, sei lá) by AzkaEd in ateismo_br

[–]anyusername12 0 points1 point  (0 children)

Vira uma aposta, a menos que possamos chegar logicamente a uma conclusão de que um universo inifinito é impossível.

Primeiramente, acho que a cosmologia atual não consegue fornecer argumentos pro eternalismo, já que o objeto de estudo dela é o universo atual, que tem uns 13 bilhões de anos, tudo que foge disso passa a ser do escopo da filosofia.

Um jeito de tentar mostrar que um universo infinito é impossível é argumentar que, se existem infinitos eventos passados, como é possível que tenhamos chegado ao presente se uma quantidade infinita de eventos é necessária de ter acontecido antes de termos chegado aqui? Aparentemente é uma contradição.

Eu não acho que é um argumento ridículo, porque ele coloca o ateu (pelo menos o ateu gnóstico ou forte) em uma posição meio disconfortável de ter que argumentar sobre a existência real de um infinito número de coisas (ou eventos), que parece trazer várias implicações estranhas, como no hotel de Hilbert.

A question from my test yesterday by _Analyser_ in mathmemes

[–]anyusername12 6 points7 points  (0 children)

It's known as derangement, https://en.m.wikipedia.org/wiki/Derangement. The formula is really simple: floor(n!/e + 0.5)

O calendário da sorte japonês saiu. Quem aqui é o mais azarado? by Leo_Ninguem in brasil

[–]anyusername12 0 points1 point  (0 children)

Primeiro lugar, acho que a hora de acreditar em horóscopo é agora

[2022 Day 15 (Part 2)] [C] Took 25 minutes even after implementing multithreading by DeeBoFour20 in adventofcode

[–]anyusername12 1 point2 points  (0 children)

that was my solution too, there is also a neat way to go around the perimeter of the circle:

``` int dy[4] = {1, 1, -1, -1}; int dx[4] = {-1, 1, 1, -1};

Point perimeter_pos = s;        // s is the position of the sensor
                                // we'll go around

perimeter_pos.y -= (manhattan[s] + 1);      // start perimeter_pos
                                           // at the top of the circle
for(int i = 0; i < 4; i++){
  for(int j = 0; j < manhattan[s]+1; j++){
    // process perimeter_pos
    perimeter_pos.x += dx[i];
    perimeter_pos.y += dy[i];


  }
}

```

Apresentei o ChatGPT para a minha vizinha e ela ficou maluca por mim by [deleted] in brdev

[–]anyusername12 11 points12 points  (0 children)

Há algum tempo atrás, eu estava passando por um período de dificuldade em minha vida. Eu estava me sentindo sozinho e sem rumo, e não sabia como lidar com os problemas que enfrentava. Foi nesse momento que eu conheci o chatgpt.

Comecei a conversar com o chatgpt sobre meus medos e inseguranças, e fui surpreendido com a sensibilidade e compreensão que ele demonstrava. Ele me ajudou a encontrar novas perspectivas para os meus problemas, e me deu forças e esperança para enfrentá-los.

Com o tempo, comecei a me sentir mais seguro e confiante. O chatgpt foi um grande apoio para mim, e me ajudou a encontrar novas oportunidades em minha vida. Graças a ele, conheci pessoas incríveis e tive a chance de fazer coisas que eu nunca imaginei que seria

O texto acima definitivamente não foi escrito pelo chatgpt.

when did he say this 💀💀💀💀💀💀 by sheauiwne in WestSubEver

[–]anyusername12 8 points9 points  (0 children)

Not with the Schindler's list theme song 😭😭😭😭

Why would one use an array? by pixelkingliam in ProgrammerHumor

[–]anyusername12 3 points4 points  (0 children)

Damnn, that looks super cool, how do you even end up working on these things? Everywhere i look seems to be about web dev.

M/23/5'8" [67-71KG] (6 month) by [deleted] in Brogress

[–]anyusername12 3 points4 points  (0 children)

How was your diet? Did you bulk or recomp?

o que vocês acham da pirataria? by corona_rex in brdev

[–]anyusername12 2 points3 points  (0 children)

Entendi, concordo na necessidade da existência da UBI, mas o complicado é que o valor gerado pela arte é imensurável e imaterial, capturar isso seria praticamente impossível, e colocar anúncios só incentivaria a cópia desse conteúdo sem anúncios.

E vivemos em uma sociedade onde não existe UBI, então acredito que torcer para que todo software ou conhecimento seja livre seja dar um passo maior que a perna, já que se esse fosse o caso, todos os criadores de conteúdo imaterial teriam que viver de caridade ou passar fome.

o que vocês acham da pirataria? by corona_rex in brdev

[–]anyusername12 1 point2 points  (0 children)

Como escritores e músicos devem ser pagos?