Skip to content

Instantly share code, notes, and snippets.

@pathikrit
pathikrit / $lang.dl.md
Last active December 19, 2015 13:40
$lang: a meta^2 programming language

$lang (pronounced dollar-lang) is a beautiful minimalistic readable programming language inspired by Good (or Crazy) Ideas™ of other languages.

Complete list of keywords in $lang:

  1. logical values: true, false
  • primitive data types: text, number, logical
  • control-flow statements: if, then, else, while
  • when
  • exists
  • is

Keybase proof

I hereby claim:

  • I am pathikrit on github.
  • I am pathikrit (https://keybase.io/pathikrit) on keybase.
  • I have a public key whose fingerprint is 32D0 C3DF 1F9B ABA2 E61A C553 8F5B 9198 DEFF 220E

To claim this, I am signing this object:

@pathikrit
pathikrit / Library.java
Last active May 6, 2022 23:51
Java Algorithms
import java.awt.*;
import java.math.*;
import java.util.regex.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Integer.parseInt;
import static java.util.AbstractMap.*;
import static java.lang.System.*;
import static java.lang.Math.*;
@pathikrit
pathikrit / maps_wishlist.md
Last active August 29, 2015 14:15
What I want from Google Maps
  • When I ask for driving directions to somewhere it should suggest "Shall I direct you to the nearest parking spot from your destination"?

  • When I drive somewhere, I should have advanced options to say that I need to fill gas within the next x miles on the way to my destination.

  • They should have OBD plugins like automatic.com to do this automatically for most cars.

  • Sometimes I arrive at my destination but I miss it and direction exits saying that I arrived but I am lost now since I drove passed the address. It should detect that if I drove past my destination and start auto-rerouting.

  • If I entered a business or restaurant address, it should auto warn if it is closed or closes soon by the time I reach it.

@pathikrit
pathikrit / weeker.scala
Last active August 29, 2015 14:17
Natural weekday chooser
val weekdays = IndexedSeq("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
def solve(idx: Int*) = (idx foldLeft Seq.empty[(Int, Int)]) {
case (ts :+ ((start, end)), x) if x == end + 1 => ts :+ (start, x)
case (t, x) => t :+ (x, x)
} map {
case (start, end) if start == end => weekdays(start)
case (start, end) => s"${weekdays(start)}-${weekdays(end)}"
}
@pathikrit
pathikrit / SudokuSolver.scala
Last active April 12, 2024 15:00
Sudoku Solver in Scala
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)))
@pathikrit
pathikrit / Node.scala
Last active September 17, 2021 02:02
Reverse a LinkedList in Scala
case class Node(value: Int, next: Option[Node])
def reverse(node: Node, prev: Option[Node] = None): Node = {
val reversed = node.copy(next = prev)
node.next map {reverse(_, Some(reversed))} getOrElse reversed
}
/****************************************************************/
val one = Node(1,Some(Node(2,Some(Node(3,None)))))
println(s"$one\n${reverse(one)}")
@pathikrit
pathikrit / git-standup
Created June 22, 2015 22:32
git daily standup
log --all --no-merges --graph --date=relative --committer=$(git config --get user.email) --pretty=format:'%C(cyan) %ad %C(yellow)%h %Creset %s %Cgreen%d' --since="$(if [[ "Mon" == "$(date +%a)" ]]; then echo "last friday"; else echo "yesterday"; fi)"
@pathikrit
pathikrit / IsPalindrome.scala
Last active April 15, 2018 11:19
Scala isPalindrome
def isPalindrome[A](x: Vector[A]): Boolean = x match {
case start +: middle :+ end => start == end && isPalindrome(middle)
case _ => true
}
@pathikrit
pathikrit / debounce.scala
Last active August 29, 2015 14:26
Debounce in Scala
import scala.compat.Platform.{currentTime => now}
import scala.concurrent.duration.FiniteDuration
import java.util.concurrent.atomic.AtomicBoolean
/**
* Debounce a function i.e. it can only be invoked iff it is not already running
* and atleast wait duration has passed since it last stopped running
* Usage:
* def test(i: Int) = println(i)