Skip to content

Instantly share code, notes, and snippets.

{-
Based on
- https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/guide-to-ghc-extensions/list-and-comprehension-extensions
-}
{-# LANGUAGE ParallelListComp, TransformListComp #-}
f :: (Num a, Ord a) => [a] -> [a] -> [(a, a)]
f xs ys = [(x, y) | x <- xs,
then (filter (\z -> z > 10))
{-
The file is based on:
https://ocharles.org.uk/blog/guest-posts/2014-12-07-list-comprehensions.html
-}
{-# LANGUAGE TransformListComp, RecordWildCards #-}
import GHC.Exts (groupWith, the)
import Data.Ord (comparing)
import Data.List (sortBy)
from random import randint as ri, shuffle
width, height = 5, 5
ship_count = 5
try_count = 5
class NotOnTable(Exception):
pass
def guess(row, col):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<html>
<head>
<title>Showing the relationship graph for question {{n}}</title>
<style>
#graph-container {
top: 0;
bottom: 0;
left: 0;
right: 0;
""" The problem description:
Given a Data Structure having first n integers and next n chars.
A = i1 i2 i3 ... iN c1 c2 c3 ... cN.Write an in-place algorithm
to rearrange the elements of the array ass A = i1 c1 i2 c2 ... in cn
"""
def swap(arr, ind1, ind2):
""" Solver logic for https://boardgamegeek.com/boardgame/1198/set """
from random import shuffle
from itertools import product, combinations
revd = [
["one", "two", "three"],
["red", "green", "blue"],
["empty", "half", "full"],
["ellipse", "rectangle", "wavy"]]
@jakab922
jakab922 / datetime_format.bsh
Created August 30, 2016 07:59
Formatting the current time in beanshell
import java.util.Date;
import java.text.SimpleDateFormat;
SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMddHHmmss" );
return formatter.format( new java.util.Date() );
def delete(tree, key):
remove_node = find(tree, key)
if remove_node is None:
raise KeyError
remove_color = remove_node.color
replace_node = None
rl, rr, tl = remove_node.left, remove_node.right, tree.leaf
if rl == tl and rr == tl:
replace_node = tree.leaf
transplant(tree, remove_node, tree.leaf)
@jakab922
jakab922 / gradient_descent.py
Created September 3, 2016 11:25
Gradient decent for linear regression
import numpy as np
def gradient_descent(x, y, alpha, rounds):
z = np.ones(x.shapes[1])
for _ in xrange(rounds):
z = z - alpha * np.dot(np.dot(X, z) - y, X)
return z