This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This trivially solves a quiz on the Italian magazine | |
"La Settimana Enigmistica", namely | |
"Quesito con la Susi n. 946". | |
It uses, without any special reason, >C++11 | |
features. | |
Problem: | |
There are four friends (Giovanni, Marco, Simone, Elisa) | |
sat down behind a desk; Susi must say who's the shortest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This trivially solves a quiz on the Italian magazine | |
"La Settimana Enigmistica", namely | |
"Quesito con la Susi n. 946". | |
It uses, without any special reason, >C++11 | |
features. | |
Problem: | |
There are four friends (Giovanni, Marco, Simone, Elisa) | |
sat down behind a desk; Susi must say who's the shortest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! Find the solution for the problem | |
! "Quesito con la Susi n. 948" | |
! from Italian magazine "La Settimana Enigmistica". | |
! Brute force, as usual. | |
! | |
! Find | |
! n = 3*y0 + y1 + y2 + y3 + y4 + y5 + y6 | |
! so that | |
! y(i) is between 4 and 10 included | |
! (hence n is between 36 and 90 included) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6.c; | |
# based on my original attempt, enhanced with protos | |
# and ideas from https://github.com/moritz/json | |
grammar JSON-Grammar | |
{ | |
token TOP { \s* <json-value> \s* } | |
proto token json-value { * } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// likely you'd like to use this someway; instead, this code | |
// simply ignores and accepts memory leaks. | |
//#include <memory> | |
#include <string> | |
#include <stack> | |
#include <sstream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- interpreter of + and . | |
data StackEl = Onum Integer | Ostr String | |
instance Show StackEl where | |
show (Onum a) = show a | |
show (Ostr s) = "\"" ++ s ++ "\"" | |
plus (Onum a) (Onum b) = Onum $ a+b | |
plus (Onum a) (Ostr b) = Ostr $ (show a) ++ b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "elements.h" | |
#include <stddef.h> | |
#include <stdbool.h> | |
static int compare(const element *a, const element *b) | |
{ | |
if (a->e2 == b->e2) | |
return 0; | |
else if (a->e1 != b->e1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Element.hpp" | |
#include <vector> | |
#include <string> | |
size_t count_uniques(const std::vector<SElement> v) | |
{ | |
size_t c = 0; | |
bool found; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module counter2 | |
implicit none | |
type element | |
character(len=16) :: s | |
integer :: e1, e2 | |
end type element | |
contains | |
function count_unique(s) result(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Counter | |
(Element(..), | |
countUnique, | |
countUnique2) where | |
data Element = Element { s :: String, | |
e1 :: Int, | |
e2 :: Int } deriving (Show, Eq) |