Skip to content

Instantly share code, notes, and snippets.

View tomsmeding's full-sized avatar
🦆

Tom Smeding tomsmeding

🦆
View GitHub Profile
Undefined symbols for architecture x86_64:
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
_main in n3-81953a.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in n3-81953a.o
"std::__1::ios_base::getloc() const", referenced from:
_main in n3-81953a.o
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in n3-81953a.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)", referenced from:
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<cha
#include <iostream>
#include <iomanip>
using namespace std;
#if 1
int gcd(int a,int b){ //Euclidean algorithm
int t;
while(b){
//VYF+VYF=TIEN
function check(e,f,i,n,t,v,y){return 2*(100*v+10*y+f)==1000*t+100*i+10*e+n;}
function search(acc,ansvec){if(acc.length==7){if(check.apply(null,acc))ansvec.push(acc.slice());return;}for(var i=0;i<10;i++)search(acc.concat([i]),ansvec);}
function get(){var ansvec=[];search([],ansvec);return ansvec;}
function distinct(){return get().filter(function(v){return v.map(function(e,i){return v.indexOf(e)!=i;}).reduce(function(a,b){return a+b;})==0;});}
function reasonable(){return distinct().filter(function(v){return v[5]!=0&&v[4]!=0;});}
function goodnozero(){return distinct().filter(function(v){return v.reduce(function(a,b){return a&&b!=0;},true);});}
function format(v){return ""+v[5]+v[6]+v[1]+"+"+v[5]+v[6]+v[1]+"="+v[4]+v[2]+v[0]+v[3];}
function printall(vv){console.log(vv.map(format).join("\n"));}
function TIEN(v){return 1000*v[4]+100*v[2]+10*v[0]+v[3];}
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <unordered_map>
#include <utility>
#include <tuple>
#include <algorithm>
@tomsmeding
tomsmeding / breakstuff.js
Last active August 29, 2015 14:26
Word-wrapping function for javascript
function breakstuff(s,maxlen){
var idx=s.indexOf("\n");
if(idx!=-1){
return breakstuff(s.slice(0,idx),maxlen).concat(breakstuff(s.slice(idx+1),maxlen));
}
var punct=".,;:?!"; //stuff that has a space after it
var wspace=" \t"; //whitespace chars, NOT NEWLINE!
var i;
var lines=[];
var linestart=0,lastend=0;
#!/usr/bin/env bash
LASTUPDATEAT="Thu Aug 6 14:54:49 CEST 2015"
#this is self-modifying code.
which gtail >/dev/null && TAIL=gtail || TAIL=tail
which gstat >/dev/null && STAT=gstat || STAT=stat
if ! eval $TAIL --version >/dev/null; then
echo "Error: Your 'tail' is the BSD version, not the GNU version."
exit 1
$ g++-5 -Wall -O2 -o postrun postrun.cpp -std=c++11
postrun.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > tokenise(std::istream&)':
postrun.cpp:62:13: error: the value of 'stringmode' is not usable in a constant expression
case stringmode:c=stringmode;break;
^
postrun.cpp:20:9: note: 'char stringmode' is not const
char c,stringmode;
^
postrun.cpp:62:13: error: the value of 'stringmode' is not usable in a constant expression
case stringmode:c=stringmode;break;
@tomsmeding
tomsmeding / hr_swapnodes.hs
Created September 5, 2015 20:14
Solution to the hackerrank Swap Nodes problem (functional programming category)
module Main where
import Control.Monad (liftM)
data Tree a = Null | Node a (Tree a) (Tree a)
instance (Show a) => Show (Tree a) where
show Null = "(null)"
show (Node val Null Null) = (show val)
show (Node val Null t2) = (show val) ++ " " ++ (show t2)
@tomsmeding
tomsmeding / parenpairs.hs
Created September 15, 2015 18:28
pairs of parentheses
parenpairs :: String -> [(Int,Int)]
parenpairs = go 0 []
-- index stack string
where go _ [] [] = []
go i st ('[':cs) = go (i+1) (i:st) cs
go i (s:st) (']':cs) = (s,i) : go (i+1) st cs
go i [] (']':cs) = error "rip -- unmatched closing bracket"
go i st (_:cs) = go (i+1) st cs
go _ (_:_) [] = error "rip -- unmatched open bracket"
@tomsmeding
tomsmeding / Makefile
Created September 26, 2015 21:31
A general-purpose makefile for loose c/c++ files in a directory
.PHONY: all clean remake
CC = gcc
CFLAGS = -Wall -Wextra -pedantic -O2
CXX = g++
CXXFLAGS = -Wall -Wextra -pedantic -O2
SYS = $(shell $(CC) -dumpmachine)
ifneq (,$(findstring mingw,$(SYS))$(findstring cygwin,$(SYS))$(findstring windows,$(SYS)))
#windows