(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| killall Xcode | |
| xcrun -k | |
| xcodebuild -alltargets clean | |
| rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" | |
| rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache" | |
| rm -rf /Applications/Xcode.app | |
| rm -rf ~/Library/Caches/com.apple.dt.Xcode | |
| rm -rf ~/Library/Developer | |
| rm -rf ~/Library/MobileDevice | |
| rm -rf ~/Library/Preferences/com.apple.dt.Xcode.plist |
| package com.example | |
| import java.text.NumberFormat | |
| import java.time.Instant | |
| import cats.effect.{IO, Sync, Timer} | |
| import fs2.{Chunk, Stream} | |
| import monix.eval.Task | |
| import monix.execution.Scheduler | |
| import monix.reactive.Observable |
| import cats.Monad | |
| import cats.effect.concurrent.{Ref, Semaphore} | |
| import cats.effect.{Concurrent, Resource} | |
| import cats.implicits._ | |
| import fs2.{Pipe, Stream} | |
| import fs2.concurrent.{NoneTerminatedQueue, Queue} | |
| /** Represents the ability to enqueue keyed items into a stream of queues that emits homogenous keyed streams. | |
| * |
| val n = 9 | |
| val s = Math.sqrt(n).toInt | |
| type Board = IndexedSeq[IndexedSeq[Int]] | |
| def solve(board: Board, cell: Int = 0): Option[Board] = (cell%n, cell/n) match { | |
| case (r, `n`) => Some(board) | |
| case (r, c) if board(r)(c) > 0 => solve(board, cell + 1) | |
| case (r, c) => | |
| def guess(x: Int) = solve(board.updated(r, board(r).updated(c, x)), cell + 1) | |
| val used = board.indices.flatMap(i => Seq(board(r)(i), board(i)(c), board(s*(r/s) + i/s)(s*(c/s) + i%s))) |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| /* | |
| * Code contributed to Rosetta Code: <http://rosettacode.org/wiki/Tic-tac-toe#Scala> | |
| * | |
| * Creative commons license "CC0 1.0 Universal (CC0 1.0)" | |
| * <http://creativecommons.org/publicdomain/zero/1.0/> | |
| * To the extent possible under law, Rubén Béjar <http://www.rubenbejar.com> | |
| * has waived all copyright and related or neighboring rights to this | |
| * source file. This work is published from: Spain. | |
| * | |
| * Computers vs. human. Human starts. |