Re:Merry Christmas to HN
by jarcane on Thursday December 25, 2014 @03:33AM
(#8795828)
[ Parent
| on HN ]
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string s {33,78,68,0,65,0,40,65,80,80,89,0,46,69,87,0,57,69,65,82,0,79,70,0,
70,85,78,67,84,73,79,78,65,76,0,67,79,68,69,0,84,79,0,89,79,85,0,
84,79,79,12,0,51,73,82,1};
transform (begin(s), end(s), begin(s), [](char c){ return c + 32; });
cout << s << endl;
}Last one, in old-fashioned style:
5 FORX=1TO16:READN:N=N+32:?CHR$(N);:NEXTX:DATA45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1Coffee:
[45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1].map((x) -> String.fromCharCode x+32).join('')
What language is this?
Haskell. Here's another way to do it in the same language, using function composition and point-free style.
map (chr . (+32)) [45, 69, 82, 82, 89, 0, 35, 72, 89, 73, 83, 84, 77, 65, 83, 1]
Merry Xmas. I thought I'd try Haskell for the same time for Xmas and found I have to download it and import Data.Char first in case anyone else is trying!
Re:Merry Christmas to HN
by peterwwillis on Thursday December 25, 2014 @08:22AM
(#8796205)
Or in Perl:
map{chr$_+32}(45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1)
shorter using pack: # shorts
pack("s*",25933,29298,8313,26691,26994,29811,24941,8563)
# longs
pack("l*",1920099661,1749229689,1953720690,561209709)
# 64-bit
pack("q*",7512884309367350605,2410377348306397554)
# hex
pack("h*",d45627279702348627963747d6163712)explain :)
Re:Merry Christmas to HN
by krat0sprakhar on Thursday December 25, 2014 @03:47AM
(#8795850)
Copy-paste in your browser console -
// Merry Christmas
console.log(
[45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1]
.map(function(i) { return i + 32; })
.map(function(i) { return String.fromCharCode(i); })
.join("")
);Javascript
[45, 69, 82, 82, 89, 0, 35, 72, 82, 73, 83, 84, 77, 65, 83, 1].map(function(x){ return String.fromCharCode(x +32)}).join('') ; Racket version
(apply string (map (λ (x) (integer->char (+ x 32))) '(45 69 82 82 89 0 35 72 82 73 83 84 77 65 83 1)))I'm to lazy to do the math (substract and look for ascii code), but it should be "Merry Christmas". clue: look where "r" is i the string.
Python equivalent for convenience:
map(lambda x: chr (x + 32), [45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1])
Just paste it into a python terminal and run it :)
Re:Merry Christmas to HN
by heinrich5991 on Thursday December 25, 2014 @05:42AM
(#8795990)
Python 2/3 compatiblity:
"".join(map(lambda x: chr (x + 32), [45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1]))Or as a list comprehension if that's your thing:
"".join([chr(x + 32) for x in [45,69,82,82,89,0,35,72,82,73,83,84,77,65,83,1]])
Re:Merry Christmas to HN
by kevinavery on Thursday December 25, 2014 @12:27PM
(#8796679)
Scala
List(45,69,82,82,89,0,35,72,89,73,83,84,77,65,83,1) map (_ + 32 toChar) mkString